SNS
SNS is a cloud service for the mass delivery of messages.
It is a fully managed publish-subscribe messaging and mobile communication service.
It can be event-driven, with automated services responding to triggers.
AWS SNS can publish messages to many different endpoints (Delivery Formats/Transport protocols):
- HTTP and HTTPS
- Email and Email-JSON
- AWS SQS
- Applications
- AWS Lambda
- SMS (depending on region)
LocalStack Developer Endpoints
-
Create a platform PlatformApplicationArn:
awslocal sns create-platform-application --name app-test --platform APNS --attributes TopicArn=arn:aws:sns:us-east-1:000000000000:localstack-topic
{
"PlatformApplicationArn": "arn:aws:sns:us-east-1:000000000000:app/APNS/app-test"
}
-
Create EndpointArn:
awslocal sns create-platform-endpoint --platform-application-arn "arn:aws:sns:us-east-1:000000000000:app/APNS/app-test" --token my-fake-token
{
"EndpointArn": "arn:aws:sns:us-east-1:000000000000:endpoint/APNS/app-test/023d670d-cc83-45c1-abac-99a708f4f639"
}
-
Publish a message to the platform endpoint:
awslocal sns publish --target-arn "arn:aws:sns:us-east-1:000000000000:endpoint/APNS/app-test/a819d3ac-07bb-46bf-82cf-3dfeccbedcf2" --message '{"APNS_PLATFORM": "{\"aps\": {\"content-available\": 1}}"}' --message-structure json
awslocal sns publish --target-arn "arn:aws:sns:us-east-1:000000000000:endpoint/APNS/app-test/a819d3ac-07bb-46bf-82cf-3dfeccbedcf2" --message "hello"
-
Retrieve the messages published to the platform endpoint:
curl "http://localhost:4566/_aws/sns/platform-endpoint-messages" | jq .
{
"platform_endpoint_messages": {
"arn:aws:sns:us-east-1:000000000000:endpoint/APNS/app-test/a819d3ac-07bb-46bf-82cf-3dfeccbedcf2": [
{
"TargetArn": "arn:aws:sns:us-east-1:000000000000:endpoint/APNS/app-test/a819d3ac-07bb-46bf-82cf-3dfeccbedcf2",
"TopicArn": "",
"Message": "null",
"MessageAttributes": {},
"MessageStructure": "json",
"Subject": null,
"MessageId": "2d66b936-58b7-4676-87d0-474ce7963dbe"
},
{
"TargetArn": "arn:aws:sns:us-east-1:000000000000:endpoint/APNS/app-test/a819d3ac-07bb-46bf-82cf-3dfeccbedcf2",
"TopicArn": "",
"Message": "hello",
"MessageAttributes": {},
"MessageStructure": null,
"Subject": null,
"MessageId": "ad5ce702-7d3f-48dd-b8a4-6aa04eee1846"
}
]
},
"region": "us-east-1"
}
🗃️ Examples
2 items
📄️ References
Publishing messages to Amazon SNS from a Spring Boot application