2
votes

I have a Lambda function mapped to API Gateway, where I have Models defined for the request input and response output.

But how to I access that model in the Lambda function (node) code?

http://docs.aws.amazon.com/apigateway/latest/developerguide/models-mappings.html

2

2 Answers

0
votes

Unfortunately this is not natively supported in Lambda/API Gateway. You could certainly make a request to the API Gateway service to get the model information or simply hard code this information in the Lambda function.

0
votes

OK turns out this is very easy! The model defined in API gateway is available right as the event parameter to the lambda handler method. This will write it to a log:

console.log(JSON.stringify(event, null, '  '));

And an individual field on that object can be accessed like:

console.log("Model property value: " + event.foo);