Don't forget to hurry.
event ['body']
.isBase64Encoded
is enabled in the API Gateway settingsIf you pass the JSON encoded version when throwing it to the API, you can get the JSON after Base64 decoding. In that case, JSON parsing processing is performed instead of parsing the request query.
import json
import base64
import urllib.parse
def lambda_handler(event, context):
#Decode because the POST parameter is BASE64 encoded
decoded_body = base64.b64decode(event['body']).decode()
#Convert POST parameters to dict type
post_params = urllib.parse.parse_qs(decoded_body)
result = {}
result['message'] = 'Response from lambda'
#See POSTed data(Note that it is an array)
result['name'] = post_params['name'][0]
result['email'] = post_params['email'][0]
return {
'statusCode': 200,
'body': json.dumps(result)
}
Recommended Posts