英文:
localstack sqs subscribe to sns doesn't work
问题
我最近尝试在localstack环境下将sqs订阅到sns。在创建了sns和sqs之后,如果我在AWS CLI或AWS SDK中提供了协议属性,我就无法使用sqs协议进行订阅,如下所示:
使用awslocal:
awslocal sns subscribe \
--notification-endpoint "http://localhost:4566/000000000000/test" \
--topic-arn "arn:aws:sns:us-east-1:000000000000:test" \
使用AWS SDK:
const input: SubscribeCommandInput = {
// SubscribeInput
TopicArn: testTopicArn.TopicArn,
Protocol: 'sqs',
Endpoint: testQueueURL,
ReturnSubscriptionArn: true,
};
无论哪种方式,最终都会出现如下错误:
在调用Subscribe操作时发生错误(InvalidParameter):无效参数:SQS终端ARN
如果我将协议更改为http
,则成功订阅,但问题是在这种类型的订阅后,没有消息进入队列。本地堆栈Docker日志如下:
在发送SNS消息时收到错误,将其放入DLQ(如果已配置):404客户端错误:url:http://localhost:4566/000000000000/test
英文:
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
答案1
得分: 0
SNS主题的SQS队列目标的正确终点是队列ARN,而不是其URL。请参阅此处的文档:
https://docs.aws.amazon.com/sns/latest/api/API_Subscribe.html
对于sqs协议,终点是Amazon SQS队列的ARN。
在订阅主题之前,您需要获取SQS队列的ARN,例如:
awslocal sqs get-queue-attributes --queue-url http://{queueURL} --attribute-names QueueArn
然后,您可以将此ARN传递给Endpoint
参数以订阅主题。
英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论