Created
February 22, 2022 14:12
-
-
Save divmgl/d24e96955cfa50c8aee0170777d847b8 to your computer and use it in GitHub Desktop.
Smitten VPC Arc Plugin
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 characters
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 | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment