[英]Sending a message to AWS SQS Queue with AWS Lambda Python API Times out
I am trying to write to an SQS message in AWS Lambda using its Python API, but anything I try times out (I've run it for a minute but no success). 我正在尝试使用其Python API写入AWS Lambda中的SQS消息,但我尝试的任何事情都会超时(我已经运行了一分钟但没有成功)。 I have SQS full access configured for the role.
我为该角色配置了SQS完全访问权限。 I can see the function logs get to the right place, yet the last line says
我可以看到函数日志到达正确的位置,但最后一行说
Starting new HTTPS connection (1): eu-west-1.queue.amazonaws.com
before it times out. 在它超时之前。 I'm testing it using the test client within the AWS console.
我正在使用AWS控制台中的测试客户端对其进行测试。
The handler code is: 处理程序代码是:
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)
It seems to always time out on retrieving the queue URL. 似乎总是超时检索队列URL。 Why is this and how do I actually prevent that from happening so I can write to the queue?
为什么这样,我如何实际防止这种情况发生,以便我可以写入队列?
I had assigned this function to a VPC and associated subnets, which was preventing it from accessing external resources. 我已将此功能分配给VPC和关联的子网,这阻止了它访问外部资源。 Removing this resolved my issue.
删除此解决了我的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.