AWS CLI에서 Amazon SNS 액세스
AWS Command Line Interface(AWS CLI)를 사용하여 Amazon Simple Notification Service(Amazon SNS)의 기능에 액세스할 수 있습니다. Amazon SNS에 대한 AWS CLI 명령을 나열하려면 다음 명령을 사용합니다.
aws sns help
명령을 실행하기 전에 기본 자격 증명을 설정합니다. 자세한 내용은 AWS CLI 설정 구성 섹션을 참조하세요.
이 주제에서는 Amazon SNS에 대한 일반적인 태스크를 수행하는 AWS CLI 명령의 예제를 보여줍니다.
주제 생성
주제를 만들려면 sns
create-topic
$
aws sns create-topic --name
my-topic
{ "TopicArn": "arn:aws:sns:us-west-2:123456789012:my-topic" }
나중에 메시지를 게시할 때 사용할 응답의 TopicArn
을 적어 둡니다.
주제 구독
주제를 구독하려면 sns
subscribe
다음 예제는 email
에 대한 이메일 주소와 notification-endpoint
프로토콜을 지정합니다.
$
aws sns subscribe --topic-arn arn:aws:sns:us-west-2:123456789012:
my-topic
--protocolsaanvi@example.com
{ "SubscriptionArn": "pending confirmation" }
AWS는 subscribe
명령으로 지정한 이메일 주소로 즉시 확인 메시지를 보냅니다. 이메일 메시지에는 다음 텍스트가 포함됩니다.
You have chosen to subscribe to the topic: arn:aws:sns:us-west-2:123456789012:my-topic To confirm this subscription, click or visit the following link (If this was in error no action is necessary): Confirm subscription
수신자가 구독 확인 링크를 클릭하면 수신자의 브라우저에 다음과 유사한 정보가 포함된 알림 메시지가 표시됩니다.
Subscription confirmed! You have subscribed saanvi@example.com to the topic:my-topic. Your subscription's id is: arn:aws:sns:us-west-2:123456789012:my-topic:1328f057-de93-4c15-512e-8bb22EXAMPLE If it was not your intention to subscribe, click here to unsubscribe.
주제 게시
주제의 모든 구독자에게 메시지를 보내려면 sns
publish
다음 예제에서는 지정된 주제의 모든 가입자에게 'Hello World!'라는 메시지를 보냅니다.
$
aws sns publish --topic-arn
arn:aws:sns:us-west-2:123456789012:my-topic
--message"Hello World!"
{ "MessageId": "4e41661d-5eec-5ddf-8dab-2c867EXAMPLE" }
이 예에서 AWS는 'Hello World!' 텍스트가 포함된 이메일 메시지를 saanvi@example.com
으로 전송합니다.
주제에서 구독 취소
주제 구독을 해지하고 해당 주제로 게시된 메시지 수신을 중단하려면 sns
unsubscribe
$
aws sns unsubscribe --subscription-arn
arn:aws:sns:us-west-2:123456789012:my-topic:1328f057-de93-4c15-512e-8bb22EXAMPLE
구독이 성공적으로 해지되었는지 확인하려면 sns
list-subscriptions
$
aws sns list-subscriptions
주제 삭제
주제를 삭제하려면 sns
delete-topic
$
aws sns delete-topic --topic-arn arn:aws:sns:us-west-2:123456789012:my-topic
AWS가 주제를 성공적으로 삭제했는지 확인하려면 sns
list-topics
$
aws sns list-topics