我正在尝试使用其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和关联的子网,这阻止了它访问外部资源。删除此问题解决了我的问题。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句