[英]AWS Lambda Snowflake Python Connector hangs attempting to connect
I have a small AWS Lambda function that looks like this:我有一个小的 AWS Lambda 函数,如下所示:
It grabs the credentials to connect to Snowflake from SSM Parameter Store, and then calls snowflake.connector.connect
.它获取凭据以从 SSM Parameter Store 连接到 Snowflake,然后调用
snowflake.connector.connect
。 It's meant to obviously go grab data from my Snowflake data warehouse.这显然是为了从我的 Snowflake 数据仓库中获取数据。 However, the code hangs and never finishes the
snowflake.connector.connect
call.但是,代码挂起并且永远不会完成
snowflake.connector.connect
调用。
I believe my subnets and networking are set up properly:我相信我的子网和网络设置正确:
0.0.0.0/0
to the NAT Gateway instance.0.0.0.0/0
定向到 NAT 网关实例的路由表。 In my code, I print(requests.get('http://216.58.192.142'))
just to prove that I do indeed have internet connectivity.print(requests.get('http://216.58.192.142'))
只是为了证明我确实有互联网连接。/mnt/efs
path, and I add /mnt/efs/python
to my PYTHONPATH
in the code before I start to import those dependencies./mnt/efs
路径的 EFS 文件系统中,并将/mnt/efs/python
到我的PYTHONPATH
中在我开始导入这些依赖项之前的代码。import boto3
import snowflake.connector
print("Getting snowflake creds")
session = boto3.session.Session()
ssm = session.client("ssm")
obj = ssm.get_parameter(Name="snowflake", WithDecryption=True)
sf_creds = json.loads(obj.get("Parameter").get("Value"))
def get_data(event, context):
print(requests.get('http://216.58.192.142'))
print("Executing")
print("got parameter, connecting")
con = snowflake.connector.connect(
user=sf_creds["USER"],
password=sf_creds["PASSWORD"],
account=sf_creds["ACCOUNT"],
ocsp_response_cache_filename="/tmp/ocsp_response_cache"
)
print("connected")
When I run this same exact code locally on my MacBook, I am able to connect fairly quickly, within a second or two.当我在 MacBook 本地运行相同的代码时,我能够在一两秒内快速连接。 My
snowflake-python-connector
version is 2.3.2
.我的
snowflake-python-connector
版本是2.3.2
。
However, no matter how long I try, the connect
method hands when it executes in an AWS Lambda function.但是,无论我尝试多久,
connect
方法都会在 AWS Lambda 函数中执行时传递。 I'm really not sure what is going on.我真的不确定发生了什么。
I've verified that我已经证实
[200 OK]
from the requests.get
call). requests.get
调用接收[200 OK]
)。 Really, I'm at a loss as to why this is happening, especially given that the code works fine on my local machine - could someone try to point me in the right direction?真的,我不知道为什么会发生这种情况,特别是考虑到代码在我的本地机器上运行良好 - 有人可以尝试指出我正确的方向吗?
Lambda can respond with 200, but there can be exception in logs. Lambda 可以响应 200,但日志中可能会出现异常。 Check out the CloudWatch logs of this lambda.
查看此 lambda 的 CloudWatch 日志。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.