AWS Importing Local VM using AWS CLI Step By Step

In this post, I will share the details on importing the local virtual machine to the Amazon cloud. This post will be helpful to import the local virtual machine on our machine into Amazon cloud and use it as the Amazon EC2 instance.

(1) Install CLI install the AWS Command Line Interface from Amazon CLI Documentation 

(2) configure CLI referring to CLI Documentation, you can just type aws configure

(3) And enter the access key and secret generated in the AWS website. For instance:

(4) To update any of your settings, simply run aws configure again and enter new values as appropriate.

(5) Create a S3 bucket on AWS and upload the OVA file manually there

(6) Give the user access to create role (you can give the admin access, more details on AWS IAM documentation  or you can give the individual roles, check AWS VM Documentation

Screen Shot 2016-06-01 at 9.33.13 PM.png

(7) Create a user role VM. Import uses a role in your AWS account to perform certain operations (e.g: downloading disk images from an Amazon S3 bucket). You must create a role with the name vmimport with the following policy and trusted entities. Create a file named trust-policy.json with the following policy:

(8) Use the following command to create a role named vmimport and give VM Import/Export access to it

(9) Creating a policy for the service role and save it as role-policy.json

(10) Replace <disk-image-file-bucket> with the appropriate Amazon S3 bucket where the disk files are stored. Run the following command to attach the policy to the role created above:
(11) Import the VM image using the AWS CLI (refer AWS CLI Home page for more details)

(12) The file containers.json is a JSON document that contains information about the image. The S3Key is the name of the image file you want to upload to the S3Bucket.

(13) 
Result: cisl-toulon:Documents baral$ aws ec2 describe-import-image-tasks
(14) Monitor the progress: cisl-toulon:Documents baral$ aws ec2 describe-import-image-tasks
(15) Once the image is imported, it should be visible in the AMI list. You can identify it with the imageid or the snapshotid. Configure it and launch it.
(16) Import the vmdk file (using the ec2 CLI)
(17) Once your import task is completed, you can use the ec2 run-instances command to create an Amazon EC2 instance from the AMI generated during the import process.
(18) After you launch, the vagrant based VM might ask for a password even if it is associated with a key. For instance, you can use the following command to do ssh to the vagrant based VM:
(19) When prompted for the password, use ‘vagrant’, without the quotes
(20) Configuration and Credential Files The CLI stores credentials specified with aws configure in a local file named credentials in a folder named .aws in your home directory. Home directory location varies but can be referred to using the environment variables %UserProfile% in Windows and $HOME or ~ (tilde) in Unix-like systems. For example, the following commands list the contents of the .aws folder: Linux, OS X, or Unix
$ ls ~/.aws

2 comments:

  1. Hi, When I ran Step 8. I'm getting "An error occurred (InvalidParameter) when calling the ImportImage operation: User does not have access to the S3 object"

    What can be the problem?

    ReplyDelete
  2. Anonymous, I ran into the same issue. In my case, it was a 0 byte file in the s3 bucket. If aws is unable to parse the file, you may also get the same error.

    ReplyDelete