简体   繁体   English

通过AWS Lambda函数与mongodb通信

[英]communicate with mongodb from aws lambda function

I have created a lambda function and executed a program which include numpy by uploading zip file and it executed successfully. 我创建了一个lambda函数,并通过上传zip文件执行了一个包含numpy的程序,该程序成功执行。

but when I connect the mongodb using public ip then it throughing exception as "time out". 但是当我使用公共ip连接mongodb时,它将通过异常作为“超时”。 Please help me . 请帮我 。 thanks in advance. 提前致谢。

The problem is that your Lambda function is unable to connect to your EC2 instance which is running MongoDB. 问题是您的Lambda函数无法连接到运行MongoDB的EC2实例。

This is most likely a SecurityGroup issue. 这很可能是SecurityGroup问题。

You should allow your lambda VPC to connect to your EC2 instance. 您应允许Lambda VPC连接到EC2实例。 In essence it means that you will assign a VPC, subnet and Security group to your lambda. 本质上,这意味着您将为Lambda分配一个VPC,子网和安全组。 Afterwards you can allow the security group of the lambda to access the security group of your mongo. 之后,您可以允许lambda的安全组访问mongo的安全组。

Detailed instructions on how to add a vpc/subnet/sg to your lambda can be found here 有关如何将vpc / subnet / sg添加到lambda的详细说明,请参见此处

You add VPC information to your Lambda function configuration using the VpcConfig parameter, either at the time you create a Lambda function (see CreateFunction), or you can add it to the existing Lambda function configuration (see UpdateFunctionConfiguration). 您可以在创建Lambda函数时(请参阅CreateFunction)使用VpcConfig参数将VPC信息添加到Lambda函数配置中,也可以将其添加到现有Lambda函数配置中(请参见UpdateFunctionConfiguration)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM