Bootstrap FreeKB - Amazon Web Services (AWS) - List Simple Notification Service (SNS) Subscribers using the AWS CLI
Amazon Web Services (AWS) - List Simple Notification Service (SNS) Subscribers using the AWS CLI


This assumes you have already configured the aws command line tool. If not, check out my article on Getting Started with the AWS CLI.

A Simple Notification Service (SNS) Topic can be used to create notification alerts, such as an email notification. This uses the messaging services pub sub model.

  • pub (publish) - create a new alert in a Topic
  • sub (subscribe) - get alerts in a Topic

Before setting up sub (subscribers), you will to create an SNS Topic. Check out my article on Creating a Simple Notification Service (SNS) Topics using the AWS CLI.

~]$ aws sns create-topic --name my-topic 
{
    "TopicArn": "arn:aws:sns:us-east-1:123456789012:my-topic"
}

 

There are various types of subscriptions.

  • application - messages published to the topic will be delivered to an EndpointArn for a mobile app or device - the message must be JSO
  • email - messages published to the topic will be emailed to the subscriber
  • email-json - messages published to the topic will be emailed to the subscriber - the message must be JSON
  • firehouse - messages published to the topic will be delivered to an AWS Kinesis Data Firehose delivery stream - the message must be JSON
  • http - messages published to the topic will be POST to an HTTP url - the message must be JSON
  • https - messages published to the topic will be POST to an HTTPS url - the message must be JSON
  • lambda - messages published to the topic will be sent to a Lambda Function
  • sms - messages published to the topic will be published to an SMS device (e.g. cellphone)
  • Simple Queue Service (SQS) - messages published to the topic will be put onto a SQS queue

 

The aws sns list-subscriptions command can be used to the Subscriptions to a Simple Notification Service (SNS) Topic.

Likewise, the aws sns list-subscriptions-by-topic command can be used to list the Topic Subscribers.

aws sns list-subscriptions-by-topic --topic-arn arn:aws:sns:us-east-1:123456789012:my-topic

 

If something like this is returned, the Topic currently has no subscribers.

{
    "Subscriptions": []
}

 

On the other hand, if the Topic has one or more subscribers, something like this should be returned. Notice in this example that the SubscrptionArn has PendingConfirmation. Perhaps john.doe@example.com has not yet acknowledged his subscription to the Topic.

{
    "Subscriptions": [
        {
            "SubscriptionArn": "PendingConfirmation",
            "Owner": "7112345074123",
            "Protocol": "email",
            "Endpoint": "john.doe@example.com",
            "TopicArn": "arn:aws:sns:us-east-1:123456789012:my-topic"
        }
    ]
}

 

On the other hand, if the user has confirmed their subscription to the Topic, the Amazon Resource Number (ARN) should be displayed.

{
    "Subscriptions": [
        {
            "SubscriptionArn": "arn:aws:sns:us-east-1:123456789012:my-topic:989c115b-a0c4-4e72-9c12-eea2b3250b7a",
            "Owner": "7112345074123",
            "Protocol": "email",
            "Endpoint": "john.doe@example.com",
            "TopicArn": "arn:aws:sns:us-east-1:123456789012:my-topic"
        }
    ]
}

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter ebff43 in the box below so that we can be sure you are a human.