【问题标题】:Boto 3 hanging in LambdaBoto 3 挂在 Lambda
【发布时间】:2016-06-17 10:31:18
【问题描述】:

我正在尝试使用 Lambda 拍摄 Elasticsearch 集群的快照。我的脚本在本地完美运行,但在 Lambda 中,它在尝试扫描 DynamoDB(我的 Elasticsearch 位置的真实来源)时挂起。为了排除 IAM 权限,我将函数完全管理员作为调试的临时措施。我的代码如下:

import boto3
import datetime
import json
import requests

dynamodb = boto3.resource('dynamodb', region_name='us-east-1')

# change this to whatever your table name is
table = dynamodb.Table('elasticsearch-backups')
today = datetime.date.today()

# I don't fully understand the reason for this. Following example
# http://docs.aws.amazon.com/amazondynamodb/latest/gettingstartedguide/GettingStarted.Python.04.html
pe = "#dmn, #pth, #bkt"
ean = {"#dmn": "domain", "#pth": "path", "#bkt": "bucket"}


def lambda_handler(event, context):
    print "started"

    print "scanning table"


# hangs at this table.scan call


    nodes = table.scan(
        ProjectionExpression=pe,
        ExpressionAttributeNames=ean
        )

    print "nodes are " + str(nodes)

    for i in nodes['Items']:
        bucket = str(i['bucket'])
        path = str(i['path'])

        print "bucket is " + str(i['bucket'])
        print "base_path is " + str(i['path'])

        print "setting repository json"
        repository = {
            "type": "s3",
            "settings": {
                "bucket": bucket,
                "base_path": path
            }
        }
        print "repository json is " + json.dumps(repository)

        print "setting url path"
        url = i['domain'] + "/_snapshot/lambda_s3_repository"
        print "url path is " + url

    # create repository
        print "creating repository"
        response = requests.put(
            url,
            data=json.dumps(repository)
            )
        print response.content

    # start snapshot
        print "starting snapshot"
        url = url + "/" + str(today)
        response = requests.put(
            url
            )
        print response.content

lambda_handler("test", "test")

我可以做些什么来更好地了解该挂起函数调用中发生的事情以进一步调试?我在日志中几乎看不到任何东西。它不会失败,它只是挂起,直到 Lambda 杀死它。

【问题讨论】:

  • 挂在那一步听起来像是网络连接问题。如果这是权限问题,您将立即收到错误消息。您是否碰巧为您的 Lambda 函数启用了 VPC 访问?
  • 是的,几乎可以肯定。我没有启用 NAT 网关。我会这样做并报告
  • 不幸的是,该子网中已经存在一个 NAT 实例,并且路由设置正确。这不是托管的 NAT,但这应该没关系 AFAIK
  • 像个白痴一样,我在传出的安全组中过于严格了。感谢您为我指明方向

标签: python python-2.7 amazon-dynamodb aws-lambda boto3


【解决方案1】:

在这种情况下,我无法连接到 DynamoDB API。这可能是由于没有按照 Mark B 的建议在 VPC 功能上设置 NAT,但在这种情况下,我对传出安全组的限制过于严格。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-10-05
    • 2014-02-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多