AWS CLI를 사용한 Cloud Control API 예제 - AWS Command Line Interface

이 문서는 AWS CLI의 버전 1에만 해당합니다. AWS CLI의 버전 2와 관련된 문서는 버전 2 사용 설명서를 참조하세요.

AWS CLI를 사용한 Cloud Control API 예제

다음 코드 예제에서는 Cloud Control API에서 AWS Command Line Interface를 사용하여 작업을 수행하고 일반적인 시나리오를 구현하는 방법을 보여 줍니다.

작업은 대규모 프로그램에서 발췌한 코드이며 컨텍스트에 맞춰 실행해야 합니다. 작업은 개별 서비스 함수를 직접적으로 호출하는 방법을 보여주며 관련 시나리오의 컨텍스트에 맞는 작업을 볼 수 있습니다.

각 예제에는 컨텍스트에서 코드를 설정하고 실행하는 방법에 대한 지침을 찾을 수 있는 전체 소스 코드에 대한 링크가 포함되어 있습니다.

주제

작업

다음 코드 예제에서는 create-resource을 사용하는 방법을 보여 줍니다.

AWS CLI

리소스를 생성하는 방법

다음 create-resource 예제에서는 보존 기간이 168시간이고 샤드 수가 3인 ResourceExampleAWS::Kinesis::Stream 리소스를 생성합니다.

aws cloudcontrol create-resource \ --type-name AWS::Kinesis::Stream \ --desired-state "{\"Name\": \"ResourceExample\",\"RetentionPeriodHours\":168, \"ShardCount\":3}"

출력:

{ "ProgressEvent": { "EventTime": 1632506656.706, "TypeName": "AWS::Kinesis::Stream", "OperationStatus": "IN_PROGRESS", "Operation": "CREATE", "Identifier": "ResourceExample", "RequestToken": "20999d87-e304-4725-ad84-832dcbfd7fc5" } }

자세한 내용은 Cloud Control API 사용 설명서의 리소스 생성을 참조하세요.

  • API 세부 정보는 AWS CLI 명령 참조의 CreateResource를 참조하세요.

다음 코드 예제에서는 delete-resource을 사용하는 방법을 보여 줍니다.

AWS CLI

리소스를 삭제하는 방법

다음 delete-resource 예제에서는 AWS 계정에서 식별자 ResourceExample가 있는 AWS::Kinesis::Stream 리소스를 삭제합니다.

aws cloudcontrol delete-resource \ --type-name AWS::Kinesis::Stream \ --identifier ResourceExample

출력:

{ "ProgressEvent": { "TypeName": "AWS::Kinesis::Stream", "Identifier": "ResourceExample", "RequestToken": "e48f26ff-d0f9-4ab8-a878-120db1edf111", "Operation": "DELETE", "OperationStatus": "IN_PROGRESS", "EventTime": 1632950300.14 } }

자세한 내용은 Cloud Control API 사용 설명서의 리소스 삭제를 참조하세요.

  • API 세부 정보는 AWS CLI 명령 참조의 DeleteResource 섹션을 참조하세요.

다음 코드 예제에서는 get-resource-request-status을 사용하는 방법을 보여 줍니다.

AWS CLI

리소스 요청의 상태 정보를 가져오는 방법

다음 예는 샘플 요청에 지정된 작업에 대한 정보를 반환합니다.

aws cloudcontrol get-resource-request-status \ --request-token "e1a6b86e-46bd-41ac-bfba-001234567890"

출력:

{ "ProgressEvent": { "TypeName": "AWS::Kinesis::Stream", "Identifier": "Demo", "RequestToken": "e1a6b86e-46bd-41ac-bfba-001234567890", "Operation": "CREATE", "OperationStatus": "FAILED", "EventTime": 1632950268.481, "StatusMessage": "Resource of type 'AWS::Kinesis::Stream' with identifier 'Demo' already exists.", "ErrorCode": "AlreadyExists" } }

자세한 내용은 Cloud Control API 사용 설명서의 리소스 작업 요청 관리를 참조하세요.

다음 코드 예제에서는 get-resource을 사용하는 방법을 보여 줍니다.

