Overview
This step-by-step, hands-on AWS CloudFormation tutorial is ideal for beginners. You will create a simple CloudFormation stack containing a single resource. And you’ll be doing it twice: with AWS CloudFormation Console, then with AWS Command Line Interface (AWS CLI).
By doing the same task with both the Console and the CLI, you’ll gain insight into the benefits of each. Note: tutorial instructions for each tool are self-contained, so you can choose to follow the steps for one but not the other.
Unfamiliar with AWS CloudFormation? Read this first:
What is AWS CloudFormation?
A Note about AWS Costs
It’s not surprising that using AWS costs money. The good news is: if your AWS account is less than 12 months old, you’re eligible for Free Tier. Which means some stuff is free (for those first 12 months).
If your AWS user account is eligible for Free Tier, then following the steps in this tutorial will not incur a cost. Be sure to follow the Cleanup task(s) so unused resources do not exist past your Free Tier eligibility date.
Resource Cost Summary
Below are the resource(s) you’ll be creating with this Tutorial. Read this to verify if your AWS user account is eligible for Free Tier.
Resource(s) | Cost | Free Tier Limits |
S3 Bucket | Free Tier eligible 12 months free | 5 GB of Standard Storage 20,000 Get Requests 2,000 Put Requests |
Now, let’s get to the good stuff …
Tutorials
We use AWS CloudFormation to create stacks of resources. We can then manage all the stack’s resources (and their dependencies) as a group.
Remember, to declare all the resources in a stack, we first create a template. A template is just a JSON or YAML file. This tutorial uses the YAML format.
So, that’s what we’ll do: create a template, then call on CloudFormation to create a stack containing the resources within the template. Our stack will contain only 1 resource, to keep it simple.

Then we’ll delete the stack (thereby, deleting the resources.)
First, we’ll use the AWS CloudFormation Console. Next, we’ll use the AWS CLI (command line) to do the same set of tasks.
AWS CloudFormation Console
Pre-Requisites
- AWS Account (here for instructions on creating an account)
Instructions
Open the AWS CloudFormation Console
- Log into the AWS Console: https://aws.amazon.com/console/
- Type CloudFormation in the search bar, then select it.
Initiate Stack Creation
- Click Create stack, then select With new resources (standard) from the drop-down.
- If this is your first stack, you may also have to click the orange Create stack button near the bottom to advance to the next page.

Prepare Template
When you create a stack in the CloudFormation Console, you’ll be given several options for preparing a template:
- Upload or point to an existing template
- Start with a sample template
- Use the template Designer

One of the benefits of the CloudFormation Console is its template Designer. With the Designer, you can visually create your stack with an architectural visual. CloudFormation will create your template interactively for you. We’ll be using the Designer in this Tutorial.
- Choose Create template in Designer, then click Create template in designer.
- From Resource type list in left column, click S3.
- Drag Bucket to the designer pane on the right.
- Notice the bottom part of your screen: Properties editor is now occupied with default S3 Bucket properties. For Choose template language: select YAML.
- At bottom of screen you’ll see 2 tabs. Click Template. Review the editor window contents. You don’t have to make any changes, just start getting familiar with templates.
- Rename the template by clicking on
new.template
(top left of Template editor) and replace it withmy_console_stack.yml
(or, use any name that makes sense to you.). - Click the checkmark next to
my_console_stack.yml
name to save it.

- Near the top/left of the window, you’ll see a row of icons. Click the checkmark icon to verify the template is valid. You should see ‘Template is valid’ message in small font.
- To create the stack from the template declarations, click the cloud (with the up-arrow inside) icon to the left of the validation check icon.
- You’ll be re-directed back to the ‘Create stack’ page. The Amazon S3 URL field in Specify template section will automatically filled-in for you. If you look at the URL value, near the end of the string, you’ll see your template’s name
my_console_stack.yml
embedded.

Congratulations, you’ve created a template!
- Click Next.
Specify Stack Details
- Enter
my-stack-1
for the Stack name (or, use any name that makes sense to you) - Leave Parameter blank to accept just the defaults.
- Click Next, then Next again to accept more defaults. Normally, you’ll want to set parameters, permissions and options. But for now, we’re just getting the feel for using CloudFormation.
- Scroll down and click Create stack.
- You’ll be sent to your new stack’s page. You may have to wait a moment for the status to be Complete.

Congratulations, your stack is created! Now let’s find the S3 bucket that should have gotten created with the stack …
Verify Stack and Resource
- Still on the stack’s page, click the Resources tab.
- You should see there is 1 Resources, and its Type is ‘AWS::S3::Bucket’. Just like we asked for.

- Notice the Physical ID name starts with our stack name,
my-stack-1
post-fixed with a bunch of alpha-numeric characters. Click it (the Physical ID). You’ll be re-directed to the Amazon S3 page for your new S3 bucket.

