Reputation: 89
I am replatforming an existing application to work with AWS API Gateway and AWS Lambda. The current application exposes it functionality as REST API which is implemented as a Spring Boot application and Spring REST Controller annotations.
While I am able to get the request body JSON from the API Gateway into the Lambda function, in certain cases I would need variables from the Request object as well as path variables accessible in the Lambda function. I did take a look at the Lambda Context object but it did not have anything that could help me in this regard.
Example API URLs: I use a path variable similar to the id variable in the following API call
GET http://www.example.com/users/{id}/alerts
. {id} will be the path variable here. An example of how we use a request variable is in the following URL where the alert id is passed as a query string parameter -GET http://www.example.com/users/{id}/alerts?id=1234
Is there any recommended way to get this done? I do not want to use the RequestHandler interface as I am aiming to tie each API to a separate Lambda function.
Upvotes: 3
Views: 6972
Reputation: 4152
If you are using AWS integration type:
Use a mapping template to send $input.params('id') property in the request body to your Lambda function.
If you are using AWS_PROXY integration type:
You can access the path parameters via the "pathParameters" property of the incoming event. For more details, please read the docs.
Upvotes: 3
Reputation:
I suggest you use the Lambda Proxy integration type, it makes all the information you need available with the least hassle. So, the properties you need to read will be available as follows:
/users/...
path: event.path
event.queryStringParameters.id
event.httpMethod
event.pathParameters
Let me know if you need any more information.
Upvotes: 2