codingstuff.io
ExploreTutorialsProblemsCS Subjects
Get Started
ExploreTutorialsProblemsCS Subjects
Get Started
codingstuff.io

Master the art of building software through interactive tutorials, real-world problems, and guided projects.

Pune, Maharashtra, India

codingstuffmail@gmail.com

Product

  • Explore
  • Tutorials
  • Problems
  • CS Subjects

Company

  • About
  • Contact
  • Privacy Policy
  • Terms & Conditions
  • Sitemap

© 2026 codingstuff.io. All rights reserved.

Built with ❤️ for developers everywhere

/
/
All Tutorials
☁️

AWS Cloud

23 / 60 topics
21Introduction to Amazon SNS22Creating an SNS Topic23SNS Subscriptions
Tutorials/AWS Cloud/SNS Subscriptions
☁️AWS Cloud

SNS Subscriptions

Updated 2026-05-15
10 min read

SNS Subscriptions

Introduction

Amazon Simple Notification Service (SNS) is a fully managed messaging service that enables you to send notifications to multiple subscribers. These subscribers can be email addresses, phone numbers, or other endpoints such as Amazon SQS queues and Lambda functions. One of the core concepts in SNS is subscriptions, which define how messages are delivered to these endpoints.

In this tutorial, we will explore what SNS subscriptions are, how they work, and how you can manage them using AWS CLI and SDKs. By the end of this guide, you should have a solid understanding of how to set up and manage subscriptions for your SNS topics.

Concept

An SNS subscription is a relationship between an SNS topic and an endpoint that specifies how messages published to the topic should be delivered. Each subscription has several attributes, including:

  • Topic ARN: The Amazon Resource Name (ARN) of the SNS topic.
  • Protocol: The method used to deliver messages to the endpoint (e.g., HTTP, HTTPS, email, SMS).
  • Endpoint: The destination where messages are sent (e.g., an email address or a URL).
  • Subscription ARN: A unique identifier for the subscription.

Subscriptions can be confirmed by the endpoint. For example, when you create an email subscription, AWS SNS sends a confirmation email to the specified address. The user must open this email and confirm the subscription before messages are delivered.

Examples

Creating a Subscription Using AWS CLI

To create a subscription using the AWS Command Line Interface (CLI), follow these steps:

  1. Create an SNS Topic: If you haven't already, create an SNS topic.

    Terminal
    aws sns create-topic --name MyTopic
    Output
    {
      "TopicArn": "arn:aws:sns:us-east-1:123456789012:MyTopic"
    }
  2. Create a Subscription: Subscribe an endpoint to the topic.

    Terminal
    aws sns subscribe --topic-arn arn:aws:sns:us-east-1:123456789012:MyTopic --protocol email --notification-endpoint example@example.com
    Output
    {
      "SubscriptionArn": "pending confirmation"
    }

    Note that the subscription ARN will be in a "pending confirmation" state until the user confirms the subscription via email.

  3. Confirm the Subscription: Check your inbox and confirm the subscription by clicking the link in the confirmation email.

Managing Subscriptions Using AWS SDK for JavaScript

You can also manage subscriptions using the AWS SDK for JavaScript. Below is an example of how to list all subscriptions for a topic:

JavaScript
1const AWS = require('aws-sdk');
2AWS.config.region = 'us-east-1';
3
4const sns = new AWS.SNS();
5
6const params = {
7 TopicArn: 'arn:aws:sns:us-east-1:123456789012:MyTopic'
8};
9
10sns.listSubscriptionsByTopic(params, (err, data) => {
11 if (err) {
12 console.error('Error listing subscriptions:', err);
13 } else {
14 console.log('Subscriptions:', data.Subscriptions);
15 }
16});

Deleting a Subscription

To delete a subscription, use the unsubscribe API in the AWS CLI or SDK.

JavaScript
1const params = {
2 SubscriptionArn: 'arn:aws:sns:us-east-1:123456789012:MyTopic:subscription-id'
3};
4
5sns.unsubscribe(params, (err, data) => {
6 if (err) {
7 console.error('Error deleting subscription:', err);
8 } else {
9 console.log('Subscription deleted successfully');
10 }
11});

What's Next?

Now that you have a good understanding of SNS subscriptions, the next step is to explore Amazon SQS. SQS is another messaging service that can be used as an endpoint for SNS subscriptions. In the next tutorial, we will dive into how SQS works and how it integrates with SNS.

Stay tuned!


PreviousCreating an SNS TopicNext Introduction to Amazon SQS

Recommended Gear

Creating an SNS TopicIntroduction to Amazon SQS