What is Amazon Machine Image (AMI)?
An Amazon Machine Image is a special type of virtual appliance that is used to instantiate (create) a virtual machine within EC2. It serves as the basic unit of deployment for services delivered using EC2. Whenever you want to launch an instance, you need to specify AMI. To launch instances, you can also use different AMIs. If you want to launch multiple instances from a single AMI, then you need multiple instances of the same configuration.
Properties of AMI
An AMI contains:
1. A root volume template
Think of this as the base for your instance, which includes things like the operating system and applications.
2. Launch permissions
These control who can use the AMI to create instances.
3. Block device mapping
This defines which storage volumes are attached to your instance when it’s launched.
When selecting an AMI, you’ll need to consider:
- Region: Where you want to store the AMI (as pricing may vary by region).
- Permissions: Who can use the AMI.
- Operating System: The OS for your instance.
- Storage: How the root device is managed (EBS or instance store).
- Architecture: Whether the AMI is for a 32-bit or 64-bit system.
Use an AMI
You can create your own customized AMI from an existing ec2-instance with the help of snapshots. After creating a snapshot you create a new ec2-instance by using the existing one know the new instance is the copy of an existing instance with all the required data in it. You can search for an AMI that meets the criteria for your new instance and you can use that instance to create a new instance as shown in the following figure.
Why do we need AMI?
Let us suppose that we want to launch 5 servers with the same configuration. One way of doing that would be to launch a new EC2 instance every time and install the required packages every time. While the other way of doing it would be to configure your EC2 instance once and then create an image of that instance. Using that image you can deploy four more EC2 servers.
Steps to create your own AMI
Step 1: Click on the launch instance button on the AWS management console.
Step 2: Now you will be asked to select an already available AMI. Select the Free tier and then select the Amazon Linux 2 AMI.
Step 3: Select t2.micro eligible (Instance types in aws) for the free tier. Now click on next: configure Instance details.
Step 4: Here you can select the various configurations related to the EC2 instance. Click on Next: Add storage.
Step 5: Select the amount of storage you want for the EC2 instance. Click on Next: Add tags and then click Next: configure security groups.
Step 6: Here you can add the security groups to allow the desired traffic for your instance. Click on review and launch.
Step 7: Review all the configurations regarding the EC2 instance. Click on Launch.
Step 8: Choose to create a new key pair option and write the key pair name. Download the key pair and then click on the launch instance.
Step 9: We can see that the instance is launched and running in a healthy state. Now It is required to create the Amazon Machine Image of this instance.
Step 10: Click on actions. Go to the image and then click on create an image.
Step 11: A prompt will open wherein you are required to write the name of the image. Click on create an image.
Step 12: The image creation request is received. Now the image will be created. Click on close. Now go to AMI services in the AWS management console.
Step 13: The AMI image of our instance is created successfully.
AMI Types
Amazon Machine Images (AMIs) are templates used to create virtual machines (EC2 instances) in AWS. There are four main types of AMIs:
1. Amazon-provided AMIs
These are default images from AWS, offering basic operating systems like Amazon Linux, Windows, and more. They come pre-configured and are regularly updated by AWS.
Best for: Quick setups with standard configurations.
2. Marketplace AMIs
Available for purchase in the AWS Marketplace, these AMIs include third-party software and services, often with licensing fees.
Best for: Deploying specific software or enterprise applications that require licensing.
3. Community AMIs
These are publicly shared AMIs created by other AWS users. They are free to use but may not have the same level of support or reliability.
Best for: Experimenting, collaborating, or using custom setups.
4. Custom AMIs
These are AMIs created by users from their own customized EC2 instances. Once you've configured an instance with your specific settings, you can save it as a custom AMI to use again.
Best for: Replicating custom configurations across multiple instances.
Each type of AMI is designed for different needs whether you're looking for a quick, basic setup or a fully customized environment.
Buy, share and sell AMIs
If you created a customized AMI according to your needs for the organization if it is highly confidential you can keep that AMI in private or if it can be shared with the public you can keep it in the community so others can use it.
Instead of you creating customized AMIs for your organization you save effort forth and time by using the AMIs which are created by third-party organizations such as Red Hat, and Ubuntu. You can create your own customized AMI and sell it to other Amazon EC2 users depending on their need.
Pricing of AMI
1. Public AMIs
These are free to use.
2. Private AMIs
If you create a private AMI, you’ll pay depending on the storage region and other factors. The cost is generally higher for private AMIs compared to public ones.
3. Region-based Pricing
Pricing can differ depending on where your AMI is stored. For example, the cost will vary between regions like the US and Asia Pacific.
4. Data Transfer Costs
You may also incur charges for transferring data in and out of AWS.
5. Private AMI Costs
If you use a private AMI created by someone else, you may have to pay the price set by the AMI creator.
Types of EC2-Instances
There are different types of EC2-Instances types which are defined for certain use cases and unique requirements for different workloads and different applications depending on your use cases like depending on the computing, memory, or storage you required. for more read Amazon EC2 – Instance Types
Advantages Of Amazon EC2
- Highly scalable: Amazon ec-2 instance will allow you to scale your infrastructure very easily and highly. You can increase and decrease the memory and CPU whenever you required depending upon the traffic.
- Highly available: Amazon ec2-instance is highly available because you can configure it multiple availability zones and if there is a failure in one zone you can automatically access the infrastructure which is available in another zone.
- Integration: You can integrate ec2-instance with multiple aws resources which are available in AWS such as S3, Autoscaling group, Load Balancing, RDS, and so on.
- EC2-Instance is secure: Ec2-instance is more secure because it can be integrated with VPC (virtual private cloud). ec2 can be configured in multiple private subnets where it is very hard to penetrate into it.
- Global Infrastructure: Amazon ec2-instance is available in multiple regions and multiple zones by which you can deploy your applications near to your users which will decrease the latency and improves the performance of the application.