node.js – “Error: Cannot find module ‘aws-sdk’\nRequire stack:\n- /var/task/index.js\n- /var/runtime/index.mjs” despite me adding a dependency to the sdk
I have upgraded my nodejs runtime on my lamdba function today from 10x (very outdated I realise) to 18x and I am getting the following error:
“Error: Cannot find module ‘aws-sdk’\nRequire stack:\n- /var/task/index.js\n- /var/runtime/index.mjs”
I understand that any version above 16x has to include the SDK as a dependency which I have done as part of the package.json file below:
{
"name": "service-now-api",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"zip": "zip ../service-now-api.zip -r ."
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"@aws-sdk/client-s3": "^3.216.0",
"@aws-sdk/s3-request-presigner": "^3.216.0"
}
}
I must be missing something I’m just not sure what, any help would be greatly appreciated
This Lambda is responsible for handling calls into a ServiceNow instance and so if the lambda fails the calls don’t get through
Below is the code from the index.js which is relevant to the aws sdk:
const https = require('https');
const AWS = require('aws-sdk');
const proxy = require('proxy-agent');
AWS.config.update({
region: process.env.AWS_REGION,
httpOptions: {
agent: proxy(process.env.PROXY_URL),
},
});
Read more here: Source link
