I have an a closure by Amazon webservices called lambda function with delegation defined as following:
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'))
When I send a request to the lambda function as following:
{
"action": "getPosition",
"body": {
"id": 2021152530123456
}
}
I get an error response from the lambda function as following:
{"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!"}
I don't know why since JSON-File 2021152530123456.json do exist directly in s3 bucket.
Could you help to figure out what the error could be in this case?