AWS SNS Webhooks: Stop fighting text/plain and use application/json instead
If you’ve ever worked with Amazon SNS and subscribed an HTTP/HTTPS endpoint, you’ve probably hit this gotcha:
SNS sends you a JSON payload… but sets the
Content-Type
header totext/plain
.
🤨 Why Is That a Problem?
When SNS sends messages like SubscriptionConfirmation
or Notification
, the body is valid JSON. But since the header says text/plain
, most web frameworks (like Rails, Django, Express, etc.) don’t parse it into params
or req.body
.
So instead of:
params["SubscribeURL"]
You’re stuck doing:
body = request.body.read
json = JSON.parse(body)
json["SubscribeURL"]
📦 Example SNS Payload
POST /webhook HTTP/1.1
Content-Type: text/plain; charset=UTF-8
{
"Type": "SubscriptionConfirmation",
"SubscribeURL": "https://sns.us-east-1.amazonaws.com/..."
}
✅ The Fix: Use application/json
for SNS Webhooks
Since 2023, AWS finally allows you to change the content type for SNS HTTP(S) subscriptions to application/json
🎉
According to the official AWS documentation:
“You can configure Amazon SNS to send POST messages with a content type of either
application/json
ortext/plain
.”
🔧 How to Enable It (via AWS Console)
- Go to your SNS Topic in the AWS Console
- Click on the Subscriptions tab
- Find your HTTPS endpoint and click Edit
- Under Delivery Policy (HTTP/S), set “Content-Type” to
application/json
- Save your changes
Going forward, SNS will now send webhooks with:
Content-Type: application/json
🚀 Conclusion
Amazon SNS has historically defaulted to text/plain
, which made JSON payloads a pain to work with. But now, thanks to a long-awaited update, you can make it send real application/json
— and your webhooks will just work™️.
If you’re building an SNS webhook, switch the content-type early, save yourself the parsing trouble, and get clean params from day one.
References
- 📘 Creating a HTTP/S Delivery Policy (AWS Docs)
- 🧾 Amazon SNS announces support for setting content-type (AWS)
🔒 Want Better Webhook Dev Tools?
If you’re tired of debugging webhook payloads like SNS manually, you’re going to love what we’re building.
Relaye.io is a modern webhook gateway and debugger built for developers — with features like:
- 💡 Real-time payload inspection
- 🔁 Replay failed requests
- 🔒 Secure endpoints for dev and prod
- 🌍 Support for AWS SNS, Stripe, GitHub, and more
We’re currently in private beta — and we’d love your feedback.
👉 Join the waitlist at relaye.io to get early access!