How do I automate the creation of AMIs based on my EBS-backed EC2 instance using Systems Manager Automation?

Last updated: 2019-07-29

I want to automate the creation of AMIs of EBS-backed Amazon Elastic Compute Cloud (Amazon EC2) instances. How can I do this?  

Short Description

You can use AWS Systems Manager to create a maintenance window and register an automation task to automate the creation AMIs. This process is applicable for both Windows and Linux instances.

The instance that you want to create an AMI for must be listed as a managed instance in Systems Manager. First, verify that the instance meets all prerequisites for using Systems Manager. If the instance uses a private subnet, you can create VPC endpoints for Systems Manager.

Note (Windows only): Sysprep is not run on Windows instances before creating an AMI when you use the following automation process.


To automate the creation of AMIs, follow these steps:

  1. Create an AWS Identity and Access Management (IAM) role with permissions to create an AMI for the maintenance window. You can use the IAM console, AWS Command Line Interface (AWS CLI), or Tools for Windows PowerShell.
  2. Create a maintenance window.
    On the Schedule section, for Specify with, choose Cron schedule builder.
  3. Assign targets to the maintenance window.
  4. Register an Automation task to create an AMI.
    For Actions, choose Register Automation task.
    For Automation document, choose AWS-CreateImage.
    For IAM service role, choose Use a custom service role, and then choose the IAM role that you created in step 1 of this article.
    On the Input parameters section, for InstanceId, enter the pseudo parameter placeholder {{TARGET_ID}}.