CLI로 CreateSnapshot 사용 - AWS SDK 코드 예제

AWS SDK 예제 GitHub 리포지토리에 더 많은 AWS문서 SDK 예제가 있습니다.

CLI로 CreateSnapshot 사용

다음 코드 예시는 CreateSnapshot의 사용 방법을 보여 줍니다.

CLI
AWS CLI

스냅샷 생성

이 예시에서는 볼륨 ID가 vol-1234567890abcdef0의 볼륨 스냅샷과 스냅샷을 식별할 수 있는 간단한 설명을 생성합니다.

명령:

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

출력:

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

태그를 사용하여 스냅샷 생성

이 예시에서는 스냅샷을 생성하고 purpose=prod 및 costcenter=123이라는 두 개의 태그를 적용합니다.

명령:

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

출력:

{ "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" }
  • API 세부 정보는 AWS CLI 명령 참조CreateSnapshot 섹션을 참조하세요.

PowerShell
Tools for PowerShell V4

예제 1: 이 예제에서는 지정된 볼륨의 스냅샷을 생성합니다.

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

출력:

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
  • API 세부 정보는 AWS Tools for PowerShell Cmdlet 참조(V4)CreateSnapshot을 참조하세요.

Tools for PowerShell V5

예제 1: 이 예제에서는 지정된 볼륨의 스냅샷을 생성합니다.

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

출력:

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
  • API 세부 정보는 AWS Tools for PowerShell Cmdlet 참조(V5)CreateSnapshot을 참조하세요.