What is EC2 previous-instance-id? - amazon-web-services

admin#ip-172-34-40-199:/var/lib/cloud/data> cat previous-instance-id
i-08070b6e274c5abc6
admin#ip-172-34-40-199:/var/lib/cloud/data> cat instance-id
i-0d865c5d95798349b
My understanding is that instance ids are supposed to be stable. I've found no reference to them changing. The instance that this is from, I just launched moments ago.

The AMI that was the source for these instances was generated from a different instance.
Ie. i-08070b6e274c5abc6 was used to generate ami-deadbeef, then i-0d865c5d95798349b was started from ami-deadbeef. All instances started from that AMI will share the same previous-instance-id.

Instance IDs are stable within the lifetime of an instance. However you can move a volume from one instance to another, or turn a volume into an AMI and launch it as a new instance.
Cloud-init is keeping track of the previous instance ID (pnrobably from when this image was originally created) to know if it should run the firstboot and other tasks that are run once per instance.

Related

Instance Store Volume shared across multiple EC2 Instances

I am trying to understand instance store volume and I understand instance store is ideal for temporary storage and provides massive IOPS. It is retained in case of reboot but lost if you stop and start, hibernation or instance termination.
One question I have here is can Instance store be shared across EC2 instance ?
I am seeing the below in the documentation so asking. Also how to achieve this on AWS console ?
An instance store provides temporary block-level storage for your
instance. This storage is located on disks that are physically
attached to the host computer. Instance store is ideal for temporary
storage of information that changes frequently, such as buffers,
caches, scratch data, and other temporary content, or for data that is
replicated across a fleet of instances, such as a load-balanced pool
of web servers
Documentation taken : https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/InstanceStorage.html
The diagram is showing a physical host computer in an AWS Data Center. The host can be reconfigured to run many different sizes of an Instance Family (eg large, 2xlarge, 4xlarge). Do not be too concerned by the details of what it is showing.
The simple fact is that, no, instance store volumes cannot be shared across multiple Amazon EC2 instances.
The diagram given in the docs is very confusing(at least for me). I am not able to get my head around it. Maybe the InstanceA,B and C are not meant to be EC2 instances but instance store volumes as in the same diagram you see Host Computer 1 and 2.
Also the most important part is
You can specify instance store volumes for an instance only when you launch it. You can't detach an instance store volume from one instance and attach it to a different instance.
Which is what you want to know. It means you cannot share an instance store volume between 2 or more EC2 instances. When the EC2 machine is up and running, there is no way you can attach it and while launching there is no way you can specify which volume to mounted on the EC2 instance when it's created.

Why EC2 instance is stopping again and again?

I can't keep my EC2 instance in running state. Whenever I start the instance it always changing back to "Stopped" state. I tried many ways like they mentioned in this official page here.
Stopped and restarted the instance - didn't work
Created an alternate image of the current instance and launched a new instance with that image and started it. - didn't work
Finally, made a snapshot of current volume of stopped instance. Then created anew volume with that snapshot. Launched a new instance with a new AMI and stopped it. Then detached the root volume of new instance and attached the newly created volume as root volume. Then started the instance - didn't work though.
UPDATE: when I run below command to check the reason for the issue
aws ec2 describe-instances --instance-id MYINSTANCE --output json
it response with below issue
"StateReason": {
"Code": "Client.InstanceInitiatedShutdown",
"Message": "Client.InstanceInitiatedShutdown: Instance initiated shutdown"
},
What am I missing here?
You can try below
Create another fresh instance and ensure its working fine
Remove storage from this instance and attach it to the affected instance
Start your affected instance now which is having new latest storage (make sure to remove old storage)
If it works then it means there is some issue in the storage drive only.
If the above does not work then there is also possible some hardware issue. you can try creating same instance in different region with the same image to see if it works in different region or not.

How can I create an AWS AMI from a running instance but remove costly data

I have an EC2 instance that houses an application and a database. The current instance is running in a production environment with a populated database. I would like to create an AMI of the instance to use as a template for firing up new production servers but with an empty database.
If I just create an AMI from the instance then I believe it will contain all of the data which will have cost implications due to the size on disk and is also a security risk as the AMI would contain customer data.
I thought that I could create an AMI from the instance, then launch a new instance based on that AMI, delete all of the data, create a new AMI based on the new instance, then delete the original AMI and new instance.
My specific questions are:
Will I be able to delete the first AMI if the second AMI was based on an instance created from it?
I understand that the charges for AMIs are incremental in nature. How does it work if a new AMI is created from an instance that is smaller then the AMI that that instance was created from?
Is there a better way of achieving my objective?
Thanks
Will I be able to delete the first AMI if the second AMI was based on an instance created from it?
Yes. You can delete (i.e. de-register) your AMI even if you have an instance running which uses it. But this is something you can easily check on your own. Just create a dummy instance and try creating AMI from it, launch new instance, creating new AMI and so on.
I understand that the charges for AMIs are incremental in nature. How does it work if a new AMI is created from an instance that is smaller then the AMI that that instance was created from?
It won't be smaller. You can't decrease the volume size when you launch an instance from your AMI. You can only increase it. Deletion of your db from the volume will have no effect on the volume size nor its price.
Is there a better way of achieving my objective?
Depends how you define "better". What you described I think is the most logical way.

EC2 - New Instance Vs (remount) EBS-backed instance

I have a an Ubuntu-14.04 EC2 instance running with EBS volume
I regularly take snapshot
I launched a new instance Ubuntu-16.04.
I detach the root volume
I created a EBS volume from snapshot above
I re-attached the volume.
I see all the data and my servers seem to work on the new instance. For eg. mongo, app servers etc.
My question is (other than app data):
What are the differences between the new instance and the instance launched via an existing EBS?
Is the existing-EBS-launched instance supposed to work like the old instance without any changes, out-of-the-box?
What are the differences between the new instance and the instance launched via an existing EBS?
Answer- first of all, understand what EBS is, in a simple language, it is a block storage volume for use with Amazon EC2 Instance.
So Whenever you launch a new Instance via an existing EBS, all the stuff/ any manual changes on the disk which you have done previously will be automatically reflected in your new Instance, as you are using the same disk (Block Storage). It's just when you want any kind of modification like wants to change the key pair at that time we detach the volume, do the modifications and again attach the volume (disk).
Is the existing-EBS-launched instance supposed to work like the old instance without any changes, out-of-the-box?
Answer- yes Existing EBS launched instance work as the old instance, its just what kind of modification you have provided to the new instance. Suppose while launching you have changed the Type of instance, key pair, attach different security group. So all these changes will be reflected and all the manual operations done on Disk will remains same.

Create copy of EC2 instance and launch as new instances

I setup one mail server in one EC2 instances. I want to copy the whole instance and launch as another new instance.
I'm very confused about snapshot and AMI, so please suggest how to do it.
When talking about creating a copy or clone of an instance, there's two aspects to consider:
The configuration of the instance itself, such as Instance Type, Security Group, IAM Role and network subnet
The contents of the disk volume(s)
To launch an instance with the same instance configuration, use the Launch More Like This option in the actions menu, which can launch a new instance with the same configuration. This will also select the original AMI used to launch the initial instance -- please note that this means it will have the same disk as sued when launching the initial instance, but will not have a copy of all data stored/changed on the initial instance since it was first started.
If you wish to make a perfect copy of the instance, including the contents of the disk volume(s), then create an AMI (see documentation for Linux and Windows). This will make a copy of the disk volume(s) so that any instance launched from the AMI will have the same data on disk. Then, launch a new instance from that AMI.