Swiftorial Logo
Home
Swift Lessons
AI Tools
Learn More
Career
Resources

AWS SNS Basics

What is Amazon SNS?

Amazon Simple Notification Service (SNS) is a fully managed messaging service for both application-to-application (A2A) and application-to-person (A2P) communication. It allows you to send messages to a large number of subscribers or endpoints.

Key SNS Concepts

  • Topic: A logical access point and communication channel. Publishers send messages to a topic, and subscribers receive those messages.
  • Subscription: Represents the endpoint that receives messages published to a topic. Endpoints can be email, SMS, AWS Lambda functions, SQS queues, or HTTP/S endpoints.
  • Publisher: An entity that sends messages to a topic.
  • Subscriber: An entity that receives messages from a topic.
  • Message: The data sent by a publisher to a topic, which is then delivered to all subscribers.

Creating an SNS Topic

To create an SNS topic:

  1. Sign in to the AWS Management Console.
  2. Navigate to the Amazon SNS Dashboard.
  3. Click "Create topic".
  4. Choose the topic type (Standard or FIFO). For this example, select "Standard".
  5. Enter a name for your topic (e.g., "MySNSTopic").
  6. Click "Create topic".

Example: Creating a Standard SNS Topic

Let's create a standard SNS topic:

Step-by-Step Example:

  1. Sign in to the AWS Management Console.
  2. Navigate to the Amazon SNS Dashboard and click "Create topic".
  3. Choose "Standard" as the topic type.
  4. Enter a name for your topic (e.g., "MyStandardTopic").
  5. Click "Create topic".

Subscribing to an SNS Topic

To subscribe to an SNS topic:

  1. Sign in to the AWS Management Console.
  2. Navigate to the Amazon SNS Dashboard.
  3. Click on the topic you created (e.g., "MySNSTopic").
  4. Click "Create subscription".
  5. Select the protocol (e.g., Email, SMS, Lambda, SQS, HTTP/S) and enter the endpoint (e.g., an email address or phone number).
  6. Click "Create subscription".
  7. For some protocols (e.g., Email), you may need to confirm the subscription by following a link sent to the endpoint.

Example: Subscribing an Email Endpoint to an SNS Topic

Let's subscribe an email endpoint to the "MyStandardTopic" SNS topic:

Step-by-Step Example:

  1. Sign in to the AWS Management Console.
  2. Navigate to the Amazon SNS Dashboard and click on the topic you created (e.g., "MyStandardTopic").
  3. Click "Create subscription".
  4. Select "Email" as the protocol and enter your email address as the endpoint.
  5. Click "Create subscription".
  6. Check your email for a confirmation message from AWS. Click the confirmation link to confirm the subscription.

Publishing a Message to an SNS Topic

To publish a message to an SNS topic:

  1. Sign in to the AWS Management Console.
  2. Navigate to the Amazon SNS Dashboard.
  3. Click on the topic you created (e.g., "MySNSTopic").
  4. Click "Publish message".
  5. Enter the message subject and message body.
  6. Click "Publish message".

Example: Publishing a Message to an SNS Topic

Let's publish a message to the "MyStandardTopic" SNS topic:

Step-by-Step Example:

  1. Sign in to the AWS Management Console.
  2. Navigate to the Amazon SNS Dashboard and click on the topic you created (e.g., "MyStandardTopic").
  3. Click "Publish message".
  4. Enter a subject (e.g., "Test Message") and a message body (e.g., "This is a test message.").
  5. Click "Publish message".

Managing SNS Topics and Subscriptions

You can manage your SNS topics and subscriptions using the AWS Management Console, AWS CLI, or SDKs:

  • View Topics: List and view details of your SNS topics.
  • View Subscriptions: List and view details of your topic subscriptions.
  • Delete Topics: Remove SNS topics that are no longer needed.
  • Unsubscribe: Remove subscriptions from a topic.

Example: Viewing SNS Topic Subscriptions

Let's view the subscriptions for the "MyStandardTopic" SNS topic:

Step-by-Step Example:

  1. Sign in to the AWS Management Console.
  2. Navigate to the Amazon SNS Dashboard and click on the topic you created (e.g., "MyStandardTopic").
  3. Click on the "Subscriptions" tab to view the list of subscriptions for the topic.
  4. View the details of each subscription, including the protocol, endpoint, and subscription ARN.

Conclusion

Amazon SNS provides a flexible and scalable messaging service that allows you to send messages to a large number of subscribers or endpoints. By understanding the basics of SNS, including how to create topics, subscribe endpoints, and publish messages, you can effectively use SNS to manage communication between your applications and services.