Can I convert S3 backed AMI to EBS backed AMI? - amazon-web-services

Can I convert S3 backed AMI to EBS backed AMI? If yes, how?
Can I convert EBS backed AMI to S3 backed AMI? If yes, how?

When an Amazon EC2 instance is started, the contents of the chosen Amazon Machine Image (AMI) are copied to the boot disk. This boot disk can be either:
EBS-Backed, meaning the boot volume is created on an EBS volume (that persists even when the instance is stopped), or
Instance Store-Backed (aka S3-backed because the AMI is kept in Amazon S3), meaning that the AMI is copied to the Instance Store (aka Ephemeral disk), which is lost when the instance is stopped.
In the early days of EC2, only Instance Store was available. These days, EBS is the preferred storage medium. The only benefit of using Instance Store-Backed AMIs these days is that it's cheaper (no charge for EBS), but the instances can't be stopped and the data on the disk is lost when the machine stops.
Here's some links to instructions for converting between the types:
StackOverflow: Amazon EC2 - Convert EBS root device with instance store root device
StackOverflow: Amazon EC2 - Swap root instance store device with EBS device
AWS Blog: Converting an S3-Backed Windows AMI to an EBS-Backed AMI

Related

AWS launch new instance using Ubuntu 22.04: image has more volumes than instances allows

AWS launch new instance using Ubuntu 22.04:
The selected AMI contains more instance store volumes
than the instance allows. Only the first 0 instance
store volumes from the AMI will be accessible from the
instance
What does it mean? does an AMI have volumes?
EC2 instances can have two basic types of volumes: EBS (Elastic Block Store) and Instance Store. This article spells out the differences, but in a nutshell, EBS volumes are network attached storage that are independent of an instance, while Instance Store volumes are local block storage volumes that are not persistent (e.g. when the instance is terminated, the instance store volume is lost).
You ask if an AMI has volumes. An AMI basically is one or more volumes. The AMI is a snapshot of a disk in a particular state. These days, most modern AMIs use EBS storage for the root volume; that is, the volume that contains the operating system kernel that an instance boots from. It used to be commonplace to use Instance Store for the root volume, but EBS has become nearly as fast, more secure, and more reliable than Instance Store, so the use cases for Instance Store volumes are dwindling.
With all that said, I'm quite surprised that you're seeing this error. The error message suggests that the AMI includes Instance Store but the instance type you selected does not support Instance Store (many instance types do not). However, all Ubuntu 22.04 AMIs use EBS, not Instance Store. If you use the Ubuntu Amazon EC2 AMI Locator and search for "22.04", you'll find that all of the results have hvm:ebs-ssd as the instance type. Only very old Ubuntu AMIs have Instance Store volumes.
Make sure you are using the AMI Locator to find the Ubuntu 22.04 AMI. Those AMIs should work with most or all EC2 instance types.

AWS EC2: AMI vs instance type EBS selection

While creating EC2 instance on AWS, I see following AMI options:
Amazon Linux 2 AMI (HVM) - Kernel 5.10, SSD Volume Type
macOS Monterey 12.2.1 - ami-00aa9c0d2393d0139 The macOS Monterey AMI is an EBS-backed, AWS-supported image
First option tells that disk storage is SSD volume type which I assume means that storage used is instance's local storage. Second option tells that storage is elastic block storage.
I opt for first one.
Then on next step for instance type:
Why does it displays 'EBS only' for 'Instance Storage(GB)' column as in previous step I opted for non-EBS type? Are those unrelated?
An AMI will always restore to an EBS volume (or multiple EBS volumes). An AMI is really just a snapshot of one or more EBS volumes, plus some metadata. EBS volumes can be SSD or Magnetic. Your assumption that "SSD Volume Type" indicated local instance storage is incorrect.
Instance storage is ephemeral. An EC2 server never boots from an instance storage volume. Certain instance types come with instance storage that are good for things like fast temp folders, caches, etc. But instance storage volumes can't be saved to snapshots or AMIs, can't be persisted across stops/start cycles, and can't be moved between EC2 instances.

Stoping an EC2 instance without losing the data on a mounted ephemeral drive?

