Creating a subscription
-
In the management console
, select the folder containing the topic. -
Navigate
to Cloud Notification Service. -
Select Topics on the left.
-
Select a topic.
-
Select Subscriptions on the left.
-
Click Create subscription.
-
Select a notification channel type:
-
Mobile push notifications.
Enter the endpoint ARN in
arn:aws:sns::<cloud_id>:endpoint/<platform>/<channel_name>/<endpoint_unique_id>format. You can copy the ARN on the endpoint’s settings page. -
In-browser push notifications.
Enter the endpoint ARN in
arn:aws:sns::<cloud_id>:endpoint/<platform>/<channel_name>/<endpoint_unique_id>format. -
SMS.
Enter your phone number in E.164
format, e.g.,+79991112233. You do not need to pre-add the phone number to the SMS notification channel, but you need to create the channel itself. -
Yandex Message Queue
Enter the Message Queue URL.
-
-
Click Create subscription.
Subscribe other endpoints to the topic in the same way.
-
-
If you do not have the AWS CLI yet, install and configure it.
-
Run this command:
aws sns subscribe \ --topic-arn <topic_ARN> \ --protocol <channel_type> \ --notification-endpoint <endpoint_ARN_or_phone_number>Where:
-
topic-arn: Topic ARN. -
protocol: Notification channel type, e.g.,sms,application,sqs. -
notification-endpoint: Endpoint subscribing to the topic.- For both mobile and browser push notifications, enter your endpoint ARN in
arn:aws:sns::<cloud_id>:endpoint/<platform>/<channel_name>/<endpoint_unique_id>format. - For SMS, enter a phone number in E.164
format, e.g.,+79991112233. - For Message Queue, enter the queue URL.
For a topic to be able to send messages to a queue, it must have the
SQSServiceAccountIdattribute set. See the guide on creating and managing a topic for more details. - For both mobile and browser push notifications, enter your endpoint ARN in
Learn more about the
aws sns subscribecommand in this AWS guide . -
-
If you do not have the AWS SDK for Python (boto3) yet, install and configure it.
-
Use the following code to subscribe an endpoint to notifications in a topic:
try: response = client.subscribe( TopicArn = "<topic_ARN>", Protocol = "<channel_type>", Endpoint = "<endpoint_ARN_or_phone_number_or_queue_URL>" ) print(f"Topic ARN: {response['TopicArn']}") except botocore.exceptions.ClientError as error: print(f"Error: {error}")Where:
-
TopicArn: Topic ARN. -
Protocol: Notification channel type, e.g.,sms,application, orsqs. -
Endpoint: Endpoint subscribing to the topic:- For both mobile and browser push notifications, enter your endpoint ARN in
arn:aws:sns::<cloud_id>:endpoint/<platform>/<channel_name>/<endpoint_unique_id>format. - For SMS, enter a phone number in E.164
format, e.g.,+79991112233. - For Message Queue, enter the queue URL.
For a topic to be able to send messages to a queue, it must have the
SQSServiceAccountIdattribute set. For details, see the guides on creating and managing a topic. - For both mobile and browser push notifications, enter your endpoint ARN in
-