Ở bước này, bạn sẽ tạo một role tên là vmimport và import máy ảo đã được tải lên S3 Bucket ở bước trước thành AMI. Toàn bộ quá trình sẽ được thao tác với AWS CLI.
Trước khi thực hiện việc Import máy ảo vào AWS. Bạn cần kiểm tra role cần thiết cho việc thực thi này.
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": { "Service": "vmie.amazonaws.com" },
"Action": "sts:AssumeRole",
"Condition": {
"StringEquals":{
"sts:Externalid": "vmimport"
}
}
}
]
}
--assume-role-policy-document
# thay thế "E:\trust-policy.json" bằng đường dẫn tới tập tin trust-policy.json trên môi trường của bạn
aws iam create-role --role-name vmimport --assume-role-policy-document "file://E:\trust-policy.json"
disk-image-file-bucket là tên của S3 bucket dùng để lưu các file đã export từ onpremise (trong ví dụ này là import-bucket-2023). export-bucket là tên của S3 bucket dùng để export ec2 instance sẽ dùng cho phần Export VM từ AWS ở sau.
{
"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"
Chúng ta sẽ sử dụng AWS CLI để khởi chạy tiến trình Import máy ảo thành AMI.
Đối với máy ảo ở On-premise, hãy chắc chắn rằng bạn không sử dụng UEFI boot cho máy ảo. UEFI boot không được hỗ trợ trên AWS. Việc convert sẽ không thành công và xuất hiện lỗi ClientError: EFI partition detected. UEFI booting is not supported in EC2.
Đối với máy ảo Linux, hãy kiểm tra phiên bản kernel mới nhất đang được AWS support. Các kernel mới hơn hỗ trợ của AWS sẽ không thực hiện được. Yêu cầu về Hệ điều hành bạn có thể tham khảo tại Yêu cầu Hệ điều hành
aws ec2 import-image --description "VM Image" --disk-containers Format=vhdx,UserBucket="{S3Bucket=import-bucket-2021,S3Key=Ubuntu.vhdx}"
Nếu khi chạy lệnh bạn gặp lỗi An error occurred (InvalidParameter) when calling the ImportImage operation: The service role vmimport provided does not exist or does not have sufficient permissions, hãy kiểm tra lại bước tạo role vmimport và chắc chắn rằng role đã được tạo và thiết lập đủ quyền.