

# AWS CLI를 사용한 Amazon SNS 예제
<a name="cli_sns_code_examples"></a>

다음 코드 예제는 Amazon SNS와 함께 AWS Command Line Interface를 사용하여 작업을 수행하고 일반적인 시나리오를 구현하는 방법을 보여줍니다.

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

*시나리오*는 동일한 서비스 내에서 또는 다른 AWS 서비스와 결합된 상태에서 여러 함수를 직접적으로 호출하여 특정 태스크를 수행하는 방법을 보여주는 코드 예제입니다.

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

**Topics**
+ [작업](#actions)
+ [시나리오](#scenarios)

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

### `add-permission`
<a name="sns_AddPermission_cli_topic"></a>

다음 코드 예시는 `add-permission`의 사용 방법을 보여줍니다.

**AWS CLI**  
**주제에 권한을 추가하는 방법**  
다음 `add-permission` 예제에서는 AWS 계정 `987654321098`이 AWS 계정 `123456789012`에서 지정된 주제로 `Publish` 작업을 사용할 수 있는 권한을 추가합니다.  

```
aws sns add-permission \
    --topic-arn arn:aws:sns:us-west-2:123456789012:MyTopic \
    --label Publish-Permission \
    --aws-account-id 987654321098 \
    --action-name Publish
```
이 명령은 출력을 생성하지 않습니다.  
+  API 세부 정보는 **AWS CLI 명령 참조의 [AddPermission](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/sns/add-permission.html) 섹션을 참조하세요.

### `check-if-phone-number-is-opted-out`
<a name="sns_CheckIfPhoneNumberIsOptedOut_cli_topic"></a>

다음 코드 예시는 `check-if-phone-number-is-opted-out`의 사용 방법을 보여줍니다.

**AWS CLI**  
**전화번호의 SMS 메시지 옵트아웃을 확인하려면**  
다음 `check-if-phone-number-is-opted-out`예시에서는 지정된 전화번호가 현재 AWS계정의 SMS 메시지 수신을 옵트아웃했는지 여부를 확인합니다.  

```
aws sns check-if-phone-number-is-opted-out \
    --phone-number +1555550100
```
출력:  

```
{
    "isOptedOut": false
}
```
+  API 세부 정보는 *AWS CLI명령 참조*의 [CheckIfPhoneNumberIsOptedOut](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/sns/check-if-phone-number-is-opted-out.html)을 참조하세요.

### `confirm-subscription`
<a name="sns_ConfirmSubscription_cli_topic"></a>

다음 코드 예시는 `confirm-subscription`의 사용 방법을 보여줍니다.

**AWS CLI**  
**구독을 확인하려면**  
다음 `confirm-subscription`명령은 `my-topic`라는 SNS 주제를 구독할 때 시작된 확인 프로세스를 완료합니다. --token 파라미터는 구독 호출에 지정된 알림 엔드포인트로 전송된 확인 메시지에서 제공됩니다.  

```
aws sns confirm-subscription \
    --topic-arn arn:aws:sns:us-west-2:123456789012:my-topic \
    --token 2336412f37fb687f5d51e6e241d7700ae02f7124d8268910b858cb4db727ceeb2474bb937929d3bdd7ce5d0cce19325d036bc858d3c217426bcafa9c501a2cace93b83f1dd3797627467553dc438a8c974119496fc3eff026eaa5d14472ded6f9a5c43aec62d83ef5f49109da7176391
```
출력:  

```
{
    "SubscriptionArn": "arn:aws:sns:us-west-2:123456789012:my-topic:8a21d249-4329-4871-acc6-7be709c6ea7f"
}
```
+  API 세부 정보는 *AWS CLI명령 참조*의 [ConfirmSubscription](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/sns/confirm-subscription.html)을 참조하세요.

### `create-platform-application`
<a name="sns_CreatePlatformApplication_cli_topic"></a>

다음 코드 예시는 `create-platform-application`의 사용 방법을 보여줍니다.

**AWS CLI**  
**플랫폼 애플리케이션을 생성하는 방법**  
다음 `create-platform-application` 예제에서는 지정된 플랫폼 자격 증명을 사용하여 Google Firebase 플랫폼 애플리케이션을 생성합니다.  

```
aws sns create-platform-application \
    --name MyApplication \
    --platform GCM \
    --attributes PlatformCredential=EXAMPLEabcd12345jklm67890stuv12345bcdef
```
출력:  

```
{
    "PlatformApplicationArn": "arn:aws:sns:us-west-2:123456789012:app/GCM/MyApplication"
}
```
+  API 세부 정보는 **AWS CLI 명령 참조의 [CreatePlatformApplication](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/sns/create-platform-application.html) 섹션을 참조하세요.

### `create-topic`
<a name="sns_CreateTopic_cli_topic"></a>

다음 코드 예시는 `create-topic`의 사용 방법을 보여줍니다.

**AWS CLI**  
**SNS 주제를 생성하려면**  
다음 `create-topic`예제에서는 `my-topic`이라는 SNS 주제를 생성합니다.  

```
aws sns create-topic \
    --name my-topic
```
출력:  

```
{
    "ResponseMetadata": {
        "RequestId": "1469e8d7-1642-564e-b85d-a19b4b341f83"
    },
    "TopicArn": "arn:aws:sns:us-west-2:123456789012:my-topic"
}
```
자세한 내용은 *AWS명령줄 인터페이스 사용 설명서*의 [Amazon SQS 및 Amazon SNS와 함께 AWS명령줄 인터페이스 사용](https://docs.aws.amazon.com/cli/latest/userguide/cli-sqs-queue-sns-topic.html)을 참조하세요.  
+  API 세부 정보는 *AWS CLI명령 참조*의 [CreateTopic](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/sns/create-topic.html)을 참조하세요.

### `delete-endpoint`
<a name="sns_DeleteEndpoint_cli_topic"></a>

다음 코드 예시는 `delete-endpoint`의 사용 방법을 보여줍니다.

**AWS CLI**  
**플랫폼 애플리케이션 엔드포인트를 생성하는 방법**  
다음 `delete-endpoint` 예제에서는 지정된 플랫폼 애플리케이션 엔드포인트를 삭제합니다.  

```
aws sns delete-endpoint \
    --endpoint-arn arn:aws:sns:us-west-2:123456789012:endpoint/GCM/MyApplication/12345678-abcd-9012-efgh-345678901234
```
이 명령은 출력을 생성하지 않습니다.  
+  API 세부 정보는 **AWS CLI 명령 참조의 [DeleteEndpoint](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/sns/delete-endpoint.html) 섹션을 참조하세요.

### `delete-platform-application`
<a name="sns_DeletePlatformApplication_cli_topic"></a>

다음 코드 예시는 `delete-platform-application`의 사용 방법을 보여줍니다.

**AWS CLI**  
**플랫폼 애플리케이션을 삭제하는 방법**  
다음 `delete-platform-application` 예제에서는 지정된 플랫폼 애플리케이션을 삭제합니다  

```
aws sns delete-platform-application \
    --platform-application-arn arn:aws:sns:us-west-2:123456789012:app/ADM/MyApplication
```
이 명령은 출력을 생성하지 않습니다.  
+  API 세부 정보는 **AWS CLI 명령 참조의 [DeletePlatformApplication](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/sns/delete-platform-application.html) 섹션을 참조하세요.

### `delete-topic`
<a name="sns_DeleteTopic_cli_topic"></a>

다음 코드 예시는 `delete-topic`의 사용 방법을 보여줍니다.

**AWS CLI**  
**SNS 주제를 삭제하려면**  
다음 `delete-topic`예제에서는 지정된 SNS 주제를 삭제합니다.  

```
aws sns delete-topic \
    --topic-arn "arn:aws:sns:us-west-2:123456789012:my-topic"
```
이 명령은 출력을 생성하지 않습니다.  
+  API 세부 정보는 *AWS CLI명령 참조*의 [DeleteTopic](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/sns/delete-topic.html)을 참조하세요.

### `get-endpoint-attributes`
<a name="sns_GetEndpointAttributes_cli_topic"></a>

다음 코드 예시는 `get-endpoint-attributes`의 사용 방법을 보여줍니다.

**AWS CLI**  
**플랫폼 애플리케이션 엔드포인트 속성을 나열하는 방법**  
다음 `get-endpoint-attributes` 예제에서는 지정된 플랫폼 애플리케이션 엔드포인트의 속성을 나열합니다.  

```
aws sns get-endpoint-attributes \
    --endpoint-arn arn:aws:sns:us-west-2:123456789012:endpoint/GCM/MyApplication/12345678-abcd-9012-efgh-345678901234
```
출력:  

```
{
    "Attributes": {
        "Enabled": "true",
        "Token": "EXAMPLE12345..."
    }
}
```
+  API 세부 정보는 **AWS CLI 명령 참조의 [GetEndpointAttributes](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/sns/get-endpoint-attributes.html) 섹션을 참조하세요.

### `get-platform-application-attributes`
<a name="sns_GetPlatformApplicationAttributes_cli_topic"></a>

다음 코드 예시는 `get-platform-application-attributes`의 사용 방법을 보여줍니다.

**AWS CLI**  
**플랫폼 애플리케이션 속성을 나열하는 방법**  
다음 `get-platform-application-attributes` 예제에서는 지정된 플랫폼 애플리케이션의 속성을 나열합니다.  

```
aws sns get-platform-application-attributes \
    --platform-application-arn arn:aws:sns:us-west-2:123456789012:app/MPNS/MyApplication
```
출력:  

```
{
    "Attributes": {
        "Enabled": "true",
        "SuccessFeedbackSampleRate": "100"
    }
}
```
+  API 세부 정보는 **AWS CLI 명령 참조의 [GetPlatformApplicationAttributes](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/sns/get-platform-application-attributes.html) 섹션을 참조하세요.

### `get-sms-attributes`
<a name="sns_GetSMSAttributes_cli_topic"></a>

다음 코드 예시는 `get-sms-attributes`의 사용 방법을 보여줍니다.

**AWS CLI**  
**기본 SMS 메시지 속성을 나열하려면**  
다음 `get-sms-attributes`예제에서는 SMS 메시지 전송의 기본 속성을 나열합니다.  

```
aws sns get-sms-attributes
```
출력:  

```
{
    "attributes": {
        "DefaultSenderID": "MyName"
    }
}
```
+  API 세부 정보는 *AWS CLI명령 참조*의 [GetSMSAttributes](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/sns/get-sms-attributes.html)를 참조하세요.

### `get-subscription-attributes`
<a name="sns_GetSubscriptionAttributes_cli_topic"></a>

다음 코드 예시는 `get-subscription-attributes`의 사용 방법을 보여줍니다.

**AWS CLI**  
**주제에 대한 구독 속성을 검색하는 방법**  
다음 `get-subscription-attributes` 명령은 지정된 구독의 속성을 표시합니다. `list-subscriptions` 명령의 출력에서 `subscription-arn`를 가져올 수 있습니다.  

```
aws sns get-subscription-attributes \
    --subscription-arn "arn:aws:sns:us-west-2:123456789012:my-topic:8a21d249-4329-4871-acc6-7be709c6ea7f"
```
출력:  

```
{
    "Attributes": {
        "Endpoint": "my-email@example.com",
        "Protocol": "email",
        "RawMessageDelivery": "false",
        "ConfirmationWasAuthenticated": "false",
        "Owner": "123456789012",
        "SubscriptionArn": "arn:aws:sns:us-west-2:123456789012:my-topic:8a21d249-4329-4871-acc6-7be709c6ea7f",
        "TopicArn": "arn:aws:sns:us-west-2:123456789012:my-topic"
    }
}
```
+  API 세부 정보는 **AWS CLI 명령 참조의 [GetSubscriptionAttributes](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/sns/get-subscription-attributes.html) 섹션을 참조하세요.

### `get-topic-attributes`
<a name="sns_GetTopicAttributes_cli_topic"></a>

다음 코드 예시는 `get-topic-attributes`의 사용 방법을 보여줍니다.

**AWS CLI**  
**주제의 속성을 검색하려면**  
다음 `get-topic-attributes`예제에서는 지정된 주제의 속성을 표시합니다.  

```
aws sns get-topic-attributes \
    --topic-arn "arn:aws:sns:us-west-2:123456789012:my-topic"
```
출력:  

```
{
    "Attributes": {
        "SubscriptionsConfirmed": "1",
        "DisplayName": "my-topic",
        "SubscriptionsDeleted": "0",
        "EffectiveDeliveryPolicy": "{\"http\":{\"defaultHealthyRetryPolicy\":{\"minDelayTarget\":20,\"maxDelayTarget\":20,\"numRetries\":3,\"numMaxDelayRetries\":0,\"numNoDelayRetries\":0,\"numMinDelayRetries\":0,\"backoffFunction\":\"linear\"},\"disableSubscriptionOverrides\":false}}",
        "Owner": "123456789012",
        "Policy": "{\"Version\":\"2008-10-17\",\"Id\":\"__default_policy_ID\",\"Statement\":[{\"Sid\":\"__default_statement_ID\",\"Effect\":\"Allow\",\"Principal\":{\"AWS\":\"*\"},\"Action\":[\"SNS:Subscribe\",\"SNS:ListSubscriptionsByTopic\",\"SNS:DeleteTopic\",\"SNS:GetTopicAttributes\",\"SNS:Publish\",\"SNS:RemovePermission\",\"SNS:AddPermission\",\"SNS:SetTopicAttributes\"],\"Resource\":\"arn:aws:sns:us-west-2:123456789012:my-topic\",\"Condition\":{\"StringEquals\":{\"AWS:SourceOwner\":\"0123456789012\"}}}]}",
        "TopicArn": "arn:aws:sns:us-west-2:123456789012:my-topic",
        "SubscriptionsPending": "0"
    }
}
```
+  API 세부 정보는 *AWS CLI명령 참조*의 [GetTopicAttributes](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/sns/get-topic-attributes.html)를 참조하세요.

### `list-endpoints-by-platform-application`
<a name="sns_ListEndpointsByPlatformApplication_cli_topic"></a>

다음 코드 예시는 `list-endpoints-by-platform-application`의 사용 방법을 보여줍니다.

**AWS CLI**  
**플랫폼 애플리케이션의 엔드포인트를 나열하는 방법**  
다음 `list-endpoints-by-platform-application` 예제에서는 지정된 플랫폼 애플리케이션의 엔드포인트 및 엔드포인트 속성을 나열합니다.  

```
aws sns list-endpoints-by-platform-application \
    --platform-application-arn arn:aws:sns:us-west-2:123456789012:app/GCM/MyApplication
```
출력:  

```
{
    "Endpoints": [
        {
            "Attributes": {
                "Token": "EXAMPLE12345...,
                "Enabled": "true"
            },
            "EndpointArn": "arn:aws:sns:us-west-2:123456789012:endpoint/GCM/MyApplication/12345678-abcd-9012-efgh-345678901234"
        }
    ]
}
```
+  API 세부 정보는 **AWS CLI 명령 참조의 [ListEndpointsByPlatformApplication](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/sns/list-endpoints-by-platform-application.html) 섹션을 참조하세요.

### `list-phone-numbers-opted-out`
<a name="sns_ListPhoneNumbersOptedOut_cli_topic"></a>

다음 코드 예시는 `list-phone-numbers-opted-out`의 사용 방법을 보여줍니다.

**AWS CLI**  
**SMS 메시지 옵트아웃을 나열하려면**  
다음 `list-phone-numbers-opted-out`예제에서는 SMS 메시지 수신을 옵트아웃한 전화번호를 나열합니다.  

```
aws sns list-phone-numbers-opted-out
```
출력:  

```
{
    "phoneNumbers": [
        "+15555550100"
    ]
}
```
+  API 세부 정보는  *AWS CLI 명령 참조*의 [ListPhoneNumbersOptedOut](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/sns/list-phone-numbers-opted-out.html)을 참조하세요.

### `list-platform-applications`
<a name="sns_ListPlatformApplications_cli_topic"></a>

다음 코드 예시는 `list-platform-applications`의 사용 방법을 보여줍니다.

**AWS CLI**  
**플랫폼 애플리케이션을 나열하는 방법**  
다음 `list-platform-applications` 예제에서는 ADM 및 MPNS용 플랫폼 애플리케이션을 나열합니다.  

```
aws sns list-platform-applications
```
출력:  

```
{
    "PlatformApplications": [
        {
            "PlatformApplicationArn": "arn:aws:sns:us-west-2:123456789012:app/ADM/MyApplication",
            "Attributes": {
                "SuccessFeedbackSampleRate": "100",
                "Enabled": "true"
            }
        },
        {
            "PlatformApplicationArn": "arn:aws:sns:us-west-2:123456789012:app/MPNS/MyOtherApplication",
            "Attributes": {
                "SuccessFeedbackSampleRate": "100",
                "Enabled": "true"
            }
        }
    ]
}
```
+  API 세부 정보는 **AWS CLI 명령 참조의 [ListPlatformApplications](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/sns/list-platform-applications.html) 섹션을 참조하세요.

### `list-subscriptions-by-topic`
<a name="sns_ListSubscriptionsByTopic_cli_topic"></a>

다음 코드 예시는 `list-subscriptions-by-topic`의 사용 방법을 보여줍니다.

**AWS CLI**  
**주제와 연결된 구독을 나열하는 방법**  
다음 `list-subscriptions-by-topic` 명령은 지정된 주제와 연결된 SNS 구독 목록을 검색합니다.  

```
aws sns list-subscriptions-by-topic \
    --topic-arn "arn:aws:sns:us-west-2:123456789012:my-topic"
```
출력:  

```
{
    "Subscriptions": [
        {
            "Owner": "123456789012",
            "Endpoint": "my-email@example.com",
            "Protocol": "email",
            "TopicArn": "arn:aws:sns:us-west-2:123456789012:my-topic",
            "SubscriptionArn": "arn:aws:sns:us-west-2:123456789012:my-topic:8a21d249-4329-4871-acc6-7be709c6ea7f"
        }
    ]
}
```
+  API 세부 정보는 **AWS CLI 명령 참조의 [ListSubscriptionsByTopic](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/sns/list-subscriptions-by-topic.html) 섹션을 참조하세요.

### `list-subscriptions`
<a name="sns_ListSubscriptions_cli_topic"></a>

다음 코드 예시는 `list-subscriptions`의 사용 방법을 보여줍니다.

**AWS CLI**  
**SNS 구독을 나열하려면**  
다음 `list-subscriptions`예제에서는 AWS계정의 SNS 구독 목록을 표시합니다.  

```
aws sns list-subscriptions
```
출력:  

```
{
    "Subscriptions": [
        {
            "Owner": "123456789012",
            "Endpoint": "my-email@example.com",
            "Protocol": "email",
            "TopicArn": "arn:aws:sns:us-west-2:123456789012:my-topic",
            "SubscriptionArn": "arn:aws:sns:us-west-2:123456789012:my-topic:8a21d249-4329-4871-acc6-7be709c6ea7f"
        }
    ]
}
```
+  API 세부 정보는 *AWS CLI 명령 참조*의 [ListSubscriptions](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/sns/list-subscriptions.html)를 참조하세요.

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

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

**AWS CLI**  
**주제에 대한 태그를 나열하는 방법**  
다음 `list-tags-for-resource` 예제에서는 지정된 Amazon SNS 주제에 대한 태그를 나열합니다.  

```
aws sns list-tags-for-resource \
    --resource-arn arn:aws:sns:us-west-2:123456789012:MyTopic
```
출력:  

```
{
    "Tags": [
        {
            "Key": "Team",
            "Value": "Alpha"
        }
    ]
}
```
+  API 세부 정보는 *AWS CLI 명령 참조*의 [ListTagsForResource](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/sns/list-tags-for-resource.html) 섹션을 참조하세요.

### `list-topics`
<a name="sns_ListTopics_cli_topic"></a>

다음 코드 예시는 `list-topics`의 사용 방법을 보여줍니다.

**AWS CLI**  
**SNS 주제를 나열하려면**  
다음 `list-topics`예제에서는 AWS계정의 모든 SNS 주제를 나열합니다.  

```
aws sns list-topics
```
출력:  

```
{
    "Topics": [
        {
            "TopicArn": "arn:aws:sns:us-west-2:123456789012:my-topic"
        }
    ]
}
```
+  API 세부 정보는 *AWS CLI명령 참조*의 [ListTopics](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/sns/list-topics.html)를 참조하세요.

### `opt-in-phone-number`
<a name="sns_OptInPhoneNumber_cli_topic"></a>

다음 코드 예시는 `opt-in-phone-number`의 사용 방법을 보여줍니다.

**AWS CLI**  
**SMS 메시지에 옵트인하는 방법**  
다음 `opt-in-phone-number` 예제에서는 SMS 메시지 수신을 옵트아웃한 전화번호를 나열합니다.  

```
aws sns opt-in-phone-number \
    --phone-number +15555550100
```
이 명령은 출력을 생성하지 않습니다.  
+  API 세부 정보는 **AWS CLI 명령 참조의 [OptInPhoneNumber](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/sns/opt-in-phone-number.html) 섹션을 참조하세요.

### `publish`
<a name="sns_Publish_cli_topic"></a>

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

**AWS CLI**  
**예제 1: 주제에 메시지를 게시하려면**  
다음 `publish`예제에서는 지정된 Amazon SNS 주제에 지정된 메시지를 게시합니다. 메시지는 줄 바꿈을 포함할 수 있는 텍스트 파일에서 제공됩니다.  

```
aws sns publish \
    --topic-arn "arn:aws:sns:us-west-2:123456789012:my-topic" \
    --message file://message.txt
```
`message.txt`의 콘텐츠:  

```
Hello World
Second Line
```
출력:  

```
{
    "MessageId": "123a45b6-7890-12c3-45d6-111122223333"
}
```
**예제 2: 전화번호에 SMS 메시지를 게시하려면**  
다음 `publish`예제에서는 `Hello world!`메시지를 전화번호 `+1-555-555-0100`에 게시합니다.  

```
aws sns publish \
    --message "Hello world!" \
    --phone-number +1-555-555-0100
```
출력:  

```
{
    "MessageId": "123a45b6-7890-12c3-45d6-333322221111"
}
```
+  API 세부 정보는 *AWS CLI명령 참조*의 [Publish](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/sns/publish.html)를 참조하세요.

### `put-data-protection-policy`
<a name="sns_PutDataProtectionPolicy_cli_topic"></a>

다음 코드 예시는 `put-data-protection-policy`의 사용 방법을 보여줍니다.

**AWS CLI**  
**데이터 보호 정책을 설정하는 방법**  
**예제 1: 게시자가 CreditCardNumber로 메시지를 게시하지 못하도록 거부하는 방법**  
다음 `put-data-protection-policy` 예제에서는 게시자가 CreditCardNumber 를 사용하여 메시지를 게시하는 것을 거부합니다.  

```
aws sns put-data-protection-policy \
    --resource-arn arn:aws:sns:us-east-1:123456789012:mytopic \
    --data-protection-policy "{\"Name\":\"data_protection_policy\",\"Description\":\"Example data protection policy\",\"Version\":\"2021-06-01\",\"Statement\":[{\"DataDirection\":\"Inbound\",\"Principal\":[\"*\"],\"DataIdentifier\":[\"arn:aws:dataprotection::aws:data-identifier/CreditCardNumber\"],\"Operation\":{\"Deny\":{}}}]}"
```
이 명령은 출력을 생성하지 않습니다.  
**예제 2: 파일에서 파라미터를 로드하는 방법**  
다음 `put-data-protection-policy` 명령은 파일에서 파라미터를 로드합니다.  

```
aws sns put-data-protection-policy \
    --resource-arn arn:aws:sns:us-west-2:123456789012:MyTopic \
    --data-protection-policy file://policy.json
```
이 명령은 출력을 생성하지 않습니다.  
+  API 세부 정보는 **AWS CLI 명령 참조의 [PutDataProtectionPolicy](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/sns/put-data-protection-policy.html) 섹션을 참조하세요.

### `remove-permission`
<a name="sns_RemovePermission_cli_topic"></a>

다음 코드 예시는 `remove-permission`의 사용 방법을 보여줍니다.

**AWS CLI**  
**주제에서 권한 집합을 제거하는 방법**  
다음 `remove-permission` 예제에서는 지정된 주제에서 `Publish-Permission` 권한을 제거합니다.  

```
aws sns remove-permission \
    --topic-arn arn:aws:sns:us-west-2:123456789012:MyTopic \
    --label Publish-Permission
```
이 명령은 출력을 생성하지 않습니다.  
+  API 세부 정보는 *AWS CLI 명령 참조*의 [RemovePermission](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/sns/remove-permission.html)을 참조하세요.

### `set-endpoint-attributes`
<a name="sns_SetEndpointAttributes_cli_topic"></a>

다음 코드 예시는 `set-endpoint-attributes`의 사용 방법을 보여줍니다.

**AWS CLI**  
**엔드포인트 속성을 설정하는 방법**  
다음 `set-endpoint-attributes` 예제에서는 지정된 플랫폼 애플리케이션 엔드포인트를 비활성화합니다.  

```
aws sns set-endpoint-attributes \
    --endpoint-arn arn:aws:sns:us-west-2:123456789012:endpoint/GCM/MyApplication/12345678-abcd-9012-efgh-345678901234 \
    --attributes Enabled=false
```
출력:  

```
{
    "Attributes": {
        "Enabled": "false",
        "Token": "EXAMPLE12345..."
    }
}
```
+  API 세부 정보는 **AWS CLI 명령 참조의 [SetEndpointAttributes](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/sns/set-endpoint-attributes.html) 섹션을 참조하세요.

### `set-platform-application-attributes`
<a name="sns_SetPlatformApplicationAttributes_cli_topic"></a>

다음 코드 예시는 `set-platform-application-attributes`의 사용 방법을 보여줍니다.

**AWS CLI**  
**플랫폼 애플리케이션 속성을 설정하는 방법**  
다음 `set-platform-application-attributes` 예제에서는 지정된 플랫폼 애플리케이션의 `EventDeliveryFailure` 속성을 지정된 Amazon SNS 주제의 ARN으로 설정합니다.  

```
aws sns set-platform-application-attributes \
    --platform-application-arn arn:aws:sns:us-west-2:123456789012:app/GCM/MyApplication \
    --attributes EventDeliveryFailure=arn:aws:sns:us-west-2:123456789012:AnotherTopic
```
이 명령은 출력을 생성하지 않습니다.  
+  API 세부 정보는 **AWS CLI 명령 참조의 [SetPlatformApplicationAttributes](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/sns/set-platform-application-attributes.html) 섹션을 참조하세요.

### `set-sms-attributes`
<a name="sns_SetSMSAttributes_cli_topic"></a>

다음 코드 예시는 `set-sms-attributes`의 사용 방법을 보여줍니다.

**AWS CLI**  
**SMS 메시지 속성을 설정하려면**  
다음 `set-sms-attributes`예제에서는 SMS 메시지의 기본 발신자 ID를 `MyName`으로 설정합니다.  

```
aws sns set-sms-attributes \
    --attributes DefaultSenderID=MyName
```
이 명령은 출력을 생성하지 않습니다.  
+  API 세부 정보는 *AWS CLI명령 참조*의 [SetSMSAttributes](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/sns/set-sms-attributes.html)를 참조하세요.

### `set-subscription-attributes`
<a name="sns_SetSubscriptionAttributes_cli_topic"></a>

다음 코드 예시는 `set-subscription-attributes`의 사용 방법을 보여줍니다.

**AWS CLI**  
**구독 속성을 설정하려면**  
다음 `set-subscription-attributes`예제에서는 SQS 구독에 `RawMessageDelivery`속성을 설정합니다.  

```
aws sns set-subscription-attributes \
    --subscription-arn arn:aws:sns:us-east-1:123456789012:mytopic:f248de18-2cf6-578c-8592-b6f1eaa877dc \
    --attribute-name RawMessageDelivery \
    --attribute-value true
```
이 명령은 출력을 생성하지 않습니다.  
다음 `set-subscription-attributes`예제에서는 SQS 구독에 `FilterPolicy`속성을 설정합니다.  

```
aws sns set-subscription-attributes \
    --subscription-arn arn:aws:sns:us-east-1:123456789012:mytopic:f248de18-2cf6-578c-8592-b6f1eaa877dc \
    --attribute-name FilterPolicy \
    --attribute-value "{ \"anyMandatoryKey\": [\"any\", \"of\", \"these\"] }"
```
이 명령은 출력을 생성하지 않습니다.  
다음 `set-subscription-attributes`예제에서는 SQS 구독에서 `FilterPolicy`속성을 제거합니다.  

```
aws sns set-subscription-attributes \
    --subscription-arn arn:aws:sns:us-east-1:123456789012:mytopic:f248de18-2cf6-578c-8592-b6f1eaa877dc \
    --attribute-name FilterPolicy \
    --attribute-value "{}"
```
이 명령은 출력을 생성하지 않습니다.  
+  API 세부 정보는 *AWS CLI명령 참조*의 [SetSubscriptionAttributes](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/sns/set-subscription-attributes.html)를 참조하세요.

### `set-topic-attributes`
<a name="sns_SetTopicAttributes_cli_topic"></a>

다음 코드 예시는 `set-topic-attributes`의 사용 방법을 보여줍니다.

**AWS CLI**  
**주제에 대한 속성을 설정하려면**  
다음 `set-topic-attributes`예제에서는 지정된 주제에 `DisplayName`속성을 설정합니다.  

```
aws sns set-topic-attributes \
    --topic-arn arn:aws:sns:us-west-2:123456789012:MyTopic \
    --attribute-name DisplayName \
    --attribute-value MyTopicDisplayName
```
이 명령은 출력을 생성하지 않습니다.  
+  API 세부 정보는 *AWS CLI명령 참조*의 [SetTopicAttributes](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/sns/set-topic-attributes.html)를 참조하세요.

### `subscribe`
<a name="sns_Subscribe_cli_topic"></a>

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

**AWS CLI**  
**주제를 구독하려면**  
다음 `subscribe`명령은 이메일 주소로 지정된 주제를 구독합니다.  

```
aws sns subscribe \
    --topic-arn arn:aws:sns:us-west-2:123456789012:my-topic \
    --protocol email \
    --notification-endpoint my-email@example.com
```
출력:  

```
{
    "SubscriptionArn": "pending confirmation"
}
```
+  API 세부 정보는 *AWS CLI명령 참조*의 [Subscribe](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/sns/subscribe.html)를 참조하세요.

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

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

**AWS CLI**  
**주제에 태그를 추가하려면**  
다음 `tag-resource`예제에서는 지정된 Amazon SNS 주제에 메타데이터 태그를 추가합니다.  

```
aws sns tag-resource \
    --resource-arn arn:aws:sns:us-west-2:123456789012:MyTopic \
    --tags Key=Team,Value=Alpha
```
이 명령은 출력을 생성하지 않습니다.  
+  API 세부 정보는 **AWS CLI 명령 참조의 [TagResource](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/sns/tag-resource.html)를 참조하세요.

### `unsubscribe`
<a name="sns_Unsubscribe_cli_topic"></a>

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

**AWS CLI**  
**주제 구독을 취소하려면**  
다음 `unsubscribe`예제에서는 주제에서 지정된 구독을 삭제합니다.  

```
aws sns unsubscribe \
    --subscription-arn arn:aws:sns:us-west-2:0123456789012:my-topic:8a21d249-4329-4871-acc6-7be709c6ea7f
```
이 명령은 출력을 생성하지 않습니다.  
+  API 세부 정보는 *AWS CLI명령 참조*의 [Unsubscribe](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/sns/unsubscribe.html)를 참조하세요.

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

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

**AWS CLI**  
**주제에서 태그 제거**  
다음 `untag-resource` 예제에서는 지정된 Amazon SNS 주제에서 지정된 키가 있는 태그를 제거합니다.  

```
aws sns untag-resource \
    --resource-arn arn:aws:sns:us-west-2:123456789012:MyTopic \
    --tag-keys Team
```
이 명령은 출력을 생성하지 않습니다.  
+  API 세부 정보는 *AWS CLI 명령 참조*의 [UntagResource](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/sns/untag-resource.html)를 참조하세요.

## 시나리오
<a name="scenarios"></a>

### 푸시 알림에 대한 플랫폼 엔드포인트 생성
<a name="sns_CreatePlatformEndpoint_cli_topic"></a>

다음 코드 예제에서는 Amazon SNS 푸시 알림에 대한 플랫폼 엔드포인트를 생성하는 방법을 보여줍니다.

**AWS CLI**  
**플랫폼 애플리케이션 엔드포인트를 생성하려면**  
다음 `create-platform-endpoint` 예제에서는 지정된 토큰을 사용하여 지정된 플랫폼 애플리케이션의 엔드포인트를 생성합니다.  

```
aws sns create-platform-endpoint \
    --platform-application-arn arn:aws:sns:us-west-2:123456789012:app/GCM/MyApplication \
    --token EXAMPLE12345...
```
출력:  

```
{
      "EndpointArn": "arn:aws:sns:us-west-2:1234567890:endpoint/GCM/MyApplication/12345678-abcd-9012-efgh-345678901234"
}
```