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).
A default VPC is a logically isolated virtual network in the AWS cloud that is automatically created for your AWS account the first time you provision Amazon EC2 resources. When you launch an instance without specifying a subnet-ID, your instance will be launched in your default VPC.
Default VPC is a Virtual network which is automatically created for customer AWS account the very 1st time EC2 resources are provisioned. On the other hand, a nondefault (also called Customer VPC) is not automatically created when EC2 resources are provisioned and customer needs to create own VPC.
AWS CloudFormation allows us to implement "Infrastructure as Code" in an AWS environment. A sophisticated Virtual Private Cloud (VPC) is easy to create and update in an automated way with CloudFormation. We can re-use CloudFormation templates to build various stacks of resources for various purposes.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With