How can i confirm the subscription request HTTP from amazon SNS
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Introduction
When you subscribe an HTTP or HTTPS endpoint to an Amazon SNS topic, SNS does not start delivering normal notifications immediately. It first sends a SubscriptionConfirmation message, and your endpoint must confirm that request before the subscription becomes active.
What SNS Sends to Your Endpoint
SNS makes an HTTP POST request to the subscribed endpoint. The body is JSON and includes fields such as:
- '
Type, which isSubscriptionConfirmation' - '
MessageId' - '
Token' - '
TopicArn' - '
SubscribeURL' - '
Signatureand certificate metadata used for verification'
You can also inspect the x-amz-sns-message-type header to identify the request quickly before parsing the body.
Until the confirmation succeeds, the subscription stays in a pending state and normal notifications are not delivered. That is why testing the confirmation path is part of the setup, not an optional follow-up task.
Confirming the Subscription
There are two common ways to confirm:
- Perform an HTTP
GETrequest to theSubscribeURL - Call the SNS
ConfirmSubscriptionAPI with theTopicArnandToken
The SubscribeURL route is simple, but the API route is often easier to keep inside your application code and logs.
Here is a minimal Flask example using boto3:
This keeps the logic explicit and works well in server-side code where you already have AWS credentials configured.
Verify the Request Before Confirming
Do not blindly confirm every request that looks like SNS. A production endpoint should validate that the message really came from Amazon SNS. The key checks are:
- Confirm the signing certificate URL is from an AWS domain you trust
- Validate the SNS signature against the signed fields
- Confirm the
TopicArnmatches the topic you expect
If you skip verification, an attacker could send a fake confirmation message to your endpoint and trick your system into accepting or processing untrusted data.
Handling the Confirmation by SubscribeURL
If you prefer the URL-based flow, the code is straightforward:
This works, but it pushes the confirmation logic into a network call to a URL from the payload. Many teams prefer the SDK call because it is easier to audit and easier to stub in tests.
Common Pitfalls
- Treating every SNS request as a normal notification means the subscription never leaves the pending state.
- Confirming the request without signature validation weakens the security of the endpoint.
- Forgetting to return a successful HTTP response can cause SNS retries even after your application has already processed the confirmation.
- Not checking
TopicArncan lead one endpoint to confirm requests for the wrong topic.
Logging the message type and topic during setup also makes future troubleshooting much easier.
Summary
- SNS confirms HTTP subscriptions by sending a
SubscriptionConfirmationmessage to your endpoint. - You can confirm with the provided
SubscribeURLor with theConfirmSubscriptionAPI. - In production, validate the signature and expected topic before confirming.
- Once confirmation succeeds, SNS starts sending normal notification payloads to the endpoint.
Related reading
- How can I control user access to Amazon DynamoDB data via IAM?
- How can I create a DependsOn relation between EC2 and RDS using aws-cdk
- How can I create a one time download link with Amazon S3?
- How can I create a Route 53 Record to an ALB? AWS
- How can I connect to Android with ADB over TCP?
- How can I connect to Android with ADB over TCP?
- How can I create an image from a container running in Kubernetes?
- How can I deduce the AWS Account ID from available BasicAWSCredentials?

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.