Utilizzare CreateSnapshot con una CLI - Esempi di codice per SDK AWS

Sono disponibili altri esempi per SDK AWS nel repository GitHub della documentazione degli esempi per SDK AWS.

Utilizzare CreateSnapshot con una CLI

Gli esempi di codice seguenti mostrano come utilizzare CreateSnapshot.

CLI
AWS CLI

Come creare uno snapshot

Questo comando di esempio crea uno snapshot del volume con l’ID volume vol-1234567890abcdef0 e una breve descrizione per identificare lo snapshot.

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" }

Come creare uno snapshot con tag

Questo comando di esempio crea uno snapshot e applica due tag, ovvero 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 informazioni dettagliate sull’API, consulta CreateSnapshot nella documentazione di riferimento dei comandi della AWS CLI.

PowerShell
Strumenti per PowerShell V4

Esempio 1: questo esempio crea uno snapshot 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 informazioni dettagliate sull’API, consulta CreateSnapshot nella documentazione di riferimento dei cmdlet di AWS Strumenti per PowerShell (V4).

Strumenti per PowerShell V5

Esempio 1: questo esempio crea uno snapshot 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 informazioni dettagliate sull’API, consulta CreateSnapshot nella documentazione di riferimento dei cmdlet di AWS Strumenti per PowerShell (V5).