Lambda Function Error

0

I created Lambda function(Node.js) for image resizing. I got Runtime.HandlerNotFound error.

Cloudwatch log as follows:

2022-07-15T01:06:22.016Z undefined ERROR Uncaught Exception { "errorType": "Runtime.HandlerNotFound", "errorMessage": "index.handler is undefined or not exported", "stack": [ "Runtime.HandlerNotFound: index.handler is undefined or not exported", " at Object.module.exports.load (/var/runtime/UserFunction.js:283:11)", " at Object.<anonymous> (/var/runtime/index.js:43:34)", " at Module._compile (internal/modules/cjs/loader.js:1085:14)", " at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)", " at Module.load (internal/modules/cjs/loader.js:950:32)", " at Function.Module._load (internal/modules/cjs/loader.js:790:12)", " at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:75:12)", " at internal/main/run_main_module.js:17:47" ] }

Some of my Index.js is as follows:

'use strict';

const querystring = require('querystring'); // Don't install. const AWS = require('aws-sdk'); // Don't install.

// http://sharp.pixelplumbing.com/en/stable/api-resize/ const Sharp = require('sharp');

const S3 = new AWS.S3({ region: 'ap-northeast-2' // });

const BUCKET = 'BUCKET_NAME' // Input your bucket

// Image types that can be handled by Sharp const supportImageTypes = ['jpg', 'jpeg', 'png', 'gif', 'webp', 'svg', 'tiff', 'jfif'];

exports.handler = async(event, context, callback) => { const { request, response } = event.Records[0].cf;

console.log("request: ", request) console.log("response: ", response) . . . .

질문됨 2년 전7912회 조회
5개 답변
2

Your handler setup looks different to that described in https://docs.aws.amazon.com/lambda/latest/dg/nodejs-handler.html - are you sure it's equivalent? I don't use node.js so can't tell for sure, but it looks a good place to start.

전문가
답변함 2년 전
1
수락된 답변

can you check if the path of the handler and location of the index file in the packaged code is same? You will get this error when the path of the handler and the location of index.js in the package is not the same.

Enter image description here

AWS
답변함 2년 전
1

I notice documentation always says "index.js" but you mentioned "Index.js". I have no idea if it's relevant but just in case ...

전문가
답변함 2년 전
1

I think you packaged a zip file which does not contains the index.js in root of zip

The zip commands can give you a zip file containing another folder inside which contains the index js

Try to verify the content of package

답변함 2년 전
0

I replaced Index.js as follows:

exports.handler = function (event, context, callback) { . . .

but I got same error on cloudwatch.

2022-07-15T02:04:22.891Z undefined ERROR Uncaught Exception { "errorType": "Runtime.HandlerNotFound", "errorMessage": "index.handler is undefined or not exported", "stack": [ "Runtime.HandlerNotFound: index.handler is undefined or not exported", " at Object.module.exports.load (/var/runtime/UserFunction.js:283:11)", " at Object.<anonymous> (/var/runtime/index.js:43:34)", " at Module._compile (internal/modules/cjs/loader.js:1085:14)", " at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)", " at Module.load (internal/modules/cjs/loader.js:950:32)", " at Function.Module._load (internal/modules/cjs/loader.js:790:12)", " at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:75:12)", " at internal/main/run_main_module.js:17:47" ] }

답변함 2년 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