(upbeat music)
- Hi, I'm Swara, a cloud support engineer
here at AWS office in Bengaluru, India.
Sometimes customers ask me how they can automate
the creation of AMIs of EBS-backed EC2 instances,
so today I'll be showing you one of the methods
using Systems Manager.
Let's get started.
The instances for which you want to create the AMIs
using Systems Manager must be listed
as managed instances under SSM.
In this lab, we will create a maintenance window
and then register an automation task
for creating an AMI.
Let's first create an IAM role with sufficient permissions
to create an AMI for the maintenance window.
After logging in to the AWS Management Console,
navigate to the IAM console.
In the left navigation, select Roles
and then choose Create Role.
Select EC2 service, choose Next: Permissions.
Enter amazonSSMaintenanceWindowRole in the search bar
and select the policy.
Choose Next: Tags.
Enter a role name SSMRoleAMICreation and description.
Choose Create Role.
Go back to Roles again and then search for the role
created just now, SSMRoleAMICreation.
Choose Add Inline Policy.
And then choose a service, select EC2.
Under write access level, select CreateImage action.
Under read list access level, select DescribeImages action.
Choose Review Policy and give the role a name.
Choose Create Policy.
Select the role again,
and go to the Trust Relationships.
Edit Trust Relationship.
Add ssm.amazonaws.com.
Click Update Trust Policy.
Now navigate to Systems Manager Console.
Then select Maintenance Windows under Actions
in the left navigation of the page.
Choose Create Maintenance Window.
Give a suitable name and description
for the maintenance window.
Select Cron Schedule Builder under Schedule.
I'm choosing every Tuesday 12 PM UTC
as a schedule for the maintenance window in this video.
You can schedule the maintenance window
as per your requirement.
Specify the duration.
I'm giving the duration as two hours
and one hour for Stop Initiating Tasks.
Choose Create Maintenance Window.
Now select the maintenance window
which was created just now,
go to Actions, Register Targets.
Give the target a name and description.
Select the targets, that is, the instances
that obey your tags, or by manually selecting them.
Choose Register Target.
Now go back to the maintenance window we just created
and go to Actions, Register Automation Task.
Enter a name and description.
Select the document AWS-CreateImage.
Now select the registered target group.
You can also manually select the instances here
if you haven't registered the targets.
Select the Concurrency and Error Threshold.
I'm specifying it to be one for both in this video.
You can give these values as needed.
Select the role created as the same role,
SSMRoleAMICreation earlier here.
Under the Input Parameters, give the value
for instance ID as TARGET_ID.
Note that the TARGET_ID mentioned here is case sensitive.
TARGET_ID passes the instances registered in the target
as input to the automation document.
If NoReboot is selected as true,
note that the file system integrated
of the created image isn't guaranteed.
The default value is false,
which will power down the instance before creating an AMI.
Choose Register Automation Task.
By following these instructions,
every Tuesday at 12:00 UTC,
an AMI will be created for each targeted EC2 instance.
With the help of the steps performed,
an AMI can be created for both Windows and Linux instances.
Note that SYSPREP is not performed on Windows instances
before creating AMI using these processes
described earlier.
Thanks for watching and happy cloud computing
from all of us here at AWS.
(upbeat music)