我可以使用lambda调用将路径参数传递给另一个lambda函数吗?
我正在尝试使用lambda调用从另一个lambda函数进行调用并获取响应.问题是其他lambda函数需要将id作为路径参数(或作为查询字符串)发送.但是我没有看到lambda调用中的选项.如果我在有效负载中传递id,则另一个函数将在事件主体中接收它,而不是将其作为路径参数.是否有现有的解决方案?
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?
这是lambda函数内部的一个函数,该函数调用另一个lambda函数,该函数接收数据作为查询字符串参数
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));
}
}
);
});
}
这是lambda函数的一部分,它将数据作为查询字符串接收(而不是将数据作为路径参数接收的函数)
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,
};
API网关代理集成向Lambda函数的输入如下.
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"}
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.
因此,您的Lambda-A函数应该创建有效载荷"对象(请参阅随附的代码示例),如下所示.在Lambda-B中,您可以使用"event.pathParameters"访问路径参数.
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
}