AWS CLI

리소스의 현재 상태를 가져오는 방법

다음 get-resource 예제는 ResourceExample 라는 AWS::Kinesis::Stream 리소스의 현재 상태를 반환합니다.

aws cloudcontrol get-resource \ --type-name AWS::Kinesis::Stream \ --identifier ResourceExample

출력:

{ "TypeName": "AWS::Kinesis::Stream", "ResourceDescription": { "Identifier": "ResourceExample", "Properties": "{\"Arn\":\"arn:aws:kinesis:us-west-2:099908667365:stream/ResourceExample\",\"RetentionPeriodHours\":168,\"Name\":\"ResourceExample\",\"ShardCount\":3}" } }

자세한 내용은 Cloud Control API 사용 설명서의 리소스의 현재 상태 읽기를 참조하세요.

  • API 세부 정보는 AWS CLI 명령 참조의 GetResource 섹션을 참조하세요.

다음 코드 예제에서는 list-resource-requests을 사용하는 방법을 보여 줍니다.

AWS CLI

활성 리소스 작업 요청을 나열하는 방법

다음 list-resource-requests 예제에서는 AWS 계정에서 실패한 CREATE 및 UPDATE 작업에 대한 리소스 요청을 나열합니다.

aws cloudcontrol list-resource-requests \ --resource-request-status-filter Operations=CREATE,OperationStatuses=FAILED

출력:

{ "ResourceRequestStatusSummaries": [ { "TypeName": "AWS::Kinesis::Stream", "Identifier": "Demo", "RequestToken": "e1a6b86e-46bd-41ac-bfba-633abcdfdbd7", "Operation": "CREATE", "OperationStatus": "FAILED", "EventTime": 1632950268.481, "StatusMessage": "Resource of type 'AWS::Kinesis::Stream' with identifier 'Demo' already exists.", "ErrorCode": "AlreadyExists" } ] }

자세한 내용은 Cloud Control API 사용 설명서의 리소스 작업 요청 관리를 참조하세요.

다음 코드 예제에서는 list-resources을 사용하는 방법을 보여 줍니다.

AWS CLI

지정된 유형의 리소스를 나열하는 방법

다음 list-resources 예제에서는 AWS 계정에 프로비저닝된 AWS::Kinesis::Stream 리소스를 나열합니다.

aws cloudcontrol list-resources \ --type-name AWS::Kinesis::Stream

출력:

{ "TypeName": "AWS::Kinesis::Stream", "ResourceDescriptions": [ { "Identifier": "MyKinesisStream", "Properties": "{\"Name\":\"MyKinesisStream\"}" }, { "Identifier": "AnotherStream", "Properties": "{\"Name\":\"AnotherStream\"}" } ] }

자세한 내용은 Cloud Control API 사용 설명서의 리소스 검색을 참조하세요.

  • API 세부 정보는 AWS CLI 명령 참조의 ListResources 섹션을 참조하세요.

다음 코드 예제에서는 update-resource을 사용하는 방법을 보여 줍니다.

AWS CLI

기존 리소스의 속성을 업데이트하는 방법

다음 예제에서는 이라는 이름의 update-resourceAWS: :Logs: :LogGroup 리소스의 보존 정책을 90일로 업데이트합니다.

aws cloudcontrol update-resource \ --type-name AWS::Logs::LogGroup \ --identifier ExampleLogGroup \ --patch-document "[{\"op\":\"replace\",\"path\":\"/RetentionInDays\",\"value\":90}]"

출력:

{ "ProgressEvent": { "EventTime": "2021-08-09T18:17:15.219Z", "TypeName": "AWS::Logs::LogGroup", "OperationStatus": "IN_PROGRESS", "Operation": "UPDATE", "Identifier": "ExampleLogGroup", "RequestToken": "5f40c577-3534-4b20-9599-0b0123456789" } }

자세한 내용은 Cloud Control API 사용 설명서의 리소스 업데이트를 참조하세요.

  • API 세부 정보는 AWS CLI 명령 참조의 UpdateResource 섹션을 참조하세요.