Creating a subscription
- In the management console
, select the folder containing the topic. - In the list of services, select 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.
-
-
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: Type of notification channel, e.g.,sms,application.notification-endpoint: ARN of the endpoint subscribing to the topic, inarn: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 more information about the
aws sns subscribecommand, see the AWS documentation .
-
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>" ) 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.,smsorapplication.Endpoint: ARN of the endpoint subscribing to the topic, inarn: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.