Notification Service Amazon Simple - AWS Documentation

Amazon Simple Notification Service

Developer Guide

Amazon Simple Notification Service Developer Guide

Amazon Simple Notification Service: Developer Guide

Copyright ? 2020 Amazon Web Services, Inc. and/or its affiliates. All rights reserved. Amazon's trademarks and trade dress may not be used in connection with any product or service that is not Amazon's, in any manner that is likely to cause confusion among customers, or in any manner that disparages or discredits Amazon. All other trademarks not owned by Amazon are the property of their respective owners, who may or may not be affiliated with, connected to, or sponsored by Amazon.

Amazon Simple Notification Service Developer Guide

Table of Contents

What is Amazon SNS? ........................................................................................................................ 1 Setting Up Access .............................................................................................................................. 2

Step 1: Create an AWS Account and an IAM Administrator User ........................................................ 2 Step 2: Create an IAM User and Get Your AWS Credentials .............................................................. 2 Next Steps ................................................................................................................................ 3 Getting Started .................................................................................................................................. 4 Prerequisites .............................................................................................................................. 4 Step 1: Create a Topic ................................................................................................................ 4 Step 2: Create a Subscription for an Endpoint to the Topic .............................................................. 4 Step 3: Publish a Message to the Topic ......................................................................................... 5 Step 4: Delete the Subscription and Topic ..................................................................................... 6 Next Steps ................................................................................................................................ 7 Tutorials ............................................................................................................................................ 8 Basic Workflows ......................................................................................................................... 8

Creating a Topic ................................................................................................................. 8 Subscribing an Endpoint to a Topic .................................................................................... 11 Publishing a Message to a Topic ......................................................................................... 13 Listing, Adding, and Removing Tags for a Topic .................................................................... 16 Configuring a Dead-Letter Queue ....................................................................................... 17 Deleting a Subscription and Topic ...................................................................................... 20 Publishing Workflows ............................................................................................................... 22 Publishing a Message with Attributes .................................................................................. 22 Working with Amazon SNS Securely ........................................................................................... 27 Enabling SSE for a Topic ................................................................................................... 27 Enabling SSE for a Topic with an Encrypted Queue Subscribed ............................................... 30 Tutorial: Publishing Messages Privately from a VPC .............................................................. 32 Working with AWS Event Fork Pipelines ...................................................................................... 41 Deploying and Testing AWS Event Fork Pipelines .................................................................. 41 Subscribing AWS Event Fork Pipelines to a Topic .................................................................. 48 How Amazon SNS Works ................................................................................................................... 54 Common Scenarios ................................................................................................................... 54 Fanout ............................................................................................................................ 54 Application and System Alerts ........................................................................................... 55 Push Email and Text Messaging ......................................................................................... 55 Mobile Push Notifications .................................................................................................. 55 Message Durability ........................................................................................................... 55 Message Delivery Status ............................................................................................................ 55 Configuring Delivery Status Logging Using the AWS Management Console ............................... 56 Configuring Message Delivery Status Attributes for Topics Subscribed to Amazon SNS Endpoints Using the AWS SDKs .......................................................................................... 56 Message Delivery Retries ........................................................................................................... 58 Delivery Protocols and Policies ........................................................................................... 58 Delivery Policy Stages ....................................................................................................... 59 Creating a Delivery Policy .................................................................................................. 60 Dead-Letter Queues .................................................................................................................. 62 Why Do Message Deliveries Fail? ........................................................................................ 62 How Do Dead-Letter Queues Work? .................................................................................... 63 How Are Messages Moved into a Dead-Letter Queue? ........................................................... 63 How Can I Move Messages out of a Dead-Letter Queue? ........................................................ 64 How Can I Monitor and Log Dead-Letter Queues? ................................................................. 64 Message Attributes ................................................................................................................... 64 Message Attribute Items and Validation .............................................................................. 65 Data Types ...................................................................................................................... 65 Reserved Message Attributes for Mobile Push Notifications .................................................... 65

iii

Amazon Simple Notification Service Developer Guide

Message Filtering ..................................................................................................................... 67 Subscription Filter Policies ................................................................................................. 67 Tutorial: Applying a Subscription Filter Policy ....................................................................... 73 Tutorial: Removing a Subscription Filter Policy ..................................................................... 76 Subscription Filter Policies as Java Collections ...................................................................... 77

Message and JSON Formats ....................................................................................................... 80 HTTP/HTTPS Headers ....................................................................................................... 81 HTTP/HTTPS Subscription Confirmation JSON Format .......................................................... 81 HTTP/HTTPS Notification JSON Format .............................................................................. 83 HTTP/HTTPS Unsubscribe Confirmation JSON Format ........................................................... 84 SetSubscriptionAttributes Delivery Policy JSON Format ......................................................... 85 SetTopicAttributes Delivery Policy JSON Format ................................................................... 86

