AWS console, AWS CLI, AWS SDK, … which one do you prefer?
graph credit: aws.amazon.com
This lab is a replica of AWS Skills Challenge 3: VPC (with AWS Console), but using CloudFormation.
I will provide a step by step guide to build a VPC with 3 subnets named “Alpha”, “Bravo”, and “Charlie”. The “Alpha” subnet should contain half the available IPV4 addresses while the other two contain one quarter each. Each subnet should be in a separate Availability Zone within the same AWS region. VPC CIDR: 10.1.1.0/24.
Background
Cloudformation is a service that allows you to create and manage AWS infrastructure resources and services through code. It provides a common language for you to describe and provision all the infrastructure resources needed for your applications across various AWS regions and accounts.
CloudFormation introduces four concepts:
- A template is a JSON or YAML declarative code file that describes the intended state of all the resources you need to deploy your application.
- A stack implements and manages the group of resources outlined in your template, and allows the state and dependencies of those resources to be managed together.
- A change set is a preview of changes that will be executed by stack operations to create, update, or remove resources.
- A stack set is a group of stacks you manage together that can replicate a group.
CloudFormation allows you to achieve infrastructure as code, meaning you can manage and version your infrastructure as if it were software code.
Learn more about CloudFormation here.
Prerequisite
For this project, you need an AWS account. If you don’t have one already, set up a Free-Tier account.
Project Outline
Using a CloudFormation template build a VPC with 3 subnets named “Alpha”, “Bravo”, and “Charlie”. The “Alpha” subnet should contain half the available IPV4 addresses while the other two contain one quarter each. Each subnet should be in a separate Availability Zone within the same AWS region. VPC CIDR: 10.1.1.0/24.
Let’s Have Fun!
- Open your preferred text editor and create a new CloudFormation template in either YAML or JSON format.
- Define the CloudFormation stack name and the region where you want to create the VPC.
- Define the “Alpha” subnet with the specified IP address range and Availability Zone.
- Define the “Bravo” and “Charlie” subnets with the specified IP address range and Availability Zone.
- Save this template.
Cheat Sheet: Here’s a breakdown of what the template is doing:
- The VPC resource creates a new VPC with the CIDR block “10.1.1.0/24”.
2. The AlphaSubnet resource creates a new subnet within the VPC with the CIDR block “10.1.1.0/25” (half of the available IPV4 addresses) in availability zone “us-east-1a”.
3. The BravoSubnet resource creates a new subnet within the VPC with the CIDR block “10.1.1.128/26” (one quarter of the available IPV4 addresses) in availability zone “us-east-1b”.
4. The CharlieSubnet resource creates a new subnet within the VPC with the CIDR block “10.1.1.192/26” (one quarter of the available IPV4 addresses) in availability zone “us-east-1c”.
- Now log in to your AWS account. Go to the console and type CloudFormation.
- Click on “Create stack”
Cheat Sheet: you can use AWS CloudFormation through the AWS Management Console, AWS CloudFormation API, or AWS CLI.
- Select “template is ready”, and “upload a template file”
Cheat Sheet: you have 3 choices: “template is ready” if you have template file ready for use, “use a sample template” if you are using an existing template, and “create a template in designer” if you can graphically design your stack on a simple, drag-and-drop interface.
- Upload the yaml or json template file you created at the beginning. Then click “Next”.
- Provide a stack name for your CloudFormation stack, and provide the necessary parameters if any. Then click “Next”.
- Provide any tags if required. Click on “Next” and review the details.
- In “Configure stack options”, add any necessary info if needed.
- Click on “Submit” to create your VPC with the 3 subnets named “Alpha”, “Bravo”, and “Charlie”.
- Wait few minutes. Your stack is created.
You now have a VPC with 3 subnets named “Alpha”, “Bravo”, and “Charlie” that meet the requirements specified in the prompt.
Voilà! Using a CloudFormation template you have built a VPC with 3 subnets (IPV4 addresses, separate Availability Zones within the same AWS region, and VPC CIDR: 10.1.1.0/24).
Thank you for reading and/or following along! Please stay tuned for all my upcoming projects, and feel free to check out the rest of my articles.
Leave a Reply