AWS SNS Message Validator
raw JSON → 0.0.5 verified Fri May 01 auth: no python
A Python library for validating AWS SNS messages, including signature verification using AWS's public certificates. Version 0.0.5, last updated in 2020. Low release cadence.
pip install aws-sns-message-validator Common errors
error TypeError: the JSON object must be str, bytes or bytearray, not 'dict' ↓
cause Passing a dict directly to validate_message instead of a JSON string.
fix
Use json.dumps(message) before calling validator.validate_message().
error AttributeError: module 'aws_sns_message_validator' has no attribute 'SNSMessageValidator' ↓
cause Incorrect import path (e.g., from aws_sns_message_validator import SNSMessageValidator not just import aws_sns_message_validator).
fix
Use: from aws_sns_message_validator import SNSMessageValidator
error requests.exceptions.ConnectionError: HTTPSConnectionPool(host='sns.us-east-1.amazonaws.com', port=443): Max retries exceeded ↓
cause The certificate URL is unreachable, possibly because of network restrictions or a non-AWS URL.
fix
Ensure SigningCertURL is a valid HTTPS URL to an AWS SNS endpoint. Add proxies or override network settings if behind a firewall.
Warnings
gotcha The validate_message method expects a JSON string, not a dict. Passing a dict will cause a TypeError. ↓
fix Always json.dumps() your dict before calling validate_message.
gotcha Certificate URL must be HTTPS and point to a valid AWS certificate. The library does not validate the URL beyond downloading it. ↓
fix Ensure the SigningCertURL is always an AWS https URL (e.g., https://sns.us-east-1.amazonaws.com/...).
deprecated The library uses md5 which is deprecated; some Python environments may raise warnings. ↓
fix Ignore warnings or use a different library like 'aws-encryption-sdk' for strict compliance.
Imports
- SNSMessageValidator
from aws_sns_message_validator import SNSMessageValidator
Quickstart
import json
from aws_sns_message_validator import SNSMessageValidator
validator = SNSMessageValidator()
message = {
'Type': 'Notification',
'MessageId': '...',
'TopicArn': '...',
'Subject': '...',
'Message': '...',
'Timestamp': '...',
'SignatureVersion': '1',
'Signature': '...',
'SigningCertURL': '...',
'UnsubscribeURL': '...'
}
result = validator.validate_message(json.dumps(message))
print(result)