Back

Amazon SNS API Essential Guide

Aug 7, 20246 minute read

What type of API does Amazon SNS provide?

Amazon SNS primarily uses a REST-like API. Here are the key points about Amazon SNS's API type:

  1. REST-like API: Amazon SNS provides a REST-like HTTP/HTTPS API that allows you to interact with the service using standard HTTP methods and URLs.

  2. Query API: While not strictly RESTful, Amazon SNS uses a query-based API where you send HTTP/HTTPS requests to pre-defined endpoints with specific actions and parameters.

  3. HTTP/HTTPS protocol: The API uses HTTP or HTTPS as the protocol for sending requests and receiving responses.

  4. No SOAP support: Amazon SNS does not offer a SOAP API.

  5. No native GraphQL support: While AWS AppSync supports GraphQL APIs, Amazon SNS itself does not have native GraphQL support.

  6. SDKs available: AWS provides SDKs for various programming languages that abstract the low-level API calls, making it easier to interact with Amazon SNS.

  7. Direct HTTP requests: You can make direct HTTP requests to the Amazon SNS API without using SDKs, by properly formatting the request URL, headers, and body.

Here's an example of how you might make a direct HTTP request to publish a message to an SNS topic:

https://sns.us-east-2.amazonaws.com/?Action=Publish
&TopicArn=arn%3Aaws%3Asns%3Aus-east-2%3A698519295917%3AMy-Topic
&Subject=My%20first%20message
&Message=Hello%20world%21 
&Version=2010-03-31
&AUTHPARAMS

In this example, you would need to replace AUTHPARAMS with the appropriate authentication parameters using AWS Signature Version 4 signing process.

Does the Amazon SNS API have webhooks?

Direct Webhook Support

Amazon SNS does not have direct native support for webhooks in its API. However, it can be used to deliver events to external webhooks through some additional configuration:

  1. SNS can deliver events to HTTP/HTTPS endpoints, which can be used as webhooks.

  2. You can subscribe an HTTP/HTTPS endpoint to an SNS topic to receive notifications.

Event Types and Destinations

While SNS doesn't have native webhook events, it can be used to deliver various types of events:

  1. Native AWS events from services like AWS Billing, AWS Health, CloudFormation, CloudWatch, etc. can be sent through SNS topics to chat apps like Amazon Chime and Slack using AWS Chatbot.

  2. Custom events can be published to SNS topics and delivered to destinations like Amazon Chime, Slack, and Microsoft Teams.

  3. SNS can deliver events to various application-to-application (A2A) destinations including:

    • Amazon Kinesis Data Firehose
    • AWS Lambda
    • Amazon SQS
    • AWS Event Fork Pipelines
    • HTTP/HTTPS endpoints

Implementing Webhooks with SNS

To implement webhook-like functionality with SNS:

  1. Create an SNS topic for your events.

  2. Use a Lambda function to transform the SNS message format into the expected webhook payload format for your destination (e.g., Slack, Microsoft Teams).

  3. Subscribe your Lambda function to the SNS topic.

  4. Configure the Lambda function to send the transformed payload to your webhook endpoint.

Best Practices

When implementing webhook-like functionality with SNS:

  1. Consider payload size, keeping it minimal for fast and reliable delivery.

  2. Implement security and authorization for secure event delivery.

  3. Manage subscriptions to allow consumers to specify endpoints and event types.

  4. Consider costs and implement usage policies and quotas.

  5. Monitor and troubleshoot your webhook delivery system.

In summary, while Amazon SNS doesn't have native webhook support in its API, it can be used in combination with other AWS services like Lambda to implement webhook-like functionality for delivering events to external systems.

Rate Limits and other limitations

Here are the key points about the API rate limits for Amazon SNS:

General Rate Limits

  • Amazon SNS does not enforce a strict rate limit for Publish calls [3].

  • However, SNS may occasionally throttle requests, responding with HTTP 400 and an AWS SNS request ID [3].

  • The default rate limits vary by AWS region and can range from 30,000 transactions/second to 300 transactions/second, depending on whether it's a standard or FIFO topic [3].

Soft Limits

  • There are soft limits that vary by AWS region [1].

  • The messages per second quota is based on the total number of messages published to an Amazon SNS region, combining Publish and PublishBatch API requests [1].

  • For example, if the regional quota is 30,000 messages per second, this can be reached by:

    • Using Publish at 30,000 API requests/second (1 message per request)
    • Using PublishBatch at 3,000 API requests/second (10 messages per batch)
    • A combination of Publish and PublishBatch totaling 30,000 messages/second

Resource Limits

  • Topics: 100,000 per account for standard, 1,000 per account for FIFO [1]
  • Subscriptions: 12,500,000 per topic for standard, 100 per topic for FIFO [1]
  • Pending subscriptions: 5,000 per account [1]
  • Maximum number of messages in PublishBatchRequest: 10 PublishBatchRequestEntries [1]

Message Size Limits

  • Maximum message header size: 16,384 bytes (16 KiB) [1]
  • Maximum message size: 262,144 bytes (256 KiB) [1]
  • For SMS, each message can contain up to 140 characters, depending on the encoding schema [2]

Best Practices

  1. Monitor API activity against your rate limit [5].
  2. Catch errors caused by rate limiting (e.g., 429 Too Many Requests responses) [5].
  3. Reduce the number of API requests by optimizing code and caching frequently used data [5].
  4. Implement a rate limiter in your code to manage high volumes of traffic [5].
  5. Consider using batch operations where possible [5].

Increasing Limits

  • To request an increase in soft limits, you can submit an SNS quota increase request [1].
  • For account-level throttling limits per region, you can contact AWS Support Center [4].

