使用 AWS Lambda Python API 向 AWS SQS 队列发送消息超时
Sending a message to AWS SQS Queue with AWS Lambda Python API Times out
我正在尝试使用其 Python API 写入 AWS Lambda 中的 SQS 消息,但我尝试的任何操作都超时(我已经 运行 它一分钟但是没有成功)。我为该角色配置了 SQS 完全访问权限。我可以看到函数日志到达正确的位置,但最后一行显示
Starting new HTTPS connection (1): eu-west-1.queue.amazonaws.com
在超时之前。我正在使用 AWS 控制台中的测试客户端对其进行测试。
处理程序代码是:
import boto3
import logging
import os
logger = logging.getLogger()
logger.setLevel(logging.DEBUG)
QUEUE_NAME = os.getenv("QUEUE_NAME")
SQS = boto3.client("sqs")
def getQueueURL():
"""Retrieve the URL for the configured queue name"""
q = SQS.get_queue_url(QueueName=QUEUE_NAME).get('QueueUrl')
logger.debug("Queue URL is %s", QUEUE_URL)
return q
def record(event, context):
"""The lambda handler"""
logger.debug("Recording with event %s", event)
data = event.get('data')
try:
logger.debug("Recording %s", data)
u = getQueueURL()
logging.debug("Got queue URL %s", u)
resp = SQS.send_message(QueueUrl=u, MessageBody=data)
logger.debug("Send result: %s", resp)
except Exception as e:
raise Exception("Could not record link! %s" % e)
似乎总是在检索队列时超时 URL。为什么会这样,我该如何真正防止这种情况发生,以便我可以写入队列?
我已将此功能分配给 VPC 和关联的子网,这阻止了它访问外部资源。删除它解决了我的问题。
我正在尝试使用其 Python API 写入 AWS Lambda 中的 SQS 消息,但我尝试的任何操作都超时(我已经 运行 它一分钟但是没有成功)。我为该角色配置了 SQS 完全访问权限。我可以看到函数日志到达正确的位置,但最后一行显示
Starting new HTTPS connection (1): eu-west-1.queue.amazonaws.com
在超时之前。我正在使用 AWS 控制台中的测试客户端对其进行测试。
处理程序代码是:
import boto3
import logging
import os
logger = logging.getLogger()
logger.setLevel(logging.DEBUG)
QUEUE_NAME = os.getenv("QUEUE_NAME")
SQS = boto3.client("sqs")
def getQueueURL():
"""Retrieve the URL for the configured queue name"""
q = SQS.get_queue_url(QueueName=QUEUE_NAME).get('QueueUrl')
logger.debug("Queue URL is %s", QUEUE_URL)
return q
def record(event, context):
"""The lambda handler"""
logger.debug("Recording with event %s", event)
data = event.get('data')
try:
logger.debug("Recording %s", data)
u = getQueueURL()
logging.debug("Got queue URL %s", u)
resp = SQS.send_message(QueueUrl=u, MessageBody=data)
logger.debug("Send result: %s", resp)
except Exception as e:
raise Exception("Could not record link! %s" % e)
似乎总是在检索队列时超时 URL。为什么会这样,我该如何真正防止这种情况发生,以便我可以写入队列?
我已将此功能分配给 VPC 和关联的子网,这阻止了它访问外部资源。删除它解决了我的问题。