Verwendung von CreateSnapshot mit einer CLI - AWS-SDK-Codebeispiele

Weitere AWS-SDK-Beispiele sind im GitHub-Repository Beispiele für AWS Doc SDKs verfügbar.

Verwendung von CreateSnapshot mit einer CLI

Die folgenden Code-Beispiele zeigen, wie CreateSnapshot verwendet wird.

CLI
AWS CLI

So erstellen Sie einen Snapshot

Mit diesem Beispielbefehl wird ein Snapshot des Volumes mit der Volume-ID vol-1234567890abcdef0 und einer kurzen Beschreibung zur Identifizierung des Snapshots erstellt.

Befehl:

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

Ausgabe:

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

So erstellen Sie einen Snapshot mit Tags

Dieser Beispielbefehl erstellt einen Snapshot und wendet zwei Tags an: purpose=prod und costcenter=123.

Befehl:

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

Ausgabe:

{ "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" }
  • Weitere API-Informationen finden Sie unter CreateSnapshot in der AWS CLI-Befehlsreferenz.

PowerShell
Tools für PowerShell V4

Beispiel 1: In diesem Beispiel wird ein Snapshot des angegebenen Volumes erstellt.

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

Ausgabe:

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
  • Weitere API-Informationen finden Sie unter CreateSnapshot in der AWS -Tools für PowerShell-Cmdlet-Referenz (V4).

Tools für PowerShell V5

Beispiel 1: In diesem Beispiel wird ein Snapshot des angegebenen Volumes erstellt.

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

Ausgabe:

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
  • Weitere API-Informationen finden Sie unter CreateSnapshot in der AWS -Tools für PowerShell-Cmdlet-Referenz (V5).