投票 3 挂在 Lambda
Boto 3 hanging in Lambda
我正在尝试使用 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 杀死它。
在这种情况下,我无法连接到 DynamoDB API。这可能是由于没有按照 Mark B 的建议在 VPC 函数上设置 NAT,但在这种情况下,我对传出安全组的限制过于严格。
我正在尝试使用 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 杀死它。
在这种情况下,我无法连接到 DynamoDB API。这可能是由于没有按照 Mark B 的建议在 VPC 函数上设置 NAT,但在这种情况下,我对传出安全组的限制过于严格。