AWS CLI archive ami

I use Amazon’s Daily Backup service which creates Amazon Machine Images from snapshots which I keep for a year in S3 Deep Archive and then automatically delete using a Lifecycle Rule (Daily backups.) However I’ve upgraded the Git server and I want to keep a copy of the old one in a bucket of old instances. I want to try using the cli again rather than the AWS console. Firstly choose the profile, then search for the ami:

export AWS_PROFILE=xyze
aws ec2 describe-images --owners 000000000000 --output table | grep -B50 git | grep ImageId

This uses an option ‘owners’ which is your AWS account. Help with the command can be viewed using the help:

aws ec2 describe-images help

As previously (AWS CLI start instance) its useful to check we’ve got the right one:

aws ec2 describe-images --output table --image-ids ami-0905c88505b225019

This command stores the image in s3:

aws ec2 create-store-image-task --s3-object-tags Key=Name,Value=old-git --image-id ami-0905c88505b225019 --bucket old-instances

And this renames the file and moves it into Glacier Deep Archive:

aws s3 mv s3://old-instances/ami-0905c88505b225019.bin s3://old-instances/old-git.bin --storage-class DEEP_ARCHIVE

Leave a comment