Create a store image task
When you store an AMI in an S3 bucket, a store image task is created. You can use the store image task to monitor the progress and outcome of the process.
Contents
Securing your AMIs
It is important to ensure that the S3 bucket is configured with sufficient security to secure the content of the AMI and that the security is maintained for as long as the AMI objects remain in the bucket. If this can't be done, use of these APIs is not recommended. Ensure that public access to the S3 bucket is not allowed. We recommend enabling Server Side Encryption for the S3 buckets in which you store the AMIs, although it’s not required.
For information about how to set the appropriate security settings for your S3 buckets, review the following security topics:
When the AMI snapshots are copied to the S3 object, the data is then copied over TLS connections. You can store AMIs with encrypted snapshots, but the snapshots are decrypted as part of the store process.
Permissions for storing and restoring AMIs using S3
If your IAM principals will store or restore AMIs using Amazon S3, you need to grant them the required permissions.
The following example policy includes all of the actions that are required to allow an IAM principal to carry out the store and restore tasks.
You can also create IAM policies that grant principals access to specific resources only. For more example policies, see Access management for AWS resources in the IAM User Guide.
Note
If the snapshots that make up the AMI are encrypted, or if your account is enabled for encryption by default, your IAM principal must have permission to use the KMS key.
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"s3:DeleteObject",
"s3:GetObject",
"s3:ListBucket",
"s3:PutObject",
"s3:PutObjectTagging",
"s3:AbortMultipartUpload",
"ebs:CompleteSnapshot",
"ebs:GetSnapshotBlock",
"ebs:ListChangedBlocks",
"ebs:ListSnapshotBlocks",
"ebs:PutSnapshotBlock",
"ebs:StartSnapshot",
"ec2:CreateStoreImageTask",
"ec2:DescribeStoreImageTasks",
"ec2:CreateRestoreImageTask",
"ec2:GetEbsEncryptionByDefault",
"ec2:DescribeTags",
"ec2:CreateTags"
],
"Resource": "*"
}
]
}
Create store and restore image tasks
To store an AMI in an S3 bucket, start by creating a store image task. The time it takes to complete the task depends on the size of the AMI. You can track the progress of the task until it either succeeds or fails.
To create the store image task
Use the create-store-image-task command. Specify the ID of the AMI and the name of the S3 bucket in which to store the AMI.
aws ec2 create-store-image-task \ --image-id
ami-1234567890abcdef0
\ --bucketamzn-s3-demo-bucket
The following is example output.
{ "ObjectKey": "ami-1234567890abcdef0.bin" }
To describe the progress of the store image task
Use the describe-store-image-tasks command.
aws ec2 describe-store-image-tasks
The following is example output.
{ "StoreImageTaskResults": [ { "AmiId": "
ami-1234567890abcdef0
", "Bucket": "amzn-s3-demo-bucket
", "ProgressPercentage": 17, "S3objectKey": "ami-1234567890abcdef0
.bin", "StoreTaskState": "InProgress", "StoreTaskFailureReason": null, "TaskStartTime": "2022-01-01T01:01:01.001Z" } ] }
To create a restore image task
Use the create-restore-image-task command. Using the values for
S3ObjectKey
and Bucket
from the
describe-store-image-tasks
output, specify the object key of
the AMI and the name of the S3 bucket to which the AMI was copied. Also specify
a name for the restored AMI. The name must be unique for AMIs in the Region for
this account.
Note
The restored AMI gets a new AMI ID.
aws ec2 create-restore-image-task \ --object-key
ami-1234567890abcdef0
.bin \ --bucketamzn-s3-demo-bucket
\ --name "New AMI Name
"
The following is example output.
{ "ImageId": "ami-0eab20fe36f83e1a8" }