AWS Command Line Interface
User Guide

Using the AWS Command Line Interface with Amazon SNS

This section describes some common tasks related to Amazon Simple Notification Service (Amazon SNS) and how to perform them using the AWS Command Line Interface.

Create a Topic

The following command creates a topic named my-topic:

$ aws sns create-topic --name my-topic
    "TopicArn": "arn:aws:sns:us-west-2:123456789012:my-topic"

Make a note of the TopicArn, which you will use later to publish a message.

Subscribe to a Topic

The following command subscribes to a topic using the email protocol and an email address for the notification endpoint:

$ aws sns subscribe --topic-arn arn:aws:sns:us-west-2:123456789012:my-topic --protocol email --notification-endpoint
    "SubscriptionArn": "pending confirmation"

An email message will be sent to the email address listed in the subscribe command. The email message will have the following text:

You have chosen to subscribe to the topic:
To confirm this subscription, click or visit the following link (If this was in error no action is necessary):
Confirm subscription

After clicking Confirm subscription, a "Subscription confirmed!" notification message should appear in your browser with information similar to the following:

Subscription confirmed!

You have subscribed to the topic:my-topic.

Your subscription's id is:

If it was not your intention to subscribe, click here to unsubscribe.

Publish to a Topic

The following command publishes a message to a topic:

$ aws sns publish --topic-arn arn:aws:sns:us-west-2:123456789012:my-topic --message "Hello World!"
    "MessageId": "4e41661d-5eec-5ddf-8dab-2c867a709bab"

An email message with the text "Hello World!" will be sent to

Unsubscribe from a Topic

The following command unsubscribes from a topic:

$ aws sns unsubscribe --subscription-arn arn:aws:sns:us-west-2:123456789012:my-topic:1328f057-de93-4c15-512e-8bb2268db8c4

To verify the unsubscription to the topic, type the following:

$ aws sns list-subscriptions

Delete a Topic

The following command deletes a topic:

$ aws sns delete-topic --topic-arn arn:aws:sns:us-west-2:123456789012:my-topic

To verify the deletion of the topic, type the following:

$ aws sns list-topics