AWS SNS
qhook can receive events from AWS SNS topics. It handles the full lifecycle automatically.
How It Works
- Subscription confirmation – when SNS sends a
SubscriptionConfirmationmessage, qhook automatically confirms by fetching theSubscribeURL. - Message unwrapping – SNS wraps your payload in an envelope. qhook extracts the
Messagefield and delivers only the actual payload to your handlers. - Signature verification – each SNS message is verified using the X.509 certificate from AWS (SHA1/SHA256). Certificates are cached for 1 hour.
Setup
sources:
my-sns:
type: sns
Point your SNS subscription to:
https://your-qhook-host/sns/my-sns
The event type is extracted from:
- The message payload
typefield - The
detail-typefield (for EventBridge events via SNS) - The SNS
Subjectfield
Handler Example
sources:
my-sns:
type: sns
handlers:
process-notification:
source: my-sns
events: [order.created]
url: http://backend:3000/jobs/sns-order
Testing with LocalStack
For local development, use skip_verify: true to bypass X.509 signature verification:
sources:
my-sns:
type: sns
skip_verify: true # LocalStack does not sign messages
Run LocalStack:
docker run -d --name localstack -p 4566:4566 -e SERVICES=sns localstack/localstack:3
Create a topic and subscription:
aws --endpoint-url=http://localhost:4566 sns create-topic --name my-topic
aws --endpoint-url=http://localhost:4566 sns subscribe \
--topic-arn arn:aws:sns:us-east-1:000000000000:my-topic \
--protocol http \
--notification-endpoint http://host.docker.internal:8888/sns/my-sns
Publish a test message:
aws --endpoint-url=http://localhost:4566 sns publish \
--topic-arn arn:aws:sns:us-east-1:000000000000:my-topic \
--message '{"type":"order.created","id":"ord_123","amount":4999}'
Security
- SubscribeURL validation: qhook validates that the
SubscribeURLpoints to a legitimate SNS domain before fetching, preventing SSRF attacks. - Certificate caching: Signing certificates are cached for 1 hour to prevent DoS via repeated certificate fetches.
- Certificate URL validation: Only certificates hosted on
sns.*.amazonaws.comdomains are accepted.