Creating and Subscribing to AWS SNS Topics

15 minutes
  • 3 Learning Objectives

About this Hands-on Lab

In this live AWS environment, you will be using the AWS Simple Notification Service (SNS). You will use it to create an SNS topic and then subscribe to that topic using multiple endpoints (SMS, Email, and AWS Lambda). This environment will allow you to demonstrate that you can interact effectively with the SNS service by creating SNS topics and adding subscribers to those topics. At the end of this activity, you will have demonstrated you have a basic understanding of the SNS service, the components within it, and how to use the service in the AWS console.

Learning Objectives

Successfully complete this lab by achieving the following learning objectives:

Create an SNS Topic
  1. Click on the Services drop-down menu, search and select SNS.
  2. Type mytopic for * Topic name and select Next step >> Create topic.
  3. Select Subscription >> Create Subscription and set:

    • Topic ARN:Select the only option from drop-down menu
    • Protocol:Email
    • Endpoint:your email address
    • Click Create subscription.

    This may take some time to provision. Look in your Spam email box for a confirmation email and select Confirm subscription.

  4. Create another subscription, this time for SMS. Click subscription >> Create topic and set:
    • Topic ARN:Select the only option from drop-down menu
    • Protocol:SMS
    • Endpoint:your phone number
    • Click Create subscription. Keep this tab open.
Create a Lambda Function
  1. In a new browser tab, click on the Services drop-down menu, search and select Lambda. Keep this browser tab open.

  2. Click Create function >> Author from scratch and set:

    • Function name:SNSProcessor
    • Runtime:Python 3.6
    • Execution role:Use existing role
    • Existing role:LambdaRoleLA
    • Select Create Function.
  3. Navigate back to the SNS browser tab. Click subscription >> Create subscription and set:

    • Topic ARN:Select the only option from drop-down menu
    • Protocol:AWS Lambda
    • Endpoint:Select the only option from drop-down menu
    • Click Create subscription.
  4. Navigate back to the Lambda browser tab and paste the code within GitHub’s notification_processor.py file into the Function code area to overwriting the existing code. (Click on the Python file and click the Raw button to copy its contents.)

  5. After pasting in code, click Deploy.

Send Your SNS Topic to Multiple Endpoints
  1. Navigate back to the SNS browser tab. Select Topics >> select mytopic >> Publish message and set:

    • Subject:An AWS Topic
    • Message body:Hello, this is our first message
  2. Select publish message.

  3. If successful, you’ll receive a text message on your phone and in your email box.

  4. Navigate back to the Lambda browser tab and click on Monitoring >> View logs in CloudWatch. If successful, you will see an entry within the Log streams section.

Additional Resources

Log in to the AWS Management Console using the credentials provided on the lab instructions page. Please ensure you are using the us-east-1 (N. Virginia region) region.

This lesson's GitHub repo.

NOTE: When creating the lambda subscription, you will have to close the permission errors that appear. Afterward, you will be able to continue and finish the lab. Additionally, please delete your email in the SNS section before closing the lab.

What are Hands-on Labs

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Sign In
Welcome Back!

Psst…this one if you’ve been moved to ACG!

Get Started
Who’s going to be learning?