...

/

Infrastructure as Code: Create CloudFormation Stack

Infrastructure as Code: Create CloudFormation Stack

CloudFormation will be used in this lesson to recreate the same instrastructure we set up in the previous lessons. We are going to automate the process of instrastructure creation, instead of setting everything up manually through the AWS console.

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.

Press + to interact
aws configure --profile awsbootstrap
AWS Access Key ID [None]: AKIAIOSFODNN7EXAMPLE
AWS Secret Access Key [None]: wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
Default region name [None]: us-east-1
Default output format [None]: json

We can test our AWS CLI configuration by listing the EC2 instances in our account.

Press + to interact
aws ec2 describe-instances --profile awsbootstrap

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 ...

Access this course and 1400+ top-rated courses and projects.