One of the coolest features I like about AWS is it not only gives you the powerful images through AMI but also allows you to import your VM images running in your data center as well. In this, I would like to show you how simple it is to import the VM image into the AWS
The prerequisites for VM import are
- Configure the AWS CLI on the VM.A simple How-To guide can be found here in this link https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html
- S3 Bucket in the region you want to import the VM
- IAM Role named VMimport
For S3 Bucket I am assuming name “my-vm-imports”
Creating IAM Role
You cannot create using the AWS management console. You have to follow the aws- only
- create a trust policy trust-policy.json
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": { "Service": "vmie.amazonaws.com" },
"Action": "sts:AssumeRole",
"Condition": {
"StringEquals":{
"sts:Externalid": "vmimport"
}
}
}
]
}
2. Using aws command line create a role vmimport
aws iam create-role --role-name vmimport --assume-role-policy-document file://trust-policy.json
3. Create a file named role-policy.json with the following policy
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"s3:ListBucket",
"s3:GetBucketLocation",
"s3:FullAccess"
],
"Resource": [
"arn:aws:s3:::my-vm-imports"
]
},
{
"Effect": "Allow",
"Action": [
"s3:GetObject"
],
"Resource": [
"arn:aws:s3:::my-vm-imports/*"
]
},
{
"Effect": "Allow",
"Action":[
"ec2:ModifySnapshotAttribute",
"ec2:CopySnapshot",
"ec2:RegisterImage",
"ec2:Describe*",
"ec2:FullAccess"
],
"Resource": "*"
}
]
}
4. Use the following command “put-role-policy” to the role we created before.
aws iam put-role-policy --role-name vmimport --policy-name vmimport --policy-document file://role-policy.json
Next steps :
- Upload the VM image to S3
aws s3 cp file_path s3://my-vm-imports
2. Create a container file which contains the s3 bucket name, format, description and key name in the s3 bucket. Save this file as JSON
[
{
"Description": “My VM",
"Format": "ova",
"UserBucket": {
"S3Bucket": “my-vm-imports",
"S3Key": "my-vm-imports/myVm.ova"
}
}]
Note: Only OVA,VMDK image formats are supported in AWS
4. Finally, import the image from S3 with import-image command. After that, your image(AMI) will be ready for use
aws ec2 import-image —description “Linux or Window VM” —-disk-containers file://container.json
Thanks for Reading.
Best Regards
CloudTern