- This documentation was created using information contained from this video
- A working AWS CLI: documentation
- Amazon S3 Bucket configured: documentation
- A custom VM in one of the following formats: OVA, VMDK, and VHD/VHDX
First we must create an IAM Role. This is done by creating a file named trust-policy.json.
- Copy the content below into the trust-policy.json file
{
"Version" : "2012-10-17",
"Statement" : [
{
"Effect" : "Allow",
"Principal" : { "Service" : "vmie.amazonaws.com" },
"Action" : "sts:AssumeRole",
"Condition" : {
"StringEquals" : {
"sts:Externalid" : "vmimport"
}
}
}
]
}
- Execute the below command to create the IAM Role. Make sure the terminal is at the same directory as the trust-policy.json file
aws iam create-role --role-name vmimport --assume-role-policy-document "file://trust-policy.json"
Now we must create a role policy that allows access to Amazon S3 and Amazon EC2. This is done by creating a file named role-policy.json.
- Copy the content below into the role-policy.json file
- Replace [bucket-name] with the name of your S3 Bucket
{
"Version" : "2012-10-17",
"Statement" : [
{
"Effect" : "Allow",
"Action" : [
"s3:GetBucketLocation",
"s3:GetObject",
"s3:ListBucket"
],
"Resource" : [
"arn:aws:s3:::[bucket-name]",
"arn:aws:s3:::[bucket-name]"
]
},
{
"Effect" : "Allow",
"Action" : [
"s3:GetBucketLocation",
"s3:GetObject",
"s3:ListBucket",
"s3:PutObject",
"s3:GetBucketAcl"
],
"Resource" : [
"arn:aws:s3:::[bucket-name]",
"arn:aws:s3:::[bucket-name]/*"
]
},
{
"Effect" : "Allow",
"Action" : [
"ec2:ModifySnapshotAttribute",
"ec2:CopySnapshot",
"ec2:RegisterImage",
"ec2:Describe*"
],
"Resource" : "*"
}
]
}
- Execute the below command to create the Role Policy. Make sure the terminal is at the same directory as the role-policy.json file
aws iam put-role-policy --role-name vmimport --policy-name vmimport --policy-document "file://role-policy.json"
- Place the properly formatted VM Image in the current working directory that contains the trust-policy.json and role-policy.json files.
- Execute the below command to copy the VM Image to the Amazon S3 Bucket.
- Replace [vm-image] with the filename and extension of VM Image (EXP: image.vmdk)
- Replace [bucket-name] with the name of your S3 Bucket
aws s3 cp [vm-image] s3://[bucket-name]
To create the actual EC2 AMI create a file named containers.json. This file will contain the information of the VM Image.
- Copy the content below into the containers.json file
- Replace [description-of-vm] with a description of what the VM is for
- Replace [file-extension-of-vm] with the extension of the VM (EXP: vmdk)
- Replace [bucket-name] with the name of the bucket
- Replace [vm-image-name] with the name and extension of the VM Image (EXP: image.vmdk)
[
{
"Description" : "[description-of-vm]",
"Format" : "[file-extension-of-vm]",
"UserBucket" : {
"S3Bucket" : "[bucket-name]",
"S3Key" : "[vm-image-name]"
}
}
]
- Execute the below command to create the EC2 AMI
- Replace [description-of-vm] with the same description used above
aws ec2 import-image --description "[description-of-vm]" --disk-containers "file://containers.json"
Once the above command is sent a printout will contain an ImportTaskId. Copy the numbers of this Id.
- Execute the below command to check the status
- Replcace [import-task-id] with the id found from the printout
aws ec2 describe-import-image-tasks --import-task-ids import-ami-[import-task-id]
- Status pending means that it is still being created
- Status completed means that it is finished and can now be seen in the list of Amazon EC2 AMIs