I'm using an EC2 instance on amazon and have mounted a 1TB ephemeral to the instance. The instance is an on-demand instance that costs $5 an hour. I was wondering whether there is anyway that I could stop (not terminate) the instance and still keep my data on the mounted ephemeral drive?
The Amazon EC2 Instance Store documentation says that if I stop it, I will lose the data. Does anyone have a solution?
Instance Store is disk storage directly-attached to the Amazon EC2 host machine. When an EC2 instance is Stopped, the virtual machine is removed and it loses the CPU, RAM and Instance store so that it can be allocated to another user.
Data saved on Amazon EBS disk volumes are retained because this is network-attached storage that is kept separate from the Host computer.
The only way to "save" your data is to copy it to another location (eg an EBS volume or Amazon S3 bucket) before stopping the instance.
You can use Amazon Elastic Block Store volumes for an ec2 instances. Once you stopped your instance, ebs volumes will retain the data. You can take snapshots on your ebs volume by specific time or incremental snapshot based on your requirement. BTW, You can store the snapshot in AWS S3 bucket for backup purposes. You can copy snapshot to different region via AWS Management Console or AWS API calls.
If you choose instance store volume type, you will lose your data. For persistent disk storage you can choose AWS EBS volumes.

Launch EBS backed AMI as an Instance store machine

How do I launch an EBS backed AMI as an instance store machine with out having to do too much hack? Also, more specifically, can I launch this using in an autoscaler?
I can answer the first part of your question. As far as I know you can not launch an EBS backed AMI as instance store machine. Instead what you can do is create an IS (instance store) backed AMI from the EBS backed running instance and use that to launch instance store backed instances.
The process of converting EBS backed instance to IS backed AMI not so straight forward. You need to start from a EBS backed paravirtual instance and after that I followed this answer for the conversion. To install AWS tools and command line utilities use this AWS tutorial.

What data is stored in Ephemeral Storage of Amazon EC2 instance?

I am trying to stop a Amazon EC2 instance and get the warning message
Warning: Please note that any data on the ephemeral storage of your instance will be lost when it is stopped.
My Question
What data is stored in ephemeral storage of an Amazon EC2 instance?
Basically, root volume (your entire virtual system disk) is ephemeral, but only if you choose to create AMI backed by Amazon EC2 instance store.
If you choose to create AMI backed by EBS then your root volume is backed by EBS and everything you have on your root volume will be saved between reboots.
If you are not sure what type of volume you have, look under EC2->Elastic Block Store->Volumes in your AWS console and if your AMI root volume is listed there then you are safe. Also, if you go to EC2->Instances and then look under column "Root device type" of your instance and if it says "ebs", then you don't have to worry about data on your root device.
More details here: http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/RootDeviceStorage.html
Anything that is not stored on an EBS volume that is mounted to the instance will be lost.
For example, if you mount your EBS volume at /mystuff, then anything not in /mystuff will be lost. If you don't mount an ebs volume and save stuff on it, then I believe everything will be lost.
You can create an AMI from your current machine state, which will contain everything in your ephemeral storage. Then, when you launch a new instance based on that AMI it will contain everything as it is now.
Update: to clarify based on comments by mattgmg1990 and glenn bech:
Note that there is a difference between "stop" and "terminate". If you "stop" an instance that is backed by EBS then the information on the root volume will still be in the same state when you "start" the machine again. According to the documentation, "By default, the root device volume and the other Amazon EBS volumes attached when you launch an Amazon EBS-backed instance are automatically deleted when the instance terminates" but you can modify that via configuration.
To be clear and answer #Dean's question: EBS-type root storage doesn't seem to be ephemeral. Data is persistent across reboots and actually it doesn't make any sense to use ebs-backed root volume which is 'ephemeral'. This wouldn't be different from image-based root volume.
For EC2 instance
Stop & Start != Reboot
so for ephemeral storage (Instance Store)
Stop cause data lost
Reboot will not
According to AWS documentation [https://aws.amazon.com/premiumsupport/knowledge-center/instance-store-vs-ebs/] instance store volumes is not persistent through instance stops, terminations, or hardware failures.
Any AMI created from instance stored disk doesn't contain data present in instance store so all instances launched by this AMI will not have data stored in instance store. Instance store can be used as cache for applications running on instance, for all persistent data you should use EBS.
ephemeral is just another name of root volume when you launch Instance from AMI backed from Amazon EC2 instance store
So Everything will be stored on ephemeral.
if you have launched your instance from AMI backed by EBS volume then your instance does not have ephemeral.
refer: https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/InstanceStorage.html#instance-store-volumes
The data in an instance store persists only during the lifetime of
its associated instance. If an instance reboots (intentionally or
unintentionally), data in the instance store persists. However,
data in the instance store is lost under any of the following
circumstances:
- The underlying disk drive fails
- The instance stops
- The instance hibernates
- The instance terminates