Can I pass path parameters using lambda invoke to another lambda function?

一曲冷凌霜 提交于 2019-12-04 12:09:48

The input to the Lambda function from API Gateway proxy integration is as follows.

{
"resource": "Resource path",
"path": "Path parameter",
"httpMethod": "Incoming request's method name"
"headers": {Incoming request headers}
"queryStringParameters": {query string parameters }
"pathParameters":  {path parameters}
"stageVariables": {Applicable stage variables}
"requestContext": {Request context, including authorizer-returned key-value pairs}
"body": "A JSON string of the request payload."
"isBase64Encoded": "A boolean flag to indicate if the applicable request payload is Base64-encode"}

This schema is defined in here.

Your requirement is to pass path parameters from one lambda function (let's say Lambda-A) to another lambda function (Let's say Lambda-B). This means your Lambda-A function has to act as the API gateway that sends a request with above format to Lambda-B.

Hence your Lambda-A function should create "payload" object (please see the code sample that you have attached) as below. And in your Lambda-B, you may access the path parameters using "event.pathParameters".

const payload = {
  pathParameters: data.consulteeId
}

You can invoke the Lambda as ApiGatewayRequest. The ApiGatewayRequest has body and header. You can pass the parameters in the header. Following is the code.

 public ApiGatewayProxyResponse invokeLambda(LambdaService lambda, Object data, Map<String, String> headers) 
{
     ApiGatewayRequest request = new ApiGatewayRequest();
     request.setBody(data);
     request.setHeaders(headers);
     ApiGatewayProxyResponse response = lambda.execute(request);
     return response.getBody();
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!