-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathglobalImport.js
25 lines (25 loc) · 890 Bytes
/
globalImport.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
const response = require("cfn-response");
const AWS = require("aws-sdk");
exports.handler = (event, context) => {
const { SourceRegion, Exports = ['.+'] } = event.ResourceProperties;
const filters = Exports.map(e => new RegExp(e, 'i'));
const id = `custom:cloudformation:${SourceRegion}:exports`;
const cloudformation = new AWS.CloudFormation({ region: SourceRegion });
try {
cloudformation.listExports({}, (err, data) => {
if (err) {
throw err;
} else {
const obj = {};
data.Exports.forEach(({ Name, Value }) => {
const matches = filters.filter(f => f.test(Name));
if (matches.length > 0) obj[Name] = Value;
});
response.send(event, context, response.SUCCESS, obj, id);
}
});
} catch (err) {
console.error(err.message);
response.send(event, context, response.FAILED, {}, id);
}
};