3
votes

I was wondering if there is a way to find out the default VPC ID using CF at runtime. There is no pseudo parameter I could use within the template to find out as far as I can tell. Using the cli command can achieve the result

aws ec2 describe-vpcs --filter "Name=isDefault, Values=true"

However, this would mean that I will have to create a custom CloudFormation resource and use a Lambda function just to find the default VPC id at run time. The idea is that I want to create a role in each AWS account that prevents users from launching EC2 instances into the default VPC.

1
As far as I know, a custom resource is the only way.kichik

1 Answers

0
votes

I would suggest you use a combination of AWS Config and AWS Lambda to automatically terminate instances created in the default VPC.

I've seen it done in a demo at Re:Invent. Source: https://www.youtube.com/watch?v=sGUQFEZWkho