-
Notifications
You must be signed in to change notification settings - Fork 3.7k
/
index.ts
33 lines (28 loc) · 897 Bytes
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import { CfnUtilsResourceType } from './consts';
/**
* Parses the value of "Value" and reflects it back as attribute.
*/
export async function handler(event: AWSLambda.CloudFormationCustomResourceEvent) {
// dispatch based on resource type
if (event.ResourceType === CfnUtilsResourceType.CFN_JSON) {
return cfnJsonHandler(event);
}
if (event.ResourceType === CfnUtilsResourceType.CFN_JSON_STRINGIFY) {
return cfnJsonStringifyHandler(event);
}
throw new Error(`unexpected resource type "${event.ResourceType}`);
}
function cfnJsonHandler(event: AWSLambda.CloudFormationCustomResourceEvent) {
return {
Data: {
Value: JSON.parse(event.ResourceProperties.Value),
},
};
}
function cfnJsonStringifyHandler(event: AWSLambda.CloudFormationCustomResourceEvent) {
return {
Data: {
Value: JSON.stringify(event.ResourceProperties.Value),
},
};
}