简体   繁体   English

AWS Lambda 无法连接到端点 URL DynamoDB

[英]AWS Lambda could not connect to endpoint URL DynamoDB

I'm developing a lambda function that I write in DynamoDB.我正在开发我在 DynamoDB 中编写的 lambda function。 On one hand I have created a layer that has a script with the functions of DynamoDB:一方面,我创建了一个层,该层具有具有 DynamoDB 功能的脚本:

class DynamoHandler():
    def __init__(self):
        self.resource = boto3.resource('dynamodb', region_name = 'eu-west-1')
        self.__table = None

 

    def set_table(self, table_name: str):
        table = self.resource.Table(table_name)
        table.table_arn
        self.__table = table

 

    def insert(self, item, **kwargs):
        self.__check_table()

 

        return self.__table.put_item(
            Item=item,
            **kwargs
        )

 

In the lambda I write the following code:在lambda我写了下面的代码:

from dynamo_class import DynamoHandler
    db = DynamoHandler()
    db.set_table(TABLE NAME)
    db.insert(msg) 

And I get the error:我得到了错误:

[ERROR] EndpointConnectionError: Could not connect to the endpoint URL: "https://dynamodb.eu-west-1.amazonaws.com/" [错误] EndpointConnectionError:无法连接到端点 URL:“https://dynamodb.eu-west-1.amazonaws.com/”

Do you know how can I solve this problem?你知道我该如何解决这个问题吗? I have searched for similar errors but they occurred when the region was not specified, in my case in the DynamoDB class I assign the region "eu-west-1".我已经搜索过类似的错误,但它们是在未指定区域时发生的,在我的情况下,在 DynamoDB class 中,我分配了区域“eu-west-1”。

The timeout occurs most likely because lambda in a VPC has no inte.net nor public IP address .发生超时很可能是因为 VPC 中的lambda 没有 inte.net也没有公共 IP 地址 From docs :来自文档

Connecting a function to a public su.net doesn't give it inte.net access or a public IP address.将 function 连接到公共 su.net不会为其提供inte.net 访问权限或公共 IP 地址。

Subsequently, the lambda function can't connect to DynamoDB endpoint.随后,lambda function无法连接到 DynamoDB 端点。

There are two ways to rectify the issue:有两种方法可以纠正此问题:

  • place the lambda in a private su.net and setup NAT gateway to enable lambda access the inte.net.将 lambda 放在私有的 su.net 中并设置NAT 网关以启用 lambda 访问 inte.net。
  • Use VPC Gateway for DynamoDB which would be better in this case, as for DynamoDB gateway there are no extra charges .使用DynamoDB 的 VPC 网关在这种情况下会更好,因为 DynamoDB 网关没有额外费用

In addition to the great answer by Marcin above, have you checked that the Security Group associated with the function has the correct egress rules that allow the.network interface to connect to either the DynamoDB or its NAT gateway?除了上面 Marcin 的出色回答之外,您是否检查过与 function 关联的安全组是否具有允许 .network 接口连接到 DynamoDB 或其 NAT 网关的正确出口规则?

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

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