Utilizzare CreateSnapshot con una CLI - AWS Esempi di codice SDK

Sono disponibili altri esempi AWS SDK nel repository AWS Doc SDK Examples. GitHub

Le traduzioni sono generate tramite traduzione automatica. In caso di conflitto tra il contenuto di una traduzione e la versione originale in Inglese, quest'ultima prevarrà.

Utilizzare CreateSnapshot con una CLI

Gli esempi di codice seguenti mostrano come utilizzare CreateSnapshot.

CLI
AWS CLI

Per creare un'istantanea

Questo comando di esempio crea un'istantanea del volume con un ID di volume vol-1234567890abcdef0 e una breve descrizione per identificare l'istantanea.

Comando:

aws ec2 create-snapshot --volume-id vol-1234567890abcdef0 --description "This is my root volume snapshot"

Output:

{ "Description": "This is my root volume snapshot", "Tags": [], "Encrypted": false, "VolumeId": "vol-1234567890abcdef0", "State": "pending", "VolumeSize": 8, "StartTime": "2018-02-28T21:06:01.000Z", "Progress": "", "OwnerId": "012345678910", "SnapshotId": "snap-066877671789bd71b" }

Per creare un'istantanea con tag

Questo comando di esempio crea un'istantanea e applica due tag: purpose=prod e costcenter=123.

Comando:

aws ec2 create-snapshot --volume-id vol-1234567890abcdef0 --description 'Prod backup' --tag-specifications 'ResourceType=snapshot,Tags=[{Key=purpose,Value=prod},{Key=costcenter,Value=123}]'

Output:

{ "Description": "Prod backup", "Tags": [ { "Value": "prod", "Key": "purpose" }, { "Value": "123", "Key": "costcenter" } ], "Encrypted": false, "VolumeId": "vol-1234567890abcdef0", "State": "pending", "VolumeSize": 8, "StartTime": "2018-02-28T21:06:06.000Z", "Progress": "", "OwnerId": "012345678910", "SnapshotId": "snap-09ed24a70bc19bbe4" }
  • Per i dettagli CreateSnapshotsull'AWS CLI API, vedere in Command Reference.

PowerShell
Strumenti per PowerShell

Esempio 1: Questo esempio crea un'istantanea del volume specificato.

New-EC2Snapshot -VolumeId vol-12345678 -Description "This is a test"

Output:

DataEncryptionKeyId : Description : This is a test Encrypted : False KmsKeyId : OwnerAlias : OwnerId : 123456789012 Progress : SnapshotId : snap-12345678 StartTime : 12/22/2015 1:28:42 AM State : pending StateMessage : Tags : {} VolumeId : vol-12345678 VolumeSize : 20
  • Per i dettagli sull'API, vedere CreateSnapshotin AWS Strumenti per PowerShell Cmdlet Reference.