Lab 01: Template and Stack

Overview

This lab will start with the most basic template containing only Resources object, which contains a single resource declaration of the S3 bucket.

Topics Covered

By the end of this lab, you will be able to:

  • Write a simple CloudFormation template that describes an S3 bucket.
  • Deploy the template and create a CloudFormation stack.

Start Lab

  1. Go to the code/10-cloudformation-fundamentals/ directory.
  2. Open the 01-lab01-StackExample.yaml file in your code editor.
  3. Here is a sample CloudFormation template that defines an S3 Bucket. It has a single resource that contains the S3 bucket. Copy the code below and save to the 01-lab01-StackExample.yaml file.

    Resources:
     S3Bucket:
       Type: AWS::S3::Bucket
    1. Open the AWS CloudFormation link in a new tab and log in to your AWS account.
    2. Click on Create stack (With new resources (Standard) if you have clicked at the top right corner).
    3. In Prepare template, choose Template is ready.
    4. In Template source, choose Upload a template file.
    5. Click on Choose file button and navigate to your workshop directory.
    6. Select the file 01-lab01-StackExample.yaml referenced in step 1.
    7. Click Next.
    8. Provide a Stack name. For example cfn-workshop-s3.
    9. The Stack name identifies the stack. Use a name to help you distinguish the purpose of this stack.
    10. Click Next.
    11. You can leave Configure stack options default, click Next.
    12. On the Review page, scroll down to the bottom and click on Create stack.
    13. You can click the refresh button a few times until you see in the status CREATE_COMPLETE.

    Challenge

    In this exercise, enable versioning on the S3 bucket. Enabled versioning will prevent objects from being deleted or overwritten by mistake or to archive objects so that you can retrieve previous versions of them.

    1. Create a property VersioningConfiguration in the Properties section of the S3 resource.
    2. Set the Status to Enabled.
    3. Update the stack to reflect the changes made in the template.
    Need a hint?
    Want to see the solution?

    Clean up

    Follow these steps to clean up created resources:

    1. In in the CloudFormation console, select the the stack you have created in this lab. For example cfn-workshop-s3.
    2. In the top right corner, click on Delete.
    3. In the pop up window click on Delete stack.
    4. You can click the refresh button a few times until you see in the status DELETE_COMPLETE.

    Conclusion

    Great work! You have written your first CloudFormation template and created your first stack.