03
- 3.9 The basics of AWS CloudFormation for automating infrastructures
- Learning Objectives
- Create a CloudFormation Stack
- Delete a CloudFormation Stack
- Identify CloudFormation template components
3.9 The basics of AWS CloudFormation for automating infrastructures
Learning Objectives
By the end of this lesson you will be able to:
- Create a CloudFormation stack of an existing template.
- Delete an existing CloudFormation stack.
- Identify the basic components of a CloudFormation template.
Create a CloudFormation Stack
- Go to the CloudFormation stack in the AWS Management Console. Click the Create New Stack button.
- In the Stack Name box, type a Stack name. For this example, use DITCJenkinsStack. The Stack Name must not contain spaces. Click ‘Provide a Template URL.’ In the box below, type or paste this URL: https://stelligentlabs.s3.amazonaws.com/templates/jenkins.template. The template creates a Jenkins environment. Click Continue.
- In the Key Name box, enter ditc as your EC2 Key Pair – from the key pair you created in sublesson 3.4. Click Continue and then click Close. Your stack may take several minutes to create
- The progress of the stack creation is shown in the top portion of the CloudFormation tab. The status for DITCJenkinsStack should be CREATE_IN_PROGRESS
- Select the checkbox next to the DITCJenkinsStack stack. In the bottom pane, click the Events tab. The Events Tab displays each step in the creation of the stack. The CREATE_COMPLETE event is shown when a resource has been successfully created. If AWS CloudFormation cannot create a particular resource, it displays a CREATE_FAILED event and rolls back the stack.
- When the stack DITCJenkinsStack has the status CREATE_COMPLETE, AWS CloudFormation has finished creating the stack and you can start using its resources. The sample Jenkins stack installs and configures a Jenkins CI application onto a Tomcat server. To complete the Jenkins installation, click on the link in the JenkinsURL row to launch the Jenkins application.
Delete a CloudFormation Stack
- Go to the AWS CloudFormation Console, select DITCJenkinsStack and click Delete Stack. In the confirmation message that appears click Yes, Delete. The status for DITCJenkinsStack changes to DELETE_IN_PROGRESS. In the same way you monitored the creation of the stack, you can monitor its deletion using the Events tab. When AWS CloudFormation completes the deletion of stack, it removes the stack from the list.
Identify CloudFormation template components
- Open the CloudFormation template at https://github.com/stelligent/devopsinthecloud/blob/master/infrastructure/templates/jenkins.template .
- Review the six top-level objects: AWSTemplateFormatVersion, Description, Parameters, Resources, Mappings, Outputs in the jenkins.template file. The Resources object is the only object that’s required
- The Resources object contains the definitions of the AWS resources you want to create with the template. Each resource is listed separately and specifies the properties necessary for creating that particular resource. The resource declaration begins with a String that specifies the logical name for the resource. The logical name can be used to refer to the resources within the template.
- You use the Parameters object to declare values that can be passed to the template when you create the Stack. A parameter is an effective way to specify sensitive information – such as usernames/passwords – that you don’t want to store in the template itself.
- You use Mappings to declare conditional values that are evaluated in a similar manner as a switch statement. The template uses Mappings to select the correct Amazon Machine Image for the Region and the Architecture Type for The Instance Type.
- Outputs define custom values that are returned by the cfn-describe-stacks command and in the AWS Management Console Outputs tab after the stack is created. You can use Output values to return information from the resources in the stacks such as the URL for a website created in the template.