2 Answers
- Newest
- Most votes
- Most comments
0
Might be worth converting the body into JSON and extracting the required data
import json
def lambda_handler(event, context):
headers = event['headers']
body_str = event['body']
try:
body_json = json.loads(body_str)
# Extract the required values from the JSON
main_description_list = body_json.get('mainDescriptionList', [])
coordinator_list = body_json.get('coordinatorList', [])
# Process the extracted values as needed
print(f"Main Description List: {main_description_list}")
print(f"Images List: {images_list}")
print(f"Event List: {event_list}")
print(f"Coordinator List: {coordinator_list}")
# Additional processing or logic can be added here
except (json.JSONDecodeError, KeyError):
print("Error: Request body is not valid JSON or missing required keys")
return {
'statusCode': 200,
'body': json.dumps('Hello from Lambda!')
}
answered 2 months ago
0
Thanks @hnsoni-from-aws. I have tried your solutions but it throws the exception for JSONDecodeError. I have missed to mention that the ReactJS application send the request to the lambda function with the "' content-type': 'multipart/form-data' " in its header. Since it contains files (basically images files for "imagesList" and "coordinatorList").
I am not sure why it is this hard to process an request that contains files or am I missing something or is there a different way to do this?
answered 2 months ago
Relevant content
- Accepted Answerasked 8 months ago
- Accepted Answerasked 3 years ago
- AWS OFFICIALUpdated a year ago
- AWS OFFICIALUpdated 2 years ago
- AWS OFFICIALUpdated 8 months ago