In this step, you will create an IAM role named vmimport and import the virtual machine that was uploaded to the Amazon S3 bucket in the previous step into an Amazon Machine Image (AMI). The entire process will be performed using the AWS Command Line Interface (CLI).
Before importing the virtual machine into AWS, you need to create the necessary IAM role.
trust-policy.json to allow the VM Import/Export service to assume the vmimport role:{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": { "Service": "vmie.amazonaws.com" },
"Action": "sts:AssumeRole",
"Condition": {
"StringEquals":{
"sts:Externalid": "vmimport"
}
}
}
]
}
aws iam create-role --role-name vmimport --assume-role-policy-document "file://trust-policy.json"

Check the created role in the IAM console.

View the Trust relationships of the role.

To grant permissions to the vmimport role, create a text file named role-policy.json. In the JSON content, at the Resource lines (ARN), check and update the exact name of your bucket. Since the S3 bucket name is globally unique, if you changed the bucket name during initialization, make sure the ARN in this file matches that name (example: arn:aws:s3:::your-bucket-name).
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"s3:GetBucketLocation",
"s3:GetObject",
"s3:ListBucket"
],
"Resource": [
"arn:aws:s3:::import-bucket-2026-1a",
"arn:aws:s3:::import-bucket-2026-1a/*"
]
},
{
"Effect": "Allow",
"Action": [
"s3:GetBucketLocation",
"s3:GetObject",
"s3:ListBucket",
"s3:PutObject",
"s3:GetBucketAcl"
],
"Resource": [
"arn:aws:s3:::export-bucket-2026-1a",
"arn:aws:s3:::export-bucket-2026-1a/*"
]
},
{
"Effect": "Allow",
"Action": [
"ec2:ModifySnapshotAttribute",
"ec2:CopySnapshot",
"ec2:RegisterImage",
"ec2:Describe*"
],
"Resource": "*"
}
]
}

aws iam put-role-policy --role-name vmimport --policy-name vmimport --policy-document "file://role-policy.json"


Use the AWS CLI to import the virtual machine to AMI:
Ensure that the on-premise virtual machine does not use UEFI boot as Amazon EC2 does not support it.
For Linux virtual machines, check the kernel version supported by AWS. Refer to OS requirements.
aws ec2 import-image --description "VM Image" --disk-containers Format=vmdk,UserBucket="{S3Bucket=import-bucket-2026-1a,S3Key=Ubuntu-disk1.vmdk}"


aws ec2 describe-import-image-tasks --import-task-ids import-ami-xxxxxxxx

