There are more AWS SDK examples available in the AWS Doc SDK Examples
Use ImportSnapshot
with a CLI
The following code examples show how to use ImportSnapshot
.
- CLI
-
- AWS CLI
-
To import a snapshot
The following
import-snapshot
example imports the specified disk as a snapshot.aws ec2 import-snapshot \ --description
"My server VMDK"
\ --disk-container Format=VMDK,UserBucket={'S3Bucket=my-import-bucket,S3Key=vms/my-server-vm.vmdk'}Output:
{ "Description": "My server VMDK", "ImportTaskId": "import-snap-1234567890abcdef0", "SnapshotTaskDetail": { "Description": "My server VMDK", "DiskImageSize": "0.0", "Format": "VMDK", "Progress": "3", "Status": "active", "StatusMessage": "pending" "UserBucket": { "S3Bucket": "my-import-bucket", "S3Key": "vms/my-server-vm.vmdk" } } }
-
For API details, see ImportSnapshot
in AWS CLI Command Reference.
-
- PowerShell
-
- Tools for PowerShell
-
Example 1: This example imports a VM disk image of format 'VMDK' to an Amazon EBS snapshot. The example requires a VM Import Service Role with the default name 'vmimport', with a policy allowing Amazon EC2 access to the specified bucket, as explained in the
VM Import Prequisites
topic in http://docs.aws.amazon.com/AWSEC2/latest/WindowsGuide/VMImportPrerequisites.html. To use a custom role, specify the role name using the-RoleName
parameter.$parms = @{ "ClientToken"="idempotencyToken" "Description"="Disk Image Import" "DiskContainer_Description" = "Data disk" "DiskContainer_Format" = "VMDK" "DiskContainer_S3Bucket" = "amzn-s3-demo-bucket" "DiskContainer_S3Key" = "datadiskimage.vmdk" } Import-EC2Snapshot @parms
Output:
Description ImportTaskId SnapshotTaskDetail ----------------- -------------------- ------------------ Disk Image Import import-snap-abcdefgh Amazon.EC2.Model.SnapshotTaskDetail
-
For API details, see ImportSnapshot in AWS Tools for PowerShell Cmdlet Reference.
-