I've followed these instructions to duplicate an AWS, EBS-backed EC2 instance and I'm running into a snag.
This is exactly what I've done:
Created an AMI from the original instance (instance panel: actions>create image)
Launched the AMI as instance using the current keys (AMI panel: launch)
Created a new elastic IP and associated it with the new instance.
Problem: Everything seems fine but I lost connection to the original instance. I ran trace routes for the original IP and it's dropping when it reaches amazon. It doesn't seem to exist despite that it is showing in my panel, associated with the original instance and likewise, the original instance points to the correct IP address.
To trouble shoot, I have now:
Deleted the new AMI
Deleted the new instances
No change. What am I doing wrong? How do I properly duplicate an instance that I can then point to a different IP?
Thank you,
J
It seems that you did nothing wrong when setting up a new instance.
I don't know what you had in that instance, but one idea I have is that when you create an AMI from an instance, the default behavior of AWS is to reboot the instance:
Amazon EC2 powers down the instance before creating the AMI to ensure
that everything on the instance is stopped and in a consistent state
during the creation process. If you're confident that your instance is
in a consistent state appropriate for AMI creation, you can tell
Amazon EC2 not to power down and reboot the instance. Some file
systems, such as xfs, can freeze and unfreeze activity, making it safe
to create the image without rebooting the instance.
Maybe your web-server does not start on system start-up?
Related
Wanted to know more about internals of AWS when we autoscale an instance from one tier to another. Does AWS creates an image and spins up new instance and restores the image ? or what exactly happens inside. ?
Amazon EC2 Auto Scaling will either Launch a new instance or Terminate an existing instance. This is known as horizontal scaling. No instance is "upgraded".
In fact, it is not possible to "upgrade" an Amazon EC2 instance. Instead, you need to Stop the instance, change the Instance Type, then Start the instance again. This will launch the instance on a different host, which is dedicated to running the new Instance Type.
The disks used on Amazon EC2 are (typically) Amazon Elastic Block Store (EBS) volumes. These are network-attached volumes that exist separately to the EC2 instance. Thus, the disks are preserved when the instance is stopped and they are automatically reattached to the instance when it is started again.
So, I'm running an AWS Elastic Beanstalk environment with a single instance.
This particular app is a background job app, and in order to deploy changes to my database, I need to pause the app during the deployment process. I'm running into a couple of problems with this: -
I can stop the EC2 instance for that EBS env, however this eventually terminates that instance, and it will spin up a new instance that immediately tries to run (don't want this, I want to control when the EBS env starts again).
When the new instance starts up, the Elastic IP I've associated to the previous instance gets un-allocated, and is not automatically allocated to the new EC2 instance (this is a problem because my database has an IP firewall, so I need it to keep the same IP, before and after pausing).
I read that associating my EBS to an VPC might solve the IP issue, but I can't figure out how to do that. In my configuration it says "This environment is not part of a VPC.", but there isn't an option to make the environment part of a VPC?
Ideally, I'd love to just "pause" the instance, so that it stops and can be re-started without me losing that instance or the IP configuration of that instance.
Can anyone help me to solve these problems, or provide some other method of configuring this setup?
I'm not so experienced with Beanstalk, but you can use .ebsextension to get a script run at instance start, right? Then use that script to call aws api to get available Elastic IP and assign that to the instance itself.
I had to stop my m3.medium EC2 instance from the AWS console to resize it to m3.large. However, after it stopped, it automatically created a new instance.
Any idea why this is happening? It caused some big troubles for me.
Your AutoScaling group with minimum size = 1 spun up a new instance because there were no instances in the 'running' state available to respond to requests, particularly health checks. Your instance was deemed 'unhealthy' and replaced by the ASG.
If your instance storage was ephemeral, I'm afraid it is gone forever unless you recently saved an AMI. If your instance storage was backed by EBS, you can recover it by attaching the EBS volume to a new instance.
In the future, consider configuring your autoscaling group's launch configuration to have everything you need ahead of time, by either bootstrapping the instance or by baking an AMI.
For 'bootstrapping' an instance:
Create a new launch configuration with a standard AMI avaialble from Amazon.
Add user data to the launch configuration to handle installation and configuration of your desired programs.
For 'baking' an AMI:
Install your desired programs and configuration on a new EC2 instance.
Take an image (AMI) of that EC2 instance.
Use that image in your new launch configuration.
Manually working on an instance within an ASG and expecting the instance to persist indefinitely is dangerous, as you've just discovered.
Further Reading:
EC2 Documentation - AutoScaling Health Checks
EC2 Documentation - Amazon Machine Images
I would like to create AMI image based on my current EC2 Linux instance. There are things that bothers me tough, and I didn't find any accurate answer to my questions on the web.
My current EC2 instance has:
two private interfaces like eth0 and eth0:1
two elastic IP addresses, each of them points to above ifaces
The answer I'm missing is, will the new instance launched based on this image be created in the same manner? Duplicating somehow my current settings, etc? Is it even a problem if cloned 1:1? Since, that would be more sufficient from the Load Balancing standpoint.
From the other side, it can't be duplicated in the meaning of private IP addressing, cause I wouldn't be able to differentiate them connecting with ssh. Any1 has some experience creating images based on EC2 instances, and can hint me how it looks?
When launching an instance from an Amazon Machine Image (AMI), the disks will contain an exact copy of the disk at the time that the AMI was created.
However, other attributes might be different when launching a new instance, such as the number of Elastic Network Interfaces and, of course, the IP address will most likely be different. Therefore, you will need to request similar settings from EC2 when then instance is launched.
We are facing two problems with EC2 and RDS instances:
We are loosing existing data, when the existing EC2 instance is terminated and new EC2 instance is created automatically. Once we create Elastic Beanstalk and upload our application files, its creating one EC2 instance and running. And then next if we upload any files to the existing EC2 instance and in case its going down/terminated, one more new instance is getting created and loosing the data from the old EC2 instance.
If we add the EC2 instance ip address to the RDS inbound security group to restrict others from accessing RDS instance from other ips, we are facing problem to access RDS, when the old EC2 instance is terminated and new EC2 instance is created or any other new ec2 instance is created based on load.
Kindly suggest some solution for the above issues.
Any data you store in EC2 is going to get lost if/when the instance is terminated. You need to design your solution so that it is not dependent on ephemeral subsystems.
Exactly how, will depend on what you are doing, but for example, if you are hosting a web server and the user can upload images, better to store them on S3 instead of directly in the EC2 instance. Data should be stored in a database also not on the EC2 instance, so in an RDS instance or DynamoDB both of which will survive an EC2 termination and restart.
For the access problem, you create a security group (call it sg-1234 for example), and then make each of your new instances created with that security group when they start.
Also create an RDS security group (call if db-1234 for example) and in the DB-1234 security group create a rule that allow Sg-1234 as a source.