2 Respuestas
- Más nuevo
- Más votos
- Más comentarios
0
The event is already received by the lambda function as python dictionary so you do not need to use json.loads() to parse the event.
What you are probably trying to achieve is to parse the POST json body from the event and convert it from json string to python dictionary. So you need to do something like this:
body = json.loads(event["body"])
0
This works for me:
import json
import base64
# import requests
def lambda_handler(event, context):
#print out the body of the request
print(event['body'])
try:
# Decode the Base64 encoded body
decoded_body = base64.b64decode(event['body']).decode('utf-8')
except (ValueError, UnicodeDecodeError):
# Handle decoding errors
decoded_body = 'Error: Invalid Base64 encoded body'
return {
"statusCode": 200,
"body": json.dumps({
"message": decoded_body,
}),
}
and then when I test it:
curl https://abc123.execute-api.af-south-1.amazonaws.com/Prod/create -X POST -d '{"key1":"value1", "key2":"value2"}'
{"message": "{\"key1\":\"value1\", \"key2\":\"value2\"}"}%
respondido hace 2 meses
Contenido relevante
- OFICIAL DE AWSActualizada hace 2 años
- OFICIAL DE AWSActualizada hace 2 años
- OFICIAL DE AWSActualizada hace 2 años
- OFICIAL DE AWSActualizada hace 2 años