我想要将亚马逊机器映像(AMI)的副本导出为虚拟机(VM),以在现场虚拟化环境中部署。
简短描述
使用 AWS 命令行界面 (AWS CLI) 和 VM Import/Export 开始映像导出任务。此任务会将您的 AMI 副本导出为写入 Amazon Simple Storage Service (Amazon S3) 存储桶的虚拟机文件。使用导出的虚拟机在您的现场虚拟化环境中部署新的标准化实例。大多数 AMI 可以导出到 Citrix Xen、Microsoft Hyper-V 或 VMware vSphere。
解决方法
**注意:**如果您在运行 AWS 命令行界面 (AWS CLI) 命令时收到错误,请参阅 AWS CLI 错误故障排除。此外,请确保您使用的是最新版本的 AWS CLI。
先决条件:
- 查看虚拟机导出限制,以验证 VM Import/Export 是否支持您的 AMI。
- 如果您以 AWS Identity and Access Management (IAM) 用户身份登录,请确保您具有所需的 IAM 用户权限。
将 AMI 的副本导出为映像
**注意:**您无法导出基于 AWS 提供的 Windows AMI 或 Windows Marketplace AMI 创建的实例。您只能通过 VM Import/Export、AWS Application Migration Service (MGN) 或 AWS 弹性灾难恢复 (AWS DRS) 导出最初以自带许可证 (BYOL) 形式导入的 Windows 实例。
要运行映像导出任务,请完成以下步骤:
-
从要导出的 Amazon Elastic Compute Cloud (Amazon EC2) 实例创建 Amazon Elastic Block Store (Amazon EBS) backed AMI。
-
在客户端计算机上安装 AWS CLI。然后,使用 IAM 用户的 AWS 凭证配置 AWS CLI。
-
在与要导出的 AMI 相同的 AWS 区域中创建新的 Amazon S3 存储桶。
-
在要用于 VM Import/Export 的区域中激活 AWS Security Token Service (AWS STS)。然后,创建所需的服务角色。
-
在安装了 AWS CLI 的客户端计算机上,运行 export-image 命令启动导出映像任务:
aws ec2 export-image --image-id `ami-1234567890abcdef0` --disk-image-format example-disk-image-format --s3-export-location S3Bucket=example-export-bucket,S3Prefix=exports/
**注意:**将 ami-1234567890abcdef0 替换为您的 AMI ID。将 example-disk-image-format 替换为所需的格式。将 example-export-bucket 替换为您的 Amazon S3 存储桶的名称。
输出示例:
{
"DiskImageFormat": "vmdk",
"ExportImageTaskId": "export-ami-1234567890abcdef0",
"ImageId": "example-ami-id",
"RoleName": "vmimport",
"Progress": "0",
"S3ExportLocation": {
"S3Bucket": "example-export-bucket",
"S3Prefix": "exports/"
},
"Status": "active",
"StatusMessage": "validating"
}
在前面的示例中,Amazon S3 密钥 prefixexport-ami-id.format 将导出的文件写入您指定的 Amazon S3 存储桶。您可以为导出的文件添加前缀。
-
要检查导出映像任务的状态,请运行 describe-export-image-tasks 命令:
aws ec2 describe-export-image-tasks --export-image-task-ids export-example-ami-id
**注意:**将 export-example-ami-id 替换为您的导出任务 ID。
输出示例:
{ "ExportImageTasks": [
{
"ExportImageTaskId": "export-ami-1234567890abcdef0",
"Progress": "21",
"S3ExportLocation": {
"S3Bucket": "my-export-bucket",
"S3Prefix": "exports/"
},
"Status": "active",
"StatusMessage": "updating"
}
]
}
-
确认导出映像任务的状态变为 completed(已完成)。如果状态为 completed(已完成),则您的导出文件已作为 Amazon S3 存储桶中的对象准备就绪。
completed(已完成)状态输出示例:
{ "ExportImageTasks": [
{
"ExportImageTaskId": "example-export-ami-id",
"S3ExportLocation": {
"S3Bucket": "example-export-bucket",
"S3Prefix": "exports/"
},
"Status": "completed"
}
]
}
-
使用 Amazon S3 控制台访问 Amazon S3 存储桶。然后,下载对象。
相关信息
使用 VM Import/Export 从亚马逊机器映像 (AMI) 直接导出虚拟机
在 AWS 账户中创建 IAM 用户
AWS 安全凭证
Amazon EC2 中的亚马逊机器映像
VM Import/Export 故障排除