从另一个Lambda调用Lambda的问题

时间:2018-08-03 11:18:04

标签: node.js aws-lambda amazon-dynamodb aws-api-gateway aws-sdk-nodejs

我有2个Lambda函数,我不想通过API网关直接调用它们。 Lambda函数A正在与queryStringParameters一起调用LambdaB。由于某些原因,我收到此错误

  

{UnexpectedParameter:在参数中找到了意外的键'queryStringParameters'

这是我的Lambda A函数

    var aws = require('aws-sdk');
var lambda = new aws.Lambda({
  region: 'eu-central-1'
});    
exports.handler = (event, context, callback) => {
var params = {
      FunctionName: "function-getStats", 
      InvocationType: "RequestResponse", 
      LogType: "Tail", 
      "queryStringParameters" : { "fn" : "latest_no" }
     };
     lambda.invoke(params, function(err, data) {
       if (err) console.log(err, err.stack); // an error occurred
       else     console.log(data);           // successful response
     });
};

以下哪个叫Lambda B

var AWS = require('aws-sdk');
AWS.config.update({region: 'eu-central-1'});
var ddb = new AWS.DynamoDB.DocumentClient({apiVersion: '2012-08-10'});

exports.handler = (event, context, callback) => {
    var fn = event["queryStringParameters"]['fn'];
...
..


//If successful return the following response
     console.log("Success", items);
                callback(null, {
                    'statusCode': '200',
                    'body': JSON.stringify(items),
                    'headers': {
                        "Access-Control-Allow-Origin": "*"

                    },
                    'isBase64Encoded': false
                });

有人可以建议如何解决此问题吗?

1 个答案:

答案 0 :(得分:1)

万一有人遇到同样的问题。这是我做的方法

var aws = require('aws-sdk');
var lambda = new aws.Lambda({
  region: 'eu-central-1'
});    
exports.handler = (event, context, callback) => {
    event.queryStringParameters= {"fn" : "latest_no" };
var params = {
      FunctionName: "function-getStats", 
      InvocationType: "RequestResponse", 
      LogType: "Tail", 
      Payload: JSON.stringify(event, null, 2), 

     };
     lambda.invoke(params, function(err, data) {
       if (err) console.log(err, err.stack); // an error occurred
       else     console.log(data);           // successful response
     });
};