AWS CodeStar를 사용한 Notifications 예제AWS CLI - AWS Command Line Interface

AWS CodeStar를 사용한 Notifications 예제AWS CLI

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

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

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

주제

작업

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

AWS CLI

알림 규칙을 생성하는 방법

다음 create-notification-rule 예제에서는 rule.json이라는 JSON 파일을 사용하여 지정된 AWS 계정에 이름이 지정된 리포지토리 MyDemoRepo에 대한 MyNotificationRule이라는 알림 규칙을 생성합니다. 브랜치와 태그가 생성되면 FULL 세부 유형이 포함된 알림이 지정된 대상 Amazon SNS 주제로 전송됩니다.

aws codestar-notifications create-notification-rule \ --cli-input-json file://rule.json

rule.json의 콘텐츠:

{ "Name": "MyNotificationRule", "EventTypeIds": [ "codecommit-repository-branches-and-tags-created" ], "Resource": "arn:aws:codecommit:us-east-1:123456789012:MyDemoRepo", "Targets": [ { "TargetType": "SNS", "TargetAddress": "arn:aws:sns:us-east-1:123456789012:MyNotificationTopic" } ], "Status": "ENABLED", "DetailType": "FULL" }

출력:

{ "Arn": "arn:aws:codestar-notifications:us-east-1:123456789012:notificationrule/dc82df7a-EXAMPLE" }

자세한 내용은 AWS 개발자 도구 콘솔 사용 설명서의 Create a Notification rule을 참조하세요.

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

AWS CLI

알림 규칙을 삭제하는 방법

다음 delete-notification-rule 예제에서는 지정된 알림 규칙을 삭제합니다.

aws codestar-notifications delete-notification-rule \ --arn arn:aws:codestar-notifications:us-east-1:123456789012:notificationrule/dc82df7a-EXAMPLE

출력:

{ "Arn": "arn:aws:codestar-notifications:us-east-1:123456789012:notificationrule/dc82df7a-EXAMPLE" }

자세한 내용은 AWS 개발자 도구 콘솔 사용 설명서Delete a Notification Rule를 참조하세요.

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

AWS CLI

알림 규칙 대상을 삭제하는 방법

다음 delete-target 예제에서는 지정된 대상을 대상으로 사용하도록 구성된 모든 알림 규칙에서 지정된 대상을 제거한 다음 대상을 삭제합니다.

aws codestar-notifications delete-target \ --target-address arn:aws:sns:us-east-1:123456789012:MyNotificationTopic \ --force-unsubscribe-all

이 명령은 출력을 생성하지 않습니다.

자세한 내용은 AWS 개발자 도구 콘솔 사용 설명서Delete a Notification Rule Target를 참조하세요.

  • API 세부 정보는 AWS CLI 명령 참조DeleteTarget을 참조하세요.

다음 코드 예시에서는 describe-notification-rule을 사용하는 방법을 보여 줍니다.

AWS CLI

알림 규칙의 세부 정보를 검색하는 방법

다음 describe-notification-rule 예제에서는 지정된 알림 규칙의 세부 정보를 검색합니다.

aws codestar-notifications describe-notification-rule \ --arn arn:aws:codestar-notifications:us-west-2:123456789012:notificationrule/dc82df7a-EXAMPLE

출력:

{ "LastModifiedTimestamp": 1569199844.857, "EventTypes": [ { "ServiceName": "CodeCommit", "EventTypeName": "Branches and tags: Created", "ResourceType": "Repository", "EventTypeId": "codecommit-repository-branches-and-tags-created" } ], "Status": "ENABLED", "DetailType": "FULL", "Resource": "arn:aws:codecommit:us-west-2:123456789012:MyDemoRepo", "Arn": "arn:aws:codestar-notifications:us-west-w:123456789012:notificationrule/dc82df7a-EXAMPLE", "Targets": [ { "TargetStatus": "ACTIVE", "TargetAddress": "arn:aws:sns:us-west-2:123456789012:MyNotificationTopic", "TargetType": "SNS" } ], "Name": "MyNotificationRule", "CreatedTimestamp": 1569199844.857, "CreatedBy": "arn:aws:iam::123456789012:user/Mary_Major" }

자세한 내용은 AWS 개발자 도구 콘솔 사용 설명서View Notification Rules를 참조하세요.

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

AWS CLI

알림 규칙의 이벤트 유형을 나열하는 방법

다음 list-event-types 예제에서는 CodeDeploy 애플리케이션에 사용 가능한 모든 알림 이벤트 유형의 필터링된 목록을 검색합니다. 대신 필터를 사용하지 않으면 명령은 모든 리소스 유형에 대해 모든 알림 이벤트 유형을 반환합니다.

aws codestar-notifications list-event-types \ --filters Name=SERVICE_NAME,Value=CodeDeploy

출력:

{ "EventTypes": [ { "EventTypeId": "codedeploy-application-deployment-succeeded", "ServiceName": "CodeDeploy", "EventTypeName": "Deployment: Succeeded", "ResourceType": "Application" }, { "EventTypeId": "codedeploy-application-deployment-failed", "ServiceName": "CodeDeploy", "EventTypeName": "Deployment: Failed", "ResourceType": "Application" }, { "EventTypeId": "codedeploy-application-deployment-started", "ServiceName": "CodeDeploy", "EventTypeName": "Deployment: Started", "ResourceType": "Application" } ] }

자세한 내용은 AWS 개발자 도구 콘솔 사용 설명서Create a Notification Rule을 참조하세요.

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

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

AWS CLI

알림 규칙 목록을 검색하는 방법

다음 list-notification-rules 예제에서는 지정된 AWS 리전의 모든 알림 규칙 목록을 검색합니다.

aws codestar-notifications list-notification-rules --region us-east-1

출력:

{ "NotificationRules": [ { "Id": "dc82df7a-EXAMPLE", "Arn": "arn:aws:codestar-notifications:us-east-1:123456789012:notificationrule/dc82df7a-EXAMPLE" }, { "Id": "8d1f0983-EXAMPLE", "Arn": "arn:aws:codestar-notifications:us-east-1:123456789012:notificationrule/8d1f0983-EXAMPLE" } ] }

자세한 내용은 AWS 개발자 도구 콘솔 사용 설명서View Notification Rules를 참조하세요.

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

AWS CLI

알림 규칙에 연결된 태그 목록을 가져오는 방법

다음 list-tags-for-resource 예제에서는 지정된 알림 규칙에 연결된 모든 태그 목록을 검색합니다. 이 예제에서는 알림 규칙에 현재 연결된 태그가 없습니다.

aws codestar-notifications list-tags-for-resource \ --arn arn:aws:codestar-notifications:us-east-1:123456789012:notificationrule/fe1efd35-EXAMPLE

출력:

{ "Tags": {} }

자세한 내용은 AWS 개발자 도구 콘솔 사용 설명서Create a Notification Rule을 참조하세요.

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

AWS CLI

알림 규칙 대상 목록을 검색하는 방법

다음 list-targets 예제에서는 지정된 AWS 리전의 모든 알림 규칙 대상 목록을 검색합니다.

aws codestar-notifications list-targets \ --region us-east-1

출력:

{ "Targets": [ { "TargetAddress": "arn:aws:sns:us-east-1:123456789012:MySNSTopicForNotificationRules", "TargetType": "SNS", "TargetStatus": "ACTIVE" }, { "TargetAddress": "arn:aws:sns:us-east-1:123456789012:MySNSTopicForNotificationsAboutMyDemoRepo", "TargetType": "SNS", "TargetStatus": "ACTIVE" } ] }

자세한 내용은 AWS 개발자 도구 콘솔 사용 설명서View Notification Rule Targets를 참조하세요.

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

다음 코드 예시에서는 subscribe을 사용하는 방법을 보여 줍니다.

AWS CLI

알림 규칙에 대상을 추가하는 방법

다음 subscribe 예제에서는 지정된 알림 규칙의 대상으로 Amazon SNS 주제를 추가합니다.

aws codestar-notifications subscribe \ --arn arn:aws:codestar-notifications:us-east-1:123456789012:notificationrule/dc82df7a-EXAMPLE \ --target TargetType=SNS,TargetAddress=arn:aws:sns:us-east-1:123456789012:MyNotificationTopic

출력:

{ "Arn": "arn:aws:codestar-notifications:us-east-1:123456789012:notificationrule/dc82df7a-EXAMPLE" }

자세한 내용은 AWS 개발자 도구 콘솔 사용 설명서의 Add or Remove an Amazon SNS Topic as a Target for a Notification Rule을 참조하세요.

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

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

AWS CLI

알림 규칙에 태그를 추가하는 방법

다음 tag-resource 예제에서는 지정된 알림 규칙에 Team의 키 이름 및 값인 Li_Juan을 갖는 태그를 추가합니다.

aws codestar-notifications tag-resource \ --arn arn:aws:codestar-notifications:us-east-1:123456789012:notificationrule/fe1efd35-EXAMPLE \ --tags Team=Li_Juan

출력:

{ "Tags": { "Team": "Li_Juan" } }

자세한 내용은 AWS 개발자 도구 콘솔 사용 설명서Create a Notification Rule을 참조하세요.

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

다음 코드 예시에서는 unsubscribe을 사용하는 방법을 보여 줍니다.

AWS CLI

알림 규칙에서 대상을 제거하는 방법

다음 unsubscribe 예제에서는 지정된 알림 규칙의 대상으로 Amazon SNS 주제를 제거합니다.

aws codestar-notifications unsubscribe \ --arn arn:aws:codestar-notifications:us-east-1:123456789012:notificationrule/dc82df7a-EXAMPLE \ --target TargetType=SNS,TargetAddress=arn:aws:sns:us-east-1:123456789012:MyNotificationTopic

출력:

{ "Arn": "arn:aws:codestar-notifications:us-east-1:123456789012:notificationrule/dc82df7a-EXAMPLE" "TargetAddress": "arn:aws:sns:us-east-1:123456789012:MyNotificationTopic" }

자세한 내용은 AWS 개발자 도구 콘솔 사용 설명서의 Add or Remove an Amazon SNS Topic as a Target for a Notification Rule을 참조하세요.

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

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

AWS CLI

알림 규칙에서 태그를 제거하는 방법

다음 untag-resource 예제에서는 지정된 알림 규칙에서 키 이름이 Team인 태그를 제거합니다.

aws codestar-notifications untag-resource \ --arn arn:aws:codestar-notifications:us-east-1:123456789012:notificationrule/fe1efd35-EXAMPLE \ --tag-keys Team

이 명령은 출력을 생성하지 않습니다.

자세한 내용은 AWS 개발자 도구 콘솔 사용 설명서Edit a Notification Rule을 참조하세요.

  • API 세부 정보는 AWS CLI Command Reference의 UntagResource를 참조하세요.

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

AWS CLI

알림 규칙을 업데이트하는 방법

다음 update-notification-rule 예제에서는 update.json이라는 JSON 파일을 사용하여 AWS 계정 123456789012에 이름이 MyNotificationRule인 알림 규칙을 업데이트합니다.

aws codestar-notifications update-notification-rule \ --cli-input-json file://update.json

update.json의 콘텐츠:

{ "Name": "MyUpdatedNotificationRule", "EventTypeIds": [ "codecommit-repository-branches-and-tags-created" ], "Resource": "arn:aws:codecommit:us-east-1:123456789012:MyDemoRepo", "Targets": [ { "TargetType": "SNS", "TargetAddress": "arn:aws:sns:us-east-1:123456789012:MyNotificationTopic" } ], "Status": "ENABLED", "DetailType": "FULL" }

출력:

{ "Arn": "arn:aws:codestar-notifications:us-east-1:123456789012:notificationrule/dc82df7a-EXAMPLE" }

자세한 내용은 AWS 개발자 도구 콘솔 사용 설명서Edit a Notification Rule을 참조하세요.