Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to solve Runtime.HandlerNotFound Error in AWS Lambda

I am creating a simple API and i want to create a function that stores the input data, however i consistently get the Runtime.HandlerNotFound error.

I've checked the environment name (index.js) matches the handler (index.handler)

const AWS = require('aws-sdk');
const dynamodb = new AWS.DynamoDB({region: 'us-east-2', apiVersion: '2012-08-10'});

exports.fn = (event, context, callback) => {
    const params = {
        Item: {
            "UserId": {
                N: event.userId
            },
            "firstname": {
                S: event.firstname
            },
            "lastname": {
                S: event.lastname
            },
            "email": {
                S: event.email
            }
        },
        TableName: "contact-info"
    };
    dynamodb.putItem(params, function(err, data) {
        if (err) {
            console.log(err);
            callback(err);
        } else {
            console.log(data);
            callback(null, data);
        }
    });
};

I am expecting the AWS Lambda test to return an empty object with no errors.

like image 792
Charlie Felix Avatar asked Jun 06 '26 07:06

Charlie Felix


1 Answers

In index.handler, the index refers to the entry-point file name and handler refers to the function name in the entry-point file which would be invoked by the Lambda.

The reason why you are getting Runtime.HandlerNotFound is because the Lambda is looking for a function called handler in your index.js but you are exporting fn.

Change it to exports.handler=...

like image 168
Ramaraja Ramanujan Avatar answered Jun 07 '26 22:06

Ramaraja Ramanujan