In this step, you will create a role named vmimport and import the virtual machine that was uploaded to the S3 Bucket in the previous step into an AMI. The entire process will be handled with the AWS CLI.
Before performing the Import of virtual machines into AWS. You need to check the role required for this implementation.
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": { "Service": "vmie.amazonaws.com" },
"Action": "sts:AssumeRole",
"Condition": {
"StringEquals":{
"sts:Externalid": "vmimport"
}
}
}
]
}
--assume-role-policy-document
# replace "E:\trust-policy.json" with the path to the trust-policy.json file on your environment
aws iam create-role --role-name vmimport --assume-role-policy-document "file://E:\trust-policy.json"
{
"Version":"2012-10-17",
"Statement":[
{
"Effect": "Allow",
"Action": [
"s3:GetBucketLocation",
"s3:GetObject",
"s3:ListBucket"
],
"Resource": [
"arn:aws:s3:::disk-image-file-bucket",
"arn:aws:s3:::disk-image-file-bucket/*"
]
},
{
"Effect": "Allow",
"Action": [
"s3:GetBucketLocation",
"s3:GetObject",
"s3:ListBucket",
"s3:PutObject",
"s3:GetBucketAcl"
],
"Resource": [
"arn:aws:s3:::export-bucket",
"arn:aws:s3:::export-bucket/*"
]
},
{
"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://E:\role-policy.json"
We will use the AWS CLI to launch the Import virtual machine to AMI process.
For On-premise virtual machines, make sure you are not using UEFI boot for the virtual machine. UEFI boot is not supported on AWS. The conversion will fail and an error ClientError: EFI partition detected will appear. UEFI booting is not supported in EC2.
For Linux VMs, check for the latest kernel version supported by AWS. Newer kernels that support AWS won’t do it. Operating System Requirements can be found at Operating System Requirements
aws ec2 import-image --description "VM Image" --disk-containers Format=vhdx,UserBucket="{S3Bucket=import-bucket-2021,S3Key=Ubuntu.vhdx}"
If when running the command you get the error An error occurred (InvalidParameter) when calling the ImportImage operation: The service role vmimport provided does not exist or does not have sufficient permissions, check the step of creating the vmimport role and make sure the role has been created and set up enough permissions.