Remember that while these limits exist, Amazon SNS is designed to handle high throughput, and the actual limits may be adjusted based on your specific use case and needs.

Latest API Version

Based on the search results provided, I can answer your question about the most recent version of the Amazon SNS API. Here's the information:

API Version

The most recent version of the Amazon SNS API is 2010-03-31 [5].

Key Points to Consider

  1. This version number is consistently used in the API request examples provided in the documentation [5].

  2. Despite the version number being from 2010, Amazon SNS regularly updates its features and capabilities without changing the API version number [2].

  3. The documentation history shows that Amazon SNS frequently adds new features and support for various services, even though the API version remains the same [2].

Recent Updates and Features

Although the API version hasn't changed, Amazon SNS has introduced several new features and improvements recently:

  1. Support for FIFO topics in Canada West (Calgary) region (March 28, 2024) [2].

  2. SMS support added to new regions including Asia Pacific (Hyderabad), Asia Pacific (Melbourne), Middle East (UAE), Europe (Zurich), and Europe (Spain) (February 8, 2024) [2].

  3. Support for Firebase Cloud Messaging (FCM) HTTP v1 credentials (January 18, 2024) [2].

  4. New message filtering operators added, including suffix matching, equals-ignore case, and OR operators (November 16, 2023) [2].

  5. Support for message archiving and replay (October 26, 2023) [2].

Best Practices

  1. Always refer to the latest Amazon SNS documentation for the most up-to-date information on features and capabilities.

  2. When making API requests, use the version number 2010-03-31 in your requests to ensure compatibility [5].

  3. Stay informed about new features and updates by following the Amazon SNS release notes, which are available as an RSS feed [2].

In conclusion, while the API version number remains 2010-03-31, Amazon SNS continues to evolve and add new features regularly. It's important to stay updated with the latest documentation and release notes to take advantage of new capabilities.

How to get a Amazon SNS developer account and API Keys?

To get a developer account for Amazon SNS to create an API integration, you need to follow these steps:

Create an AWS Account

  1. If you don't already have an AWS account, you'll need to create one. This is the first step to accessing any AWS service, including Amazon SNS.

  2. Go to the AWS Management Console (https://console.aws.amazon.com/) and sign up for an account if you don't have one.

Set Up IAM Permissions

  1. Once you have an AWS account, you need to set up the appropriate IAM (Identity and Access Management) permissions to use Amazon SNS.

  2. Create an IAM role with the necessary permissions for Amazon SNS. For this tutorial, you can use the AmazonSNSReadOnlyAccess managed policy, but in practice, you should create a custom policy with only the required permissions.

  3. To create the IAM role:

    • Open the IAM console (https://console.aws.amazon.com/iam/)
    • Choose "Roles" and then "Create role"
    • Select "AWS service" as the trusted entity and choose "API Gateway"
    • Attach the AmazonSNSReadOnlyAccess policy (or your custom policy)
    • Name the role (e.g., "APIGatewaySNSProxyPolicy") and create it

Set Up Amazon SNS

  1. Create at least one topic in Amazon SNS. You can do this through the Amazon SNS console or using the AWS CLI.

Create an API in API Gateway

  1. Open the API Gateway console (https://console.aws.amazon.com/apigateway/)

  2. Create a new API or use an existing one.

  3. Create a new resource and method for your SNS integration.

  4. Set up the integration:

    • Choose "AWS Service" as the integration type
    • Select the region where your SNS topics are located
    • Choose "Simple Notification Service (SNS)" as the AWS Service
    • Select the appropriate HTTP method (e.g., GET to list topics)
    • Set the execution role to the ARN of the IAM role you created earlier
  5. Deploy your API to a stage.

Test Your Integration

  1. After deploying your API, you'll get an invoke URL. Use this URL to test your integration.

  2. You should be able to interact with Amazon SNS through your API Gateway endpoint.

What can you do with the Amazon SNS API?

Based on the provided search results, here's a list of data models you can interact with using the Amazon SNS API, along with what is possible for each:

Topics

  • Create standard and FIFO (First-In-First-Out) topics
  • Set policies for topics, such as limiting who can publish messages or subscribe to notifications
  • Specify supported notification protocols (e.g., HTTP/HTTPS, email, SMS)
  • Publish messages to topics
  • Subscribe to topics or manage subscriptions
  • Archive messages within topics (for FIFO topics)

Messages

  • Publish messages to topics
  • Set message attributes (arbitrary metadata about the message)
  • Apply server-side encryption to protect message contents
  • Archive and replay messages (for FIFO topics)
  • Filter messages based on attributes or payload

Subscriptions

  • Create and manage subscriptions to topics
  • Specify protocol and endpoint (URL, email address, etc.) for notifications
  • Assign filter policies to subscriptions
  • Set up dead-letter queues for undelivered messages

Delivery Protocols

  • Manage various delivery protocols, including:
    • HTTP/HTTPS endpoints
    • Email
    • SMS
    • Amazon SQS queues
    • AWS Lambda functions
    • Amazon Kinesis Data Firehose delivery streams
    • Mobile push notifications

Integration with Other AWS Services

  • Set up notifications and alarms for various AWS services, including:
    • Analytics services (e.g., Amazon Athena, AWS Data Pipeline)
    • Database services (e.g., Amazon DynamoDB, Amazon RDS)
    • Machine learning services (e.g., Amazon SageMaker, Amazon Rekognition)
    • Networking and content delivery services (e.g., Amazon API Gateway, Amazon CloudFront)
    • Serverless services (e.g., AWS Lambda, Amazon EventBridge)

Message Security and Networking

  • Manage server-side encryption for messages
  • Set up private connections between Amazon SNS and VPCs