Large Payload and Raw Message Delivery .................................................................................... 87 Enabling Raw Message Delivery Using the AWS Management Console ..................................... 87

Tags ........................................................................................................................................ 87 System-to-System Messaging ............................................................................................................. 89

With AWS Lambda Function as Subscriber ................................................................................... 89 Prerequisites .................................................................................................................... 89 Configuring Amazon SNS with Lambda Endpoints using the AWS Management Console ............. 89

With Amazon SQS Queue as Subscriber ...................................................................................... 90 Step 1: Get the ARN of the Queue and Topic ....................................................................... 91 Step 2: Give Permission to the Amazon SNS Topic to Send Messages to the Amazon SQS Queue .. 91 Step 3: Subscribe the Queue to the Amazon SNS Topic ......................................................... 92 Step 4: Give Users Permissions to the Appropriate Topic and Queue Actions ............................. 93 Step 5: Test the Topic's Queue Subscriptions ....................................................................... 95 Sending Messages to a Queue in a Different Account ............................................................ 95 Using an AWS CloudFormation Template to Create a Topic that Sends Messages to Amazon SQS Queues .................................................................................................................... 98

With HTTP/S Endpoint as Subscriber ........................................................................................ 103 Step 1: Make Sure Your Endpoint is Ready to Process Amazon SNS Messages .......................... 104 Step 2: Subscribe the HTTP/HTTPS Endpoint to the Amazon SNS Topic ................................. 107 Step 3: Confirm the subscription ...................................................................................... 107 Step 4: Set the delivery retry policy for the subscription (optional) ........................................ 107 Step 5: Give users permissions to publish to the topic (optional) ........................................... 108 Step 6: Send messages to the HTTP/HTTPS endpoint .......................................................... 109 Verifying Message Signatures ........................................................................................... 109 Example Code for an Endpoint Java Servlet ....................................................................... 111

With AWS Event Fork Pipelines as Subscriber ............................................................................. 114 How AWS Event Fork Pipelines Works ............................................................................... 115 Deploying AWS Event Fork Pipelines ................................................................................. 117

User Notifications ........................................................................................................................... 119 With Mobile Application as Subscriber (Mobile Push) ................................................................... 119 How User Notifications Work ........................................................................................... 120 Prerequisites for Amazon SNS User Notifications ................................................................ 120 User Notification Process Overview ................................................................................... 121 Using Amazon SNS Mobile Push ....................................................................................... 121 Application Attributes for Message Delivery Status ............................................................. 133 Application Event Notifications ......................................................................................... 136 Amazon SNS TTL ............................................................................................................ 138 Amazon SNS Mobile Push APIs ......................................................................................... 140 API Errors ...................................................................................................................... 142 With Mobile Phone Number as Subscriber (Send SMS) ................................................................. 148 Setting Preferences ......................................................................................................... 148 Sending a Message ......................................................................................................... 151 Sending a Message to Multiple Phone Numbers ................................................................. 155 Monitoring SMS Activity .................................................................................................. 161 Managing Subscriptions ................................................................................................... 166

iv

Amazon Simple Notification Service Developer Guide

Reserving a Short Code ................................................................................................... 170 Supported Regions and Countries ..................................................................................... 171 Troubleshooting ............................................................................................................................. 179 Troubleshooting Topics Using X-Ray .......................................................................................... 179 Security ......................................................................................................................................... 180 Data Protection ...................................................................................................................... 180 Data Encryption ............................................................................................................. 180 Internetwork Traffic Privacy ............................................................................................. 185 Identity and Access Management .............................................................................................. 188 Authentication ............................................................................................................... 188 Access Control ................................................................................................................ 189 Overview ....................................................................................................................... 189 Using Identity-Based Policies ........................................................................................... 202 Using Temporary Credentials ........................................................................................... 208 API Permissions Reference ............................................................................................... 208 Logging and Monitoring .......................................................................................................... 209 Logging API Calls Using CloudTrail ................................................................................... 210 Monitoring Topics Using CloudWatch ................................................................................ 213 Compliance Validation ............................................................................................................. 216 Resilience .............................................................................................................................. 217 Infrastructure Security ............................................................................................................. 217 Best Practices ......................................................................................................................... 218 Preventative Best Practices .............................................................................................. 218 Release Notes ................................................................................................................................ 220 Document History .................................................................................................................. 223 AWS Glossary ................................................................................................................................. 234

v

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download