Skip to content

SNS

CloudMock emulates Amazon SNS, a pub/sub messaging service, supporting topic management, subscriptions, message publishing with fan-out to SQS subscribers, and tagging.

OperationStatusNotes
CreateTopicSupportedCreates a topic and returns its ARN
DeleteTopicSupportedDeletes a topic and all its subscriptions
ListTopicsSupportedReturns all topic ARNs
GetTopicAttributesSupportedReturns topic attributes
SetTopicAttributesSupportedSets topic attributes
SubscribeSupportedCreates a subscription (SQS, HTTP, email, Lambda)
UnsubscribeSupportedRemoves a subscription
ListSubscriptionsSupportedReturns all subscriptions
ListSubscriptionsByTopicSupportedReturns subscriptions for a specific topic
PublishSupportedPublishes a message; fans out to SQS subscribers
TagResourceSupportedAdds tags to a topic
UntagResourceSupportedRemoves tags from a topic
Terminal window
# Create a topic
curl -X POST "http://localhost:4566/?Action=CreateTopic&Name=notifications"
# Subscribe an SQS queue
curl -X POST "http://localhost:4566/?Action=Subscribe&TopicArn=arn:aws:sns:us-east-1:000000000000:notifications&Protocol=sqs&Endpoint=arn:aws:sqs:us-east-1:000000000000:my-queue"
# Publish a message
curl -X POST "http://localhost:4566/?Action=Publish&TopicArn=arn:aws:sns:us-east-1:000000000000:notifications&Message=Hello"
import { SNSClient, CreateTopicCommand, PublishCommand, SubscribeCommand } from '@aws-sdk/client-sns';
const sns = new SNSClient({
endpoint: 'http://localhost:4566',
region: 'us-east-1',
credentials: { accessKeyId: 'test', secretAccessKey: 'test' },
});
const { TopicArn } = await sns.send(new CreateTopicCommand({ Name: 'alerts' }));
await sns.send(new SubscribeCommand({
TopicArn, Protocol: 'sqs',
Endpoint: 'arn:aws:sqs:us-east-1:000000000000:my-queue',
}));
await sns.send(new PublishCommand({ TopicArn, Message: 'Something happened' }));
import boto3
sns = boto3.client('sns', endpoint_url='http://localhost:4566',
aws_access_key_id='test', aws_secret_access_key='test',
region_name='us-east-1')
topic = sns.create_topic(Name='alerts')
topic_arn = topic['TopicArn']
sns.subscribe(TopicArn=topic_arn, Protocol='sqs',
Endpoint='arn:aws:sqs:us-east-1:000000000000:my-queue')
sns.publish(TopicArn=topic_arn, Message='Something happened', Subject='Alert')
cloudmock.yml
services:
sns:
enabled: true

No additional service-specific configuration is required.

  • Fan-out to SQS is implemented: publishing to a topic delivers the message to all subscribed SQS queues within CloudMock.
  • HTTP/HTTPS and email protocol subscriptions are stored but delivery is not attempted.
  • Lambda subscriptions record the ARN but do not invoke the function.
  • Message filtering by subscription filter policies is not implemented.
  • FIFO topics are not implemented.
  • Platform applications (mobile push) are not implemented.
CodeHTTP StatusDescription
NotFound404The specified topic does not exist
InvalidParameter400An input parameter is invalid
SubscriptionLimitExceeded400Too many subscriptions on this topic
AuthorizationError403Not authorized to perform this action