forked from panyapoc/ItemStorePersonalize
-
Notifications
You must be signed in to change notification settings - Fork 6
/
main.js
33 lines (30 loc) · 1020 Bytes
/
main.js
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
// External Dependencies:
const response = require("cfn-response");
// Local Dependencies:
const resources = require("./lib/resources");
const resourceArr = Object.keys(resources).map((key) => (resources[key]));
/**
* Composite handler for multiple custom resource types to share a single Lambda function
* See items in ./lib/resources for each type's implementation
*/
exports.handler = function setup(event, context, callback) {
console.log("Received event:", JSON.stringify(event, null, 2));
const resource = resourceArr.find((res) => (res.resourceType === event.ResourceType));
if (resource) {
return resource.handler(event, context, callback);
} else {
console.error(
`Unrecognised resource type ${
event.ResourceType
} not in known list: ${
resourceArr.map((res) => res.resourceType).join(", ")
}`
);
return response.send(
event,
context,
"FAILED",
{ Error: `Unrecognised resource type ${event.ResourceType}` },
);
}
};