AWS CloudFormation

CloudFormation supports two standard formats, JSON and YAML. Personally I find YAML cleaner. YAML is a full serialization language with robust features and it also supports comments.  We will use the YAML format for the following examples. For a quick reference to YAML format use this repo. It is a good idea to use a text editor; let's learn the hard way and use a simple text editor to learn pragmatically by doing lots of templates. Atom and Sublime Text are good editors. For YAML, the spacing convention is important and these editors will help you to do it easily.

To get started let's create the simplest template possible, s3-bucket.yaml (https://github.com/gabanox/Certified-Solution-Architect-Associate-Guide/blob/master/chapter20/s3-bucket.yaml):

Navigate to CloudFormation | Create Stack and choose the option to upload template to S3. This will use S3 as a staging area to upload and then create the stack. If templates were previously uploaded to S3, you can reference those templates using their URLs. Click Next, as shown in the following screenshot:

In the Specify Details screen you can specify input data for the template. The required input data is the Stack name, which is a logical identifier that will be used to manage the lifecycle of the provisioned objects, in fact, created objects will have this name concatenated to keep track of object instances. Click Next, as shown in the following screenshot:

In the Options screen, you can specify additional configurations like triggers for rollbacks, SNS notification topics, and IAM permissions. Leave the Options screen as is and click Next, you will be presented with a Review screen, as shown in the following screenshot:

Click on Create and the stack will be provisioned automatically. Stacks are the logical grouping of resources provisioned of updated by a single template and they are managed as a unit.

The template falls in the CREATE_IN_PROGRESS status, poll until the template changes the status to CREATE_COMPLETE. Use the Events tab, shown in the following screenshot, to understand the steps taken to provision the S3 bucket:

Now that the resource has been provisioned without errors, validate the resource created in the S3 console. Pretty fun huh?

Because this resource is managed via the stack the proper way to delete it is directly from CloudFormation to we don't leave orphaned resources. This auto assigned resource ID is a good way to work using infrastructure as code by applying the concept to cattle not pet (http://cloudscaling.com/blog/cloud-computing/the-history-of-pets-vs-cattle/). If you assign names to resources you get attached to them, but if you treat them like cattle you assign random numbers like r-01, r-02, and you manage them collectively. With the template checked use the actions button and choose delete. After this operation has completed you shouldn't see the S3 bucket anymore. This operation will not cascade the deletion if the bucket contains objects.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset