

# AWS CodeStar를 사용한 Notifications 예제AWS CLI
<a name="cli_codestar-notifications_code_examples"></a>

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

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

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

**Topics**
+ [작업](#actions)

## 작업
<a name="actions"></a>

### `create-notification-rule`
<a name="codestar-notifications_CreateNotificationRule_cli_topic"></a>

다음 코드 예시는 `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](https://docs.aws.amazon.com/codestar-notifications/latest/userguide/notification-rule-create.html)을 참조하세요.  
+  API 세부 정보는 *AWS CLI 명령 참조*의 [CreateNotificationRule](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/codestar-notifications/create-notification-rule.html)을 참조하세요.

### `delete-notification-rule`
<a name="codestar-notifications_DeleteNotificationRule_cli_topic"></a>

다음 코드 예시는 `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](https://docs.aws.amazon.com/codestar-notifications/latest/userguide/notification-rule-delete.html)를 참조하세요.  
+  API 세부 정보는 *AWS CLI 명령 참조*의 [DeleteNotificationRule](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/codestar-notifications/delete-notification-rule.html)을 참조하세요.

### `delete-target`
<a name="codestar-notifications_DeleteTarget_cli_topic"></a>

다음 코드 예시는 `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](https://docs.aws.amazon.com/codestar-notifications/latest/userguide/notification-target-delete.html)를 참조하세요.  
+  API 세부 정보는 *AWS CLI 명령 참조*의 [DeleteTarget](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/codestar-notifications/delete-target.html)을 참조하세요.

### `describe-notification-rule`
<a name="codestar-notifications_DescribeNotificationRule_cli_topic"></a>

다음 코드 예시는 `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](https://docs.aws.amazon.com/codestar-notifications/latest/userguide/notification-rule-view.html)를 참조하세요.  
+  API 세부 정보는 *AWS CLI 명령 참조*의 [DescribeNotificationRule](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/codestar-notifications/describe-notification-rule.html)을 참조하세요.

### `list-event-types`
<a name="codestar-notifications_ListEventTypes_cli_topic"></a>

다음 코드 예시는 `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](https://docs.aws.amazon.com/codestar-notifications/latest/userguide/notification-rule-create.html)을 참조하세요.  
+  API 세부 정보는 *AWS CLI 명령 참조*의 [ListEventTypes](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/codestar-notifications/list-event-types.html)를 참조하세요.

### `list-notification-rules`
<a name="codestar-notifications_ListNotificationRules_cli_topic"></a>

다음 코드 예시는 `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](https://docs.aws.amazon.com/codestar-notifications/latest/userguide/notification-rule-view.html)를 참조하세요.  
+  API 세부 정보는 *AWS CLI 명령 참조*의 [ListNotificationRules](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/codestar-notifications/list-notification-rules.html)를 참조하세요.

### `list-tags-for-resource`
<a name="codestar-notifications_ListTagsForResource_cli_topic"></a>

다음 코드 예시는 `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](https://docs.aws.amazon.com/codestar-notifications/latest/userguide/notification-rule-create.html)을 참조하세요.  
+  API 세부 정보는 *AWS CLI 명령 참조*의 [ListTagsForResource](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/codestar-notifications/list-tags-for-resource.html)를 참조하세요.

### `list-targets`
<a name="codestar-notifications_ListTargets_cli_topic"></a>

다음 코드 예시는 `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](https://docs.aws.amazon.com/codestar-notifications/latest/userguide/notification-target-view.html)를 참조하세요.  
+  API 세부 정보는 *AWS CLI 명령 참조*의 [ListTargets](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/codestar-notifications/list-targets.html)를 참조하세요.

### `subscribe`
<a name="codestar-notifications_Subscribe_cli_topic"></a>

다음 코드 예시는 `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](https://docs.aws.amazon.com/codestar-notifications/latest/userguide/notification-target-change-rule.html)을 참조하세요.  
+  API 세부 정보는 *AWS CLI명령 참조*의 [Subscribe](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/codestar-notifications/subscribe.html)를 참조하세요.

### `tag-resource`
<a name="codestar-notifications_TagResource_cli_topic"></a>

다음 코드 예시는 `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](https://docs.aws.amazon.com/codestar-notifications/latest/userguide/notification-rule-create.html)을 참조하세요.  
+  API 세부 정보는 *AWS CLI 명령 참조*의 [TagResource](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/codestar-notifications/tag-resource.html)를 참조하세요.

### `unsubscribe`
<a name="codestar-notifications_Unsubscribe_cli_topic"></a>

다음 코드 예시는 `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](https://docs.aws.amazon.com/codestar-notifications/latest/userguide/notification-target-change-rule.html)을 참조하세요.  
+  API 세부 정보는 *AWS CLI명령 참조*의 [Unsubscribe](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/codestar-notifications/unsubscribe.html)를 참조하세요.

### `untag-resource`
<a name="codestar-notifications_UntagResource_cli_topic"></a>

다음 코드 예시는 `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](https://docs.aws.amazon.com/codestar-notifications/latest/userguide/notification-rule-edit.html)을 참조하세요.  
+  API 세부 정보는 *AWS CLI 명령 참조*의 [UntagResource](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/codestar-notifications/untag-resource.html)를 참조하세요.

### `update-notification-rule`
<a name="codestar-notifications_UpdateNotificationRule_cli_topic"></a>

다음 코드 예시는 `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](https://docs.aws.amazon.com/dtconsole/latest/userguide/notification-rule-edit.html)을 참조하세요.  
+  API 세부 정보는 *AWS CLI 명령 참조*의 [UpdateNotificationRule](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/codestar-notifications/update-notification-rule.html)을 참조하세요.