Created
February 22, 2022 14:12
-
-
Save divmgl/d24e96955cfa50c8aee0170777d847b8 to your computer and use it in GitHub Desktop.
Revisions
-
divmgl created this gist
Feb 22, 2022 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,42 @@ const aws = require("aws-sdk") const iam = new aws.IAM() const ec2 = new aws.EC2() const securityGroupNames = [ "allow-internal-ingress", "allow-internal-egress", "allow-external-egress" ] module.exports = { deploy: { start: async function ({ cloudformation }) { const { Resources } = cloudformation const { AnyCatchallHTTPLambda } = Resources const { Properties } = AnyCatchallHTTPLambda const { Subnets } = await ec2.describeSubnets().promise() const internalSubnet = Subnets.find(vpc => vpc.Tags.some( ({ Key, Value }) => Key === "Name" && Value === "internal" ) ) const { SecurityGroups } = await ec2.describeSecurityGroups().promise() const securityGroups = SecurityGroups.filter(({ GroupName }) => { return securityGroupNames.indexOf(GroupName) !== -1 }) const { Roles } = await iam.listRoles().promise() const { Arn } = Roles.find(({ RoleName }) => RoleName === "lambda-role") Properties.Role = Arn Properties.VpcConfig = { SubnetIds: [internalSubnet.SubnetId], SecurityGroupIds: securityGroups.map(({ GroupId }) => GroupId) } return cloudformation } } }