I created a lambda function using the following method.
Inside a new folder I ran
npm init
to initialize a new projectThen I added my code to index.js and ran
npm install mysql --save
to save mysql package locally.After this I zipped the content of this new folder and uploaded the zip to lambda functions.
I ran the test using test in the console and got this error.
{ "errorType": "Error", "errorMessage": "Cannot find module 'mysql'\nRequire stack:\n- /var/task/index.js\n- /var/runtime/UserFunction.js\n- /var/runtime/index.js", "trace": [ "Error: Cannot find module 'mysql'", "Require stack:", "- /var/task/index.js", "- /var/runtime/UserFunction.js", "- /var/runtime/index.js", " at Function.Module._resolveFilename (internal/modules/cjs/loader.js:880:15)", " at Function.Module._load (internal/modules/cjs/loader.js:725:27)", " at Module.require (internal/modules/cjs/loader.js:952:19)", " at require (internal/modules/cjs/helpers.js:88:18)", " at Runtime.exports.handler (/var/task/index.js:4:17)", " at Runtime.handleOnce (/var/runtime/Runtime.js:66:25)" ] }