【发布时间】:2021-10-23 04:35:15
【问题描述】:
我有一个 Amazon webservices 的闭包,称为 lambda 函数,其委托定义如下:
def lambda_handler(event, context):
logger.info('Ev° %s', event)
if event['action'] == "getPosition":
getPosition(event, context)
def getPosition(event, context):
# read position from file
positionLoaded = readPosition(pId=int(json.loads(str(event['body']['id']))))
# build response
response = {
"statusCode": 200,
"body": json.dumps(positionLoaded, indent=4),
"message": "OK",
"headers": {
"Content-Type": "application/json",
}
}
return response
# Reads position in json file from s3 Bucket with pId
def readPosition(pId: int):
positionFromBucketJSON = s3_client.get_object(Bucket="bucketName", Key=str(pId) + ".json")
return json.loads(positionFromBucketJSON['Body'].read().decode('utf-8'))
当我向 lambda 函数发送请求时如下:
{
"action": "getPosition",
"body": {
"id": 2021152530123456
}
}
我收到一个错误来自 lambda 函数的响应,如下所示:
{"errorMessage": "'Not Found'", "errorType": "KeyError", "stackTrace": [" File \"/var/task/positionService.py\", line 58, in lambda_handler\n getPosition(event, context, callback=None)\n", " File \"/var/task/positionService.py\", line 76, in getPosition\n message = "not existing at all!"}
我不知道为什么,因为 JSON-File 2021152530123456.json 确实直接存在于 s3 存储桶中。
您能帮忙找出在这种情况下可能出现的错误吗?
【问题讨论】:
标签: amazon-web-services amazon-s3 aws-lambda