0

I understand that API Gateway (AG) passes params into Lambda as JSON payload.

I have setup a POST API with Lambda Proxy in AG. My lambda function takes the following param list :

{
  "fullname": "Mr xxxxx",
  "clientemail": "[email protected]",
  "clientphone": "0800 088 8888",
  "locationtext": "Laxxxxxx Hotel , CA, USA",
  "subject": "Gxxxxxrth",
  "appointmentblock_min": "60",
  "buffer": "120",
  "calendar_id": "xxxxx",
  "thedate": "2021-03-2xxxxxx",
  "thetime": "xxxxx"
}

Testing directly within the Lambda console. Everything works fine. I map all parameters in the code using the lambda EVENT object as follows :

fullname = event['fullname']  
clientemail = event['clientemail']
appointmentblock_min = int(event['appointmentblock_min'])

... and so on.

All code works fine.

Adding the API Gateway component on top ... and things don't work.

The specific problem : how can I map the lambda input parameters coming from API Gateway (AG) to lambda ? I realise that AG is sending JSON into Lambda. How to parse this payload to extract and use the parameters that I need.

I have tried to create a dict containing all the parameters :

Event = {}
Event = json.loads(body)
Event = json.loads(event.body)

No docs explicitly explain how to grab the event object params via AG.

Any help would be appreciated.

PS I am expecting to return data back to AG as follows :

return {
            'statusCode': 200,
            'headers': {'Content-Type': 'application/json'},
            'body': json.dumps(out_message),
            'isBase64Encoded': 'false'
        }

Thank you for your consideration.

1
  • AG Error : Tue Mar 23 19:49:32 UTC 2021 : Lambda execution failed with status 200 due to customer function error: 'thedate'. Lambda request id: 328e-4263-9237-174dce236e44 Tue Mar 23 19:49:32 UTC 2021 : Method completed with status: 502 thedate refers to Lambda code . Assign the variable 'thedate' to input param : thedate = event['thedate'] Commented Mar 23, 2021 at 19:51

1 Answer 1

2

According to TestEvents in Lambda, the input you get on Lambda will be

LambdaTest

So you can load your payload (or body) as

Event = json.loads(event['body'])
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.