Lambda无法将消息发送到SQS [英] Lambda can't send message to SQS
问题描述
我无法从Lambda向SQS队列发送消息 功能.这是我的设置
I'm having trouble sending a message to my SQS queue from my lambda function. Here's my setup
- Lambda已连接到默认VPC中的3个公共子网
- 存在用于SQS的VPC端点
我正在尝试使用以下命令通过boto3发送消息:
I'm trying to send a message via boto3 using the following:
import json
import boto3
sqs = boto3.client("sqs")
sqs.send_message(
QueueUrl="https://sqs.eu-west-1.amazonaws.com/012345678901/my_queue",
MessageBody=json.dumps({"message": "hello"}),
)
lambda超时(60秒).在调试时,我注意到boto3
客户端正在连接到eu-west-1.queue.amazonaws.com
而不是
我在QueueUrl参数中指定的sqs.eu-west-1.amazonaws.com
.
通过进一步的调试,我注意到eu-west-1.queue.amazonaws.com
决定在Lambda中进行公开演讲,而
sqs.eu-west-1.amazonaws.com
解析为私人地址.我不
了解为什么会这样.
The lambda is timing out (60s). While debugging, I noticed that the boto3
client is connecting to eu-west-1.queue.amazonaws.com
rather than
sqs.eu-west-1.amazonaws.com
, which I specified in the QueueUrl parameter.
Through further debugging, I noticed that eu-west-1.queue.amazonaws.com
resolves to a public address within the Lambda whereas
sqs.eu-west-1.amazonaws.com
resolves to a private address. I don't
understand why this is happening.
推荐答案
我在 GitHub ,感谢swetashre在这里回答我.事实证明,创建SQS客户端时需要指定端点URL.
I asked the same question on GitHub, so thanks to swetashre for answering me there. It turns out I needed to specify the endpoint URL when creating the SQS client.
sqs = boto3.client("sqs", endpoint_url="https://sqs.eu-west-1.amazonaws.com")
这篇关于Lambda无法将消息发送到SQS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!