AMI
Created: 2016-02-17 11:25:12 -0800 Modified: 2018-09-26 10:52:26 -0700
AMI (Amazon Machine Images)
Section titled AMI (Amazon Machine Images)General information
Section titled General information- To view any AMIs that you’ve created, go to EC2 Dashboard —> Images —> AMIs
- Creating AMIs is as easy as creating a snapshot in a hypervisor:
- Spawn a base image (into an EC2 VM)
- Make changes over SSH
- Stop it.
- Create an AMI from it (see below)
To create an image (reference):
Section titled To create an image (reference):- First, make sure to reduce start time by deleting temporary files, defragmenting your hard drive, and zeroing out free space. It’s also a good idea to “apt-get update” and “apt-get upgrade”.
- Also, it’s a good idea to clear your Bash command history so that you don’t have setup commands when you press “up” after logging in (reference)
- Note: this command will disconnect your SSH session thanks to the “exit”
- cat /dev/null > ~/.bash_history && history -c && exit
- Note: this command will disconnect your SSH session thanks to the “exit”
- To actually make the image, go to your EC2 Dashboard —> Instances —> Actions —> Image —> Create Image
- You probably do not want “No reboot” checked
- You probably want “Delete on termination” checked, otherwise you could have stray EBS volumes.
- Note: this will take ~5 minutes since it has to copy the entire disk, and the only indication that it’s doing something is in the EC2 Dashboard → Images → AMIs UI. Note that even then, you may not see an entry get added to that dialog for a couple of minutes even if everything is fine.
- The image that you create will be backed by EBS. You wouldn’t want to put it in something like S3 unless you needed to make it public.
Note: most images you create are going to have a minimum size of 8 GB. To lower this amount, you can rsync to another mounted EBS volume by following these instructions. WARNING: these instructions will waste 5 hours of your time unless you know what you’re doing with Linux.
To update an image, check out this note
Section titled To update an image, check out this noteIt’s basically just:
- Make a machine with the AMI you want
- Run the creation steps again
- Delete the old AMI
- Update references to the new AMI
To delete an AMI
Section titled To delete an AMI- BEFORE PROCEEDING, REMEMBER THE AMI ID FOR THE STEP BELOW! In the EC2 Dashboard, Images —> AMIs —> Actions —> Deregister. This only removes the AMI, not the snapshot backing it.
- Delete the EBS snapshot that backed the AMI. You can find this because the AMI ID (which you got in the step above) should be in the name or description (it looks like this: “Created by CreateImage(i-9e34f546) for ami-e7b25287 from vol-ab5b306b”).