用途:在 HTTP/HTTPS 端点接收并验证 AWS SNS(Amazon Simple Notification Service)消息,适用于设置 SNS HTTP 订阅端点、确认订阅、校验消息签名,以及处理 Notification 与 UnsubscribeConfirmation 消息。
与 HMAC Webhook 的差异:SNS 不使用共享密钥。它 POST 一个 JSON 信封,Content-Type 为 text/plain,可通过 x-amz-sns-message-type 头判断类型,无需解析正文。真实性通过信封特定字段上的 RSA 签名验证(非原始正文、非 HMAC):从 SigningCertURL 获取 AWS 公开 X.509 证书,对 base64 Signature 做 RSA 验证。新 HTTP 订阅需握手,首条消息为 SubscriptionConfirmation,必须先 GET 其 SubscribeURL(或调用 ConfirmSubscription 传 Token)后 SNS 才会发送通知。
验证方式:Node 可用 AWS 官方 sns-validator,传入解析后的消息对象: const MessageValidator = require('sns-validator'); const validator = new MessageValidator(); validator.validate(message, (err, msg) => { if (err) return res.status(400).send('Invalid signature'); }); Python 无官方 Webhook SDK,需手动按字节序构建规范字符串并用 SigningCertURL 证书做 RSA 验证(SignatureVersion 1 用 SHA1,2 用 SHA256)。
消息类型:SubscriptionConfirmation(需 GET SubscribeURL 确认)、Notification(读取 Subject/Message 处理)、UnsubscribeConfirmation(订阅被删除,验证后可选重新订阅)。业务事件名不存在于 SNS,实际载荷是 Notification 内的 Message 字符串。
环境变量:可设 AWS_SNS_TOPIC_ARN 作为允许列表;无签名密钥,应通过验证 TopicArn 限制信任。
本地开发:npx hookdeck-cli listen 3000 aws-sns --path /webhooks/aws-sns
限制:资料未提供完整价格、平台限制等细节;示例代码与测试见 examples/express、examples/nextjs、examples/fastapi。