That’s it! You created your first stack and are now the proud owner of an empty bucket!
Now you can either cleanup by deleting the stack, or you can skip the cleanup for now, leaving it until you create a second stack using the command line so you can compare the two.
Cleanup
To avoid inadvertent charges in the future, delete your new stack. Technically, we could delete the S3 bucket directly, but it’s a good idea to start managing stacks as a complete set, as opposed to managing individual resources inside a stack. Plus, even if you delete the S3 bucket, the stack will still exist.
- Return to CloudFormation > Stacks
- Select radio button next to
my-stack-1
- Click Delete, then Delete stack.
- Return to the S3 service page. The S3 bucket should now either be gone, or in the process of being deleted.
Now, let’s do the same thing, this time using your terminal command line.
AWS Command Line Interface (CLI)
Pre-Requisites
- AWS Account (here for instructions on creating an account)
- AWS CLI installed on your machine (here for installation instructions)
Instructions
- Verify you have a valid AWS CLI connection. An easy way to validate is by listing your S3 buckets. You should receive no errors, and if you have no S3 buckets, there will be no output.
Enter this command on your terminal:
$ aws s3 ls
Create Template
Templates are flat files, in either JSON or YAML format. With this Tutorial we are using the YAML format.
- Using your favorite editor on your terminal, create a template file named
my_cli_stack.yml
. Declare a single AWS S3 Bucket resource by adding these lines to the file. Remember to save the changes.
Resources:
S3Bucket:
Type: AWS::S3::Bucket
If you created a template using the AWS CloudFormation’s Designer tool, you may notice the CLI template version is a lot shorter. That’s ok. The Designer version included metadata that is not required.
Create Amazon S3 Bucket with Defaults
- Initiate the CloudFormation CLI
create-stack
command, passing it two parameters: stack-name (my-stack-2
) and your new template filemy_cli_stack.yml
:
$ aws cloudformation create-stack \--stack-name my-stack-3 \--template-body file://my_cli_stack.yml
I added a backward-slash (\
) in front of the double-dashes (--
) to avoid the double-dashes being mis-interpreted as a single long dash during a copy/paste of the above command. If you are typing the command manually, or add it to a script to run, you may not need the backward-slashes.
Your output should look something like this:
{
"StackId": "arn:aws:cloudformation:us-west-2:063809509415:stack/my-stack-2/45d82ea0-28c7-11ea-9bb0-02c46d078154"
}
Verify Stack Creation
It is possible for the output message from create-stack
to include a StackId even though the status of the stack itself is not valid or is rolled back.
- To verify that your stack creation was successful. Still at the terminal prompt, enter this command:
$ aws cloudformation describe-stacks \--stack-name my-stack-2
Output should look something like this, with “StackStatus”: “CREATE_COMPLETE”.
{
"Stacks": [
{
"StackId": "arn:aws:cloudformation:us-west-2:063809509415:stack/my-stack-2/55913d50-30bf-11ea-b8dd-0a233d312e0a",
"StackName": "my-stack-2",
"CreationTime": "2020-01-06T20:01:32.102Z",
"RollbackConfiguration": {},
"StackStatus": "CREATE_COMPLETE",
"DisableRollback": false,
"NotificationARNs": [],
"Tags": [],
"EnableTerminationProtection": false,
"DriftInformation": {
"StackDriftStatus": "NOT_CHECKED"
}
}
]
}
Congratulations, you created a stack from the command line! Now, let’s go look at our bucket …
Verify S3 Bucket Creation
- Still at the terminal prompt, enter this command to list your S3 buckets:
$ aws s3 ls
Output should include your new S3 bucket, my-stack-2
:
2020-01-06 12:01:37 my-stack-2-s3bucket-e27a6thvvjfz
Cleanup
To avoid inadvertent charges in the future, delete your new stack. We could delete the S3 bucket directly, but it’s a good idea to start managing stacks as a complete set, as opposed to managing individual resources inside a stack. Plus, even if you delete the S3 bucket, the stack will still exist.
- Enter this command on your terminal:
$ aws cloudformation delete-stack \--stack-name my-stack-2
- Then re-run
aws s3 ls
to verify it is gone. If you did not delete the stack from the AWS Console portion of this Tutorial, be sure to delete that stack as well.
Conclusion
Bravo! You created templates that declared an AWS resource, and practiced using both the AWS Console and AWS CLI to create CloudFormation stack(s)!
Which was your favorite method for creating templates and stacks?
The Console’s Designer tool is convenient. It allows you to draw your infrastructure’s architecture, then it creates a template that declares all the resources from your architectural drawing.
One downside to using the Console is there are many more steps involved in managing stacks. The CLI involves fewer steps, and fewer options for human error.
Once I have a template and become proficient at declaring resources, I find using the command line much easier and faster. And I can wrap my own programming logic around AWS CLI commands, for example with shell scripts or Python.
What’s Next?
Next step is to learn about Stack parameters, mappings and conditionals. These are the power players behind using CloudFormation for repeatability.
Leave a Reply