How to pass parameters to AWS Lambda using WSO2 API Manager

In this article, I discuss how we can pass path, query, and header parameters to AWS Lambda with the API request using WSO2 API Manager.

Binod Karunanayake
2 min readJul 4, 2022

With the new release of WSO2 API Manager 4.1.0, it has enriched the AWS Lambda as an endpoint feature with several sub-features such as ability to pass parameters, support for AWS ECS environments, and support for AWS IMDSv2.

Note: For 4.1.0+ parameter passing is enabled by default. You can enable parameter passing for previous WSO2 API Manager versions by adding following config to deployment.toml file.

[apim.lambda_mediator_config]
pass_request_params = true

Why do we need separate effort to pass parameters?

Calling a http request and invoking a function are two different scenarios. Functions only accept a predefined parameter set while there are different parameter types that are used in https requests.

  • path parameters, such as /users/{id}
  • query parameters, such as /users?role=admin
  • header parameters, such as X-MyHeader: Value

This makes a complication when invoking Lambda functions as AWS Lambda can expose functions as http requests. However, AWS has come up with a solution called Lambda Proxy Integration for their API Gateway. Basically it maps all the parameters and other important properties to the event object which is passed to Lambda function.

The same input format (with limited properties) in Lambda Proxy Integration is used in WSO2 API Gateway to pass parameters to AWS Lambda. With that, let’s see how we can pass parameters to AWS Lambda effortlessly.

Steps to follow

Note: Edit your Lambda function to log the event object before configuring the API in WSO2 API Manager, so that you can understand how this works.

  1. Create a new REST API without the endpoint URL in Publisher portal.

2. Configure the access method for AWS Lambda in endpoints page.

3. Add a resource and define parameters.

4. Save, deploy, and publish the API.

5. Create application, subscribe API, generate keys, and invoke the API.

6. You can find the logged event object in following format in CloudWatch.

{
"headers": {},
"pathParameters": {},
"queryStringParameters": {},
"body": {},
"httpMethod": "",
"path": ""
}

7. So, you can easily use event object to retrieve the parameters in the Lambda function.

That’s it! Thanks for reading my article.

--

--

Binod Karunanayake

PhD Candidate @RMIT University | Former Software Engineer @WSO2 | BSc Engineering (Hons) University of Moratuwa