Exporting from an AMI
For exporting go to permissions of S3 bucket
- Turn of block all public access
- go to ACLs and click edit,
- Add a grantee you can get the grantee information for the region here (opens in a new tab)
- We will go with All other regions as us-east-1 isnt selected
All other Regions:
c4d8eabf8db69dbe46bfe0e517100c554f01200b104d59cd408e777ba442a322
-
For each Grantee, provide the following permissions:
-
READ_ACP (In the Amazon S3 console, Bucket ACL should have the Read permission)
-
WRITE (In the Amazon S3 console, Objects should have the Write permission)
-
To export an Amazon EC2 instance using the AWS CLI, follow the steps starting from step 6. Note that your instance might reboot during this process, so plan for acceptable downtime.
5. Exporting Your EC2 Instance
Before you begin, ensure the S3 bucket you plan to export to has the correct permissions, and you have the necessary IAM roles set up.
Step 1: Create a JSON File for Export Details
Create a JSON file (e.g., file.json
) with the following details. This file specifies the container format, disk image format, and the S3 bucket and prefix where the export will be saved.
{
"ContainerFormat": "ova",
"DiskImageFormat": "VMDK",
"S3Bucket": "amzn-s3-demo-export-bucket",
"S3Prefix": "vms/"
}
- ContainerFormat: The container format you want for your export, such as
ova
. - DiskImageFormat: The format for the disk image, such as
VMDK
. - S3Bucket: The name of your S3 bucket.
- S3Prefix: The directory (prefix) where the exported image will be stored.
Step 2: Run the Export Command
Use the AWS CLI create-instance-export-task
command to export the instance. Replace instance-id
with your actual EC2 instance ID.
aws ec2 create-instance-export-task --instance-id i-xxxxxxxx --target-environment vmware --export-to-s3-task file://C:\file.json
- instance-id: Replace
i-xxxxxxxx
with your EC2 instance's ID. - file://C:\file.json: Path to the JSON file you created.
Step 3: Monitor Export Progress
The command returns an output like this, indicating the export task has started. The task will move from active
to completed
when finished.
{
"ExportTask": {
"ExportTaskId": "export-i-021345abcdef6789",
"ExportToS3Task": {
"ContainerFormat": "ova",
"DiskImageFormat": "vmdk",
"S3Bucket": "amzn-s3-demo-export-bucket",
"S3Key": "vms/export-i-021345abcdef6789.ova"
},
"InstanceExportDetails": {
"InstanceId": "i-021345abcdef6789",
"TargetEnvironment": "vmware"
},
"State": "active"
}
}
- ExportTaskId: A unique identifier for the export task.
- S3Bucket: The S3 bucket where the exported file is stored.
- S3Key: The path to the exported file in the S3 bucket.
- State: The current state of the export task, which will eventually change from
active
tocompleted
.
Important Notes
- Ensure your instance meets export requirements (like not using an instance store-backed AMI).
- Check for required IAM permissions for exporting instances to S3.
- The export process may take time depending on the instance size.