我正在尝试使用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杀死它。
答案 0 :(得分:1)
在这种情况下,我无法连接到DynamoDB API。这可能是由于没有按照Mark B的建议在VPC功能上设置NAT,但在这种情况下,我对传出安全组的限制过于严格。