简体   繁体   English

AWS Lambda Snowflake Python 连接器在尝试连接时挂起

[英]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:我相信我的子网和网络设置正确:

  • Just to test and develop, I set my security group to allow all inbound and outbound traffic on all ports.只是为了测试和开发,我将安全组设置为允许所有端口上的所有入站和出站流量。
  • I have my Lambda running in a private subnet, and a route table that directs 0.0.0.0/0 to the NAT Gateway instance.我的 Lambda 在私有子网中运行,并且有一个将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'))只是为了证明我确实有互联网连接。
  • I have many large dependencies that don't fit in the 200MB deploy package for Lambdas, so I have my dependencies mounted in an EFS file system at /mnt/efs path, and I add /mnt/efs/python to my PYTHONPATH in the code before I start to import those dependencies.我有许多大型依赖项不适合用于 Lambdas 的 200MB 部署包,因此我将我的依赖项安装在位于/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我已经证实

  • the AWS Lambda function is connected to the internet (it receives a [200 OK] from the requests.get call). AWS Lambda 函数连接到互联网(它从requests.get调用接收[200 OK] )。
  • security groups are as permissive as possible (allow all traffic on all ports both inbound and outbound)安全组尽可能宽松(允许所有入站和出站端口上的所有流量)
  • I have not touched the NACL我没有接触过 NACL

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.

相关问题 如何在不使用 snowflake-connector-python 的情况下连接到 aws lambda function 中的雪花? - How can I connect to snowflake in aws lambda function without using snowflake-connector-python? Snowflake python连接器不适用于AWS Lambda中的较大数据集 - Snowflake python connector not working on larger data set in AWS Lambda Python AWS Lambda 信号:在雪花连接(snowflake.connector)期间中止(核心转储) - Python AWS Lambda signal: aborted (core dumped) during snowflake connection (snowflake.connector) 我们如何使用 python 连接器连接到雪花 - How do we connect to snowflake using python connector 带密码的雪花连接器 (Python) - Snowflake connector with passcode (Python) Snowflake - Python 的连接器问题 - Snowflake - Connector issue with Python 适用于 Python 问题的雪花连接器 - Snowflake Connector for Python Issue 如何在 Python 3 中的 Databricks 中使用 python 雪花连接器连接到雪花? - How to connect to Snowflake using python snowflake connector from within Databricks in Python 3? 雪花查询适用于 cli 但不适用于 python 雪花连接器 - snowflake query works with cli but not python snowflake connector 为 python 安装雪花连接器时出错 - Error installing snowflake connector for python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM