Reputation: 15076
I have a stack which needs resources which need to be deployed in a certain VPC. I want to use the default VPC but I don't want to parameterize this. Is there a way to automatically obtain the default VPC value? (Like for example Fn::GetAZs: region
for AZ's in a region).
Upvotes: 19
Views: 5963
Reputation: 238209
The ID of the default VPC can be obtained using the following AWS CLI command:
$ aws ec2 describe-vpcs \
--filters Name=isDefault,Values=true \
--query 'Vpcs[*].VpcId' \
--output text
vpc-a1b2c3d4
The above command will output something like: vpc-a1b2c3d4
You can assign this output to a variable and then pass it to your CF template like this:
$ default_vpc_id=$(aws ec2 describe-vpcs \
--filters Name=isDefault,Values=true \
--query 'Vpcs[*].VpcId' \
--output text)
$ echo ${default_vpc_id}
vpc-a1b2c3d4
Upvotes: 6