Automation with CloudFormation
BACK

Automation with CloudFormation

Services used: CloudFormation, EC2, S3

Languages used: YAML, JSON

Objective: Help reduce human error and standardize deployment infrastructure. Determine how to use AWS CloudFormation to automate environment creation. Demonstrate how to read and write basic CloudFormation templates in YAML and JSON. Demonstrate how to run the automation to create different environments.

First, search for and open CloudFormation.

On the Stacks page, create a stack with new resources.

Select Create template in Designer and then click Next.

Select the Template tab and change the name from new.template to RoboticStack. Change the template language to YAML.

Using a sample file, input the code that defines the stack resources and properties.

To see the JSON equivalent code, simply select the JSON radio button.

In a new browser, visit the following website:

https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-ec2-instance.html

Scroll down to the YAML section and select InstanceType.

This page specifies if the chosen property is required, the Type, and Allowed values.

Add the next section of code that defines the security group.

Insert two empty lines after line 7 and insert code to attach RobotAppServer with RobotAppSecurityGroup.

Add the last section of code to the end of the file defining the S3 bucket.

Click the check box icon and ensure that the Template is valid.

Click the top left icon and select Save as a Local file, using the same template name.

Click the upload icon.

Ensure that the saved CloudFormation stack is saved in the specified S3 bucket. Click next.

Specify the Stack name. Click next.

Scroll down and click next.

Scroll down and click Submit.

Refresh and ensure the proper items are being created in Events.

Click the Resources tab and select the Physical ID of RobotAppServer.

Ensure that our instance was created.

Next, go to S3 and select Buckets. Ensure that the RoboticStack bucket exists.

The next step is to vertically scale the virtual server by changing it to a bigger size: Small. Go to CloudFormation and select the stack RoboticStack. Click Update and select Edit template then View in Designer. Change the instance type to t2.small. Ensure the Template is valid.

Click the upload icon and select Replace current template. Click next three times. Scroll down and click Submit.

Click the Resources tab and select the Physical ID of the updated RobotAppServer. Ensure that the Instance type has been changed from t2.micro to t2.small.

Success!