AWS Lambda构造函数错误“找不到API配置lambda-2015-03-31”

时间:2018-10-02 07:30:58

标签: node.js amazon-web-services aws-lambda

我正在尝试在nodejs代码中调用一个lambda。调用lambda构造函数时,出现错误。

我正在执行:

var aws = require('aws-sdk');
aws.config.update({region: 'us-east-1'});
var lambda = new aws.Lambda({region: 'us-east-1', apiVersion: '2015-03-31'});

最后一行抛出以下异常:

Error: Could not find API configuration lambda-2015-03-31
    at Runtime.requireModule 
    at Runtime.requireModuleOrMock 
    at Object.get [as 2015-03-31]

正确配置了环境变量。我也在做一些DynamoDB操作,一切正常。

我遵循了AWS文档: https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/Lambda.html

我还检查了服务状态(可以): https://status.aws.amazon.com/

1 个答案:

答案 0 :(得分:0)

首先,您现在不执行lambda函数,而是尝试使用必需参数声明一个新AWS Lamba对象 {{1 }}和可选参数 region。要执行lambda函数,您必须在项目中包含以下代码:

apiVersion

参考https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/Lambda.html#invoke-property

const lambdaParams =
{
    FunctionName : functionName /* your lambdas function name */,
    Payload : JSON.stringify(event) /* The event have to be a string */,
    InvocationType: 'RequestResponse' /* Request type, right now it's going to execute your lambda function synch. To do async request you have to change 'RequestResponse' to 'Event' */
};