Infrastructure as Code: Create CloudFormation Stack
Explore how to recreate your AWS infrastructure using CloudFormation and the AWS CLI. Understand script creation, template structure, and automate resource provisioning like EC2 instances and security groups. Gain hands-on experience with infrastructure as code to deploy scalable and manageable cloud environments.
We'll cover the following...
Objective
- Recreate our infrastructure using CloudFormation.
Steps
- Configure the AWS CLI.
- Create a CloudFormation Stack.
In this section, we’ll recreate the same infrastructure we set up in the previous section, but this time, we’ll use CloudFormation to automate the process, instead of setting everything up manually through the AWS console.
Configuring the AWS CLI
We’re going to use the AWS CLI to access AWS resources from the command line rather than the AWS console. If you don’t already have it installed, follow the official directions for your system. Then, configure a profile named awsbootstrap using a newly generated Access Key ID and Secret Access Key, as described in the AWS documentation.
We can test our AWS CLI configuration by listing the EC2 instances in our account.
Now that we have the AWS CLI working, we could write a bunch of scripts that call the various AWS API commands to automate the process for setting up our infrastructure. But that would be very brittle and complicated. Luckily, there’s a better way.
Infrastructure as code #
Infrastructure as code is the idea of using the same processes and tools to update your infrastructure as you do for your application code. We will now start defining our infrastructure into files that can be linted, schema-checked, version controlled, and deployed without manual ...