I've recently tried to subscribe an sqs to sns on the localstack environment. after creating sns and sqs I can not subscribe using sqs protocol if I provide the protocol attribute either on AWS CLI or AWS SDK like below:
using awslocal:
awslocal sns subscribe \
--notification-endpoint "http://localhost:4566/000000000000/test" \
--topic-arn "arn:aws:sns:us-east-1:000000000000:test" \
using AWS SDK:
const input: SubscribeCommandInput = {
// SubscribeInput
TopicArn: testTopicArn.TopicArn,
Protocol: 'sqs',
Endpoint: testQueueURL,
ReturnSubscriptionArn: true,
};
either way, I will end up with an error like the one below:
n error occurred (InvalidParameter) when calling the Subscribe operation: Invalid parameter: SQS endpoint ARN
if I change the protocol to http
it gets subscribed successfully, but the problem is that no messages end up in the queue after this type of subscription.
the local stack docker log is as follows:
Received error on sending SNS message, putting to DLQ (if configured): 404 Client Error: for url: http://localhost:4566/000000000000/test
The proper endpoint for an SQS queue destination of an SNS topic is the Queue ARN, not its URL. See the documentation here: https://docs.aws.amazon.com/sns/latest/api/API_Subscribe.html
For the sqs protocol, the endpoint is the ARN of an Amazon SQS queue.
You'll need to get the SQS Queue ARN before subscribing to the topic, with for example:
awslocal sqs get-queue-attributes --queue-url http://{queueURL} --attribute-names QueueArn
You can then pass this ARN to the Endpoint
parameter to subscribe to the Topic.