How Do You Deploy a Stack (a Collection of Infrastructure Resources) with AWS CloudFormation Using AWS CLI?

Problem scenario
You want to deploy a stack (a collection of infrastructure or application resources) with the AWS CLI. You want to create a server with CloudFormation and the AWS CLI. How do you do this?

Here is a simple example to answer the question.  This requires that you have AWS CLI installed and configured. If you need help with that, here are directions for how to do it.

Step #1  Create a .json file for the template.  The content of the file linked here is an example. You just use the content and name the file "lampstack.json". It will help you create a single EC2 instance with the proper command below.  

Step #2  Use this command from the Linux prompt but see the * below for explicit directions on which values to replace to tailor this command to work for you:

aws cloudformation create-stack --stack-name continualstack --template-body file:///tmp/lampstack.json --parameters ParameterKey=KeyName,ParameterValue=uniquepair2019 ParameterKey=DBPassword,ParameterValue=verycont ParameterKey=DBUser,ParameterValue=contuser ParameterKey=DBRootPassword,ParameterValue=contpassword

*  Before running the "aws cloudformation..." command above, replace these values:

continualstack  This is a new arbitrary name of the stack that this command will create.  Choose whatever you like.

/tmp/lamptstack.json  This is the location and name of your JSON file for your CloudFormation template.  See the attached "lampstack.json" if you want to try this.  It creates an EC-2 Linux instance with Apache, MySQL, and PHP.

uniquepair2019   This is the name of the pre-existing key that you choose when you create an EC2 instance.  When you create a new server in the AWS console, the last step prompts you to "Select an existing key pair."   You choose the (alphanumeric) key pair name on this pop-up.  (When you created one for the first time, there was a file name with a .pem extension.  Without the ".pem", this name is correct.  This key pair name of what you would use when creating an EC2 instance is what you should use instead of "uniquepair2".

verycont should be a new password you want to assign as the DBPassword.

contuser should be a new user you want to have access to the MySQL database.

contpassword should be a new password you want to assign as the DBRootPassword.

Finally, if you need an American or offshore AWS consultant for CloudFormation or something similar, please submit your request to sales [at] americandevops [dot] com and reference "" for a discount.  The price quote is free, and they can handle on-site needs for large enterprises or small freelance projects done remotely.

Leave a comment

Your email address will not be published. Required fields are marked *