DEV Community

Cover image for Infrastructure provisioning with AWS CloudFormation

Infrastructure provisioning with AWS CloudFormation


Provisioning of infrastructure can be a tedious task when carried out on the AWS console, it has a lot of limitations when it comes to tasks like creating same infrastructure when a mistake was made, recreating the same infrastructure for another project or case of not following the exact same steps needed for the infrastructure creation on the console.
Situations like this and more are the reasons why infrastructure as code (IaC) was created, to give developers the ability to write out code for their infrastructure which can be used multiple times.

In this article, we would be looking at AWS very own infrastructure as code (IaC) tool called "CloudFormation", which is written in YAML language and creating a network infrastructure which consist of a Virtual Private Network (VPN), Subnet, Internet gateway, Elastic IP, NetGateway, Routing table.

The code used for this Demo can be found here.

Creating a CloudFormation stack

To create a CloudFormation stack, the following AWS command will be passed into the terminal.

  • create-stack: Desired stack name.
  • template-body: Name of the YAML file containing the IaC.
  • parameters: Key value pairs that can be used as parameter in the YAML file.
  • region: Desired region in which the infrastructure will be created.
aws cloudformation create-stack \
  --stack-name AppDeploy \
  --template-body file://network.yml \
  --parameters ParameterKey=EnvironmentName,ParameterValue=AppDeploy \
Enter fullscreen mode Exit fullscreen mode

When it is successful, the following output will be displayed on the terminal, showing the stack ID.
stack creation initiation

On your CloudFormation dashboard in AWS console, it will display the name given to the stack and a status of CREATE_IN_PROGRESS.

stack and a status

Click the name of the stack, and check under the "resources" section to see the list of the resources indicated in the template that are being created.

resources indicated in the template that are being created

After successful creation of the resources, you can visit the VPC dashboard to view the just created VPC.

new VPC created

We were able to look at how to use CloudFormation for infrastructure provisioning by creating a group of networking resources which was deployed as a stack on the CloudFormation dashboard.

Top comments (0)