-1

I am trying to clone/transfer an EC2 instance from one AWS account to another by creating an AMI on the first account and sharing it with the second account. Then I can use that AMI to start another EC2 instance (w/ the same data/setup/EBS volumes/etc.) on the second account.

I am having trouble locating the AMI image on the second account. I tried creating another AMI and listing it publicly, still can't find it from the second account.

How would I transfer or clone an EBS-based EC2 instance from one AWS account to another?

Steve
  • 4,946
  • 12
  • 45
  • 62

5 Answers5

1

I think you can only share the image. The files are encrypted with your private account key, so you can't just move the files.

You could try migrating an AMI to the same region to see if it creates a new one: (but I doubt it)

http://docs.aws.amazon.com/AWSEC2/latest/CommandLineReference/ApiReference-cmd-MigrateImage.html

The big picture: You should NOT be manually creating AMIs. Use something like Chef, Puppet or Ansible to build your servers. This new breed of tools is declarative, so it's much easier than building with raw shell scripts. And it would make "rebuild under a different account" trivial.

I like to say:

Level 1: check your source code into version control

Level 2: check your server build script into version control

Level 3: check your "launch/manage my infrastructure" script into version control

BraveNewCurrency
  • 12,654
  • 2
  • 42
  • 50
  • Thanks for the answer, but I am not looking to migrate image between regions. I have created an AMI of the EC2 instance and shared with the second account. I'm just having trouble locating it on the second account to start a new EC2 instance using that AMI. All the corresponding EBS volumes w/ all the contained data should be used/"cloned" on the new EC2 instance running on a different AWS account. – Steve Aug 03 '13 at 23:56
1

Not sure its still actual... But you have to add destination's account number to the AMI permissions and than, if you check "Shared with me" checkbox, you should be able to create instance from that shared AMI image.

enter image description here

NilColor
  • 3,462
  • 3
  • 30
  • 44
0

This might be bit late but you can achieve this by,

  1. Give launch permissions for Account A for Account B's AMIs
  2. Create you EC2 Client by using Account A credentials
  3. Now, call DescribeImages method by filtering with ExecutableUsers parameter with self

This way you will be able to find the AMI images shared with your account by Account B. Keep in mind the AMI-Id will be different from Account B's AMI Id. Check the other Tag names to ensure the correctness of the image.

TeaCupApp
  • 11,316
  • 18
  • 70
  • 150
0

The process to clone/transfer/move an EC2 to another account includes:

Create a new AMI (Amazon Machine Image) from the source EC2 instance using the CLI command create-image in the source region.

Optional: Copy the AMI image to the target region using the copy-image CLI command. This process will take a while so check that copy was completed before you share the new AMI image or the process will fail. Depending on how close regions are and the size of an EC2 instance can take from 10 minutes to hours.

Share the AMI image with the AWS target account. AMIs are a regional resource, so to make an AMI image available in a different region, copy the AMI to the region and then share it. To share the AMI image, we need to use the modify-image-attribute CLI command.

Launch a new EC2 instance from the shared AMI image, using the run-instances CLI command.

The whole process is a little more complicated and involves up to 16 steps if you want to clone security groups, tag the instances and delete temporary AMIs.

I wrote a blog explaining all these steps in detail at https://medium.com/@gmusumeci/how-to-move-an-ec2-instance-to-another-aws-account-e5a8f04cef21

Guillermo

0

Create an AMI of the ec2 instance Share the AMI with the accountid In the 2nd aws account -create instance, choose AMI (shared with me) you should be able to see the shared AMI -Launch instance

subm
  • 44
  • 3