miqrc
miqrc

Reputation: 2384

AWS Lambda constructor error "Could not find API configuration lambda-2015-03-31"

I am trying to initialize a lambda client inside a nodejs code. When calling the lambda constructor I am getting an error.

I am executing:

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'});

This last line throws the following exception:

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

The environment variables are correctly configured. I am also doing some DynamoDB operations and everything works ok.

I followed the AWS documentation: https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/Lambda.html

I have also checked the service status (it's ok): https://status.aws.amazon.com/

Upvotes: 0

Views: 1550

Answers (1)

Nikolay Vetrov
Nikolay Vetrov

Reputation: 634

First of all, you're not executing your lambda function right now, you're trying to declare a new AWS Lamba object with a required parameter region and an optional parameter apiVersion. To execute your lambda function you have to include the following code to your project:

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' */
};

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

try
{
    const lambdaResp = await lambda.invoke(lambdaParams).promise();

    // TO DO: process lambdas response

    return lamdaResp;
}
catch (ex)
{
    console.error(ex);
}

Upvotes: 1

Related Questions