How can i confirm the subscription request HTTP from amazon SNS
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
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.

