0

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/

1 Answer 1

1

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);
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.