Deleting the instance once the AMI was created(using CFT) - amazon-ec2

Problem Statement:
I need to create an instance using CFT, once the instance was created I need to create AMI from that instance and then delete the instance.
I gone through some of the stack overflow questions with respect to my problem statement.
https://stackoverflow.com/a/41681815 -->here they explain about creating AMI from instance after the instance was launched, but I don't know how to delete the instance once the AMI was created.
Can anyone please explain how to do that?
Thanks in advance for you responses

Related

How to create /etc/krb5.conf on EC2?

I was following a guide on connecting to Kafka from EC2 instance and one of the steps was to check if '/etc/krb5.conf' exists on my EC2.
On my EC2 instance it only exists folder '/etc/krb5.conf.d' but not '/etc/krb5.conf'. From internal discussion with several people - they believe it should exist by default. Not sure why my instance do not have it.
Should it exist by default once new EC2 (RHEL 7.3) is started?
If not - how to create it manually?
While I'm not sure why a /etc/krb5.conf doesn't exist by default on your new EC2 (RHEL 7.3), I will say on all instances of Linux I have ever seen that file exists as /etc/krb5.conf. What I would do is simply copy /etc/krb5.conf.d to /etc/krb5.conf. Please ensure that it is properly configured for your Kerberos realm - to do that see the MIT example here.

How to create a ec2 instance in cloudfomration from the AMI of the instance which is also created by cloudformation

I have created a EC2 Instance using the cloud formation script and in that process I have executed around 20 commands in "AWS::CloudFormation::Init". This is a windows instance.
After that, I created a image from this and tried to create another EC2 instance using this image with couple of commands I wanted to be executed in "AWS::CloudFormation::Init".
This is giving me problem. The instance after getting created is not running the new commands which I specified in the template. But trying to run the commands which I specified while creating the old EC2Instance from which image was taken. This is through sysprep process which was given in one of the docs.
Is there any way to execute only the new commands and leaving out the old commands when the new image is created. I tried many alternatives. It is either executing old commands or none at all.
Have you stopped your instance before creating your image ? (like advised here).

Mounting Old EBS Volume to the new Instance - Amazon EC2

1) I had an instance and sudo commands were not working do to some mistakes on this instance
so i had to create a new instance.
2) I want to use old EBS volume with new instance and to stop old instance.
3) I created a new instance (New EBS Volume is created automatically with new instance)
4) I created snapshot of old volume and attached with new instance.
5) So two EBS volumes are attached with new instance.
6) When i login using SSH into new instance, i don't see old data anywhere.
7) I want every old data on new instance.
my question is.....
how i can use old volume with new instance?
please help me.. i am trying it from last 10 hours continuously :(..
What you need to do is mount the old volume on the new instance. Go to the Amazon EC2 control panel, and click "Volumes" (under Elastic Block Store). Look at the attachment information for the old EBS volume. This will be something like <instance id> (<instance name>):/dev/sdg
Make a note of the path given here, so that'd be /dev/sdg in the example above. Then use SSH and connect to your new instance, and type mkdir /mnt/oldvolume and then mount /dev/sdg /mnt/oldvolume (or whatever the path given in the control panel was). Your files should now be available under /mnt/oldvolume. If this does not solve your problem, please post again with the output of your df command after doing all of this.
So, to recap, to use an EBS volume on an instance, you need to attach it to that instance using the control panel (or API tools), and then mount it on the instance itself.

nothing happens on libcloud create_node

I use libcloud to create a new node instance Amazon EC2.
conn.create_node returns me a valid instance and printing node.dict shows the expected values.
however when I check my EC2 dashboard the new machine does not appear there.
do I need my python app to stay open so that the node is actually created?
found it: the instance was actually created but for some reason the amazon did not show it even after refresh. logging out and in solved it.

AWS console not showing all instances during volume attach

I do the following using AWS web console:
Attach EBS volume-A to instance-A. Make some changes to data on volume-A and detach it
Launch new instance-B (in the same zone as instance-A)
Try attach volume-A to the new instance-B. But the new instance does not appear in the instances list during attach volume process (dialog box).
If I try the same attach using command line EC2 API (volume-A and instance-B), it works fine!
Do you know if this is a bug in AWS web console or am I doing something wrong in the console? Tried page refresh in Step #3 but it still would not list the new instance.
In order to attach, both volumes has to be in the same zone. So if you are going to attach a volume into a instance check the zone of the instance's attached volume. If those are not matching create a new instance with the same zone as the zone of the volume that you need to attached.
The volume and the instance have to be in the same region AND the same zone.
If you have a volume in us-east-1a and the instance in us-east-1b, you would need to move the volume to us-east-1b to make it work.
Even I had faced this problem yesterday and a day before. It looks like Amazon problem with their cache. Not sure WHY.
To bring back the stuff as is, I had to sign-out and make sure things are good. But it's always good to work with CLI, works better.
Although the user interface may not list the instance ID, you can attempt to add the volume anyway. If it's genuinely impossible (rather than a cache issue) you will get an error message.
Paste in the instance ID (i-xxxxxxx) manually then type your mount point (e.g. /dev/sdf) and click Attach.
For the benefit of others: some instance types do not support encrypted volumes, which may be why the instance doesn't appear in the list. I get the following error:
Error attaching volume: 'vol-12341234' is encrypted and 't2.medium' does not support encrypted volumes.

Resources