I'm trying to call and get the response from another lambda function using lambda invoke. The problem is other lambda function needs the id to be sent as path parameters (or as a query string). But I do not see an option in lambda invoke for this. If I pass the id in payload the other function will receive it in the event body and not as path parameters. Is there an existing solution for this?
Here is a function inside a lambda function which calls another lambda function which receives the data as query string parameters
function getWisIqLink(data) {
const payload = {
queryStringParameters: {
userId: data.userId,
eventId: data.eventId,
}
};
const param = {
FunctionName: 'consult-rest-api-dev-WisiqClassGet',
InvocationType: "RequestResponse",
Payload: JSON.stringify(payload)
}
return new Promise((resolve, reject) => {
// console.log(`Starting promiseInvoke InvokeAsync with ES6 promise wrapper - ${functionName}`);
lambda.invoke(param,(err, data) => {
if (err) {
reject(err);
} else {
resolve(JSON.parse(data));
}
}
);
});
}
I'm trying to call and get the response from another lambda function using lambda invoke. The problem is other lambda function needs the id to be sent as path parameters (or as a query string). But I do not see an option in lambda invoke for this. If I pass the id in payload the other function will receive it in the event body and not as path parameters. Is there an existing solution for this?
Here is a function inside a lambda function which calls another lambda function which receives the data as query string parameters
function getWisIqLink(data) {
const payload = {
queryStringParameters: {
userId: data.userId,
eventId: data.eventId,
}
};
const param = {
FunctionName: 'consult-rest-api-dev-WisiqClassGet',
InvocationType: "RequestResponse",
Payload: JSON.stringify(payload)
}
return new Promise((resolve, reject) => {
// console.log(`Starting promiseInvoke InvokeAsync with ES6 promise wrapper - ${functionName}`);
lambda.invoke(param,(err, data) => {
if (err) {
reject(err);
} else {
resolve(JSON.parse(data));
}
}
);
});
}
Here is a bit of a lambda function which receives the data as query strings (Not the function which receives data as path parameters)
module.exports.get = async function (event, context, callback) {
const data = {
userId: event.queryStringParameters.userId,
eventId: event.queryStringParameters.eventId,
};
Share
Improve this question
edited Apr 26, 2019 at 5:12
Yasith Prabuddhaka
asked May 15, 2018 at 4:47
Yasith PrabuddhakaYasith Prabuddhaka
9171 gold badge12 silver badges18 bronze badges
2
|
2 Answers
Reset to default 14The 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();
}
event
andcontext
-- not "path parameters" -- so it isn't clear what you are saying the second function needs. Can you show us that code? – Michael - sqlbot Commented May 15, 2018 at 9:17