PART-A AWS AMI Automation using (SSM) Systems Manager Automation service Automating the Creation and Management of Amazon Machine Images (AMIs)

Saket Jain
3 min readJan 15, 2023

Steps to be performed by this automation:

Step 1. Create an Amazon Machine Image (AMI) from the provided instance ID

Step 2. Create a launch template using the AMI created in step 1

Step 3. Start refreshing instances in the Auto Scaling group using the launch template

Prerequisite

Before you begin
Complete the following tasks before you begin this example.

Configure IAM roles for Automation, a capability of AWS Systems Manager. Systems Manager requires an instance profile role and a service role ARN to process automation. For more information, see Setting up Automation.

Create a role with the required access

Search for Systems Manager service > Click on Documents

Now click on Owned by me

Create a document then click on the automation

Enter the name Choose the Editor tab, and choose Edit.

Click on Editor then Edit

Choose OK when prompted, and delete the content in the Document editor field.

In the Document editor field, paste the following YAML below is the runbook content.

Choose to Create automation button.

  1. In the navigation pane, choose Automation, and then choose Execute automation.
  2. In the Choose document page, choose the Owned by me tab.
  3. Search for the PatchAMIAndUpdateASG runbook, and select the button in the PatchAMIAndUpdateASG card.
  4. Choose Next.
  5. Choose Simple execution.

Click on Execute

To see your running executions go to executions pannel

Below you can see the executions

Click on the Execution ID

All steps have run successfully.

Reference links
Resources:

[1] Create a new image -
https://docs.aws.amazon.com/systems-manager/latest/userguide/automation-action-create.html

[2] StartInstanceRefresh — https://docs.aws.amazon.com/autoscaling/ec2/APIReference/API_StartInstanceRefresh.html

[3] create_launch_template — https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/ec2.html#EC2.Client.create_launch_template

[4] Updating AMIs for Auto Scaling — groupshttps://docs.aws.amazon.com/systems-manager/latest/userguide/automation-tutorial-update-patch-windows-ami-autoscaling.html

--

--