I'm trying to code a Lambda function that is invoked via a hit to an API Gateway endpoint. Simply returning the event, I can see that there is a body in the response:
def lambda_handler(event, context):
return str(event)
Response:
{
'version': '2.0',
'routeKey': 'ANY /identify',
'rawPath': '/default/identify',
'rawQueryString': '',
'headers':
{
...
},
'requestContext':
{
...
},
'body': '<base64 encoded string is here>',
'isBase64Encoded': True
}
However, as soon as I try to return just the body, I get the following error (multiple examples included which all return the same error).
def lambda_handler(event, context):
return str(event['body'])
def lambda_handler(event, context):
return json.loads(event['body'])
def lambda_handler(event, context):
params = parse_qs(event["body"])
def lambda_handler(event, context):
return event['body']
{
"errorMessage": "'body'",
"errorType": "KeyError",
"requestId": "5acbcc66-da05-429f-baa9-6c8d83801b4f",
"stackTrace": [
" File \"/var/task/lambda_function.py\", line 10, in lambda_handler\n return json.loads(event['body'])\n"
]
}
Any ideas?
<base64 encoded string is here>
are you even decoding the base64? What is the outcome of the decoding procedure?print(event.keys())