我正在尝试减少使用aws-sdk的nodejs lambda包的大小。这是原始的lambda package.json文件:
{
"name": "lambdanodejs",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"aws-sdk": "^2.784.0",
"bluebird": "^3.7.2",
"ioredis": "^4.19.2",
"redis": "^3.0.2",
"redis-clustr": "^1.7.0"
}
}
整体大小为57MB,54属于aws-sdk。
为了减少大小,我尝试使用特定的客户端服务(v3sdk)。关注:https://github.com/aws/aws-sdk-js-v3/blob/main/clients/client-secrets-manager/package.json
{
"name": "lambdanodejs",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"@aws-sdk/client-dynamodb": "^3.7.0",
"@aws-sdk/client-secrets-manager": "^3.7.0",
"bluebird": "^3.7.2",
"ioredis": "^4.19.2",
"redis": "^3.0.2",
"redis-clustr": "^1.7.0"
}
}
现在npm install的结果更大,大约190 + MB。另外,在node_modules中,我看到了很多在使用以前的package.json安装时没有的目录。这个v3 aws-sdk应该更轻。我错过了什么吗?
谢谢!
2条答案
按热度按时间v440hwme1#
zhte4eai2#
升级到V3极大地增加了我的Node lambda包的大小,直到我还将lambda运行时从NODEJS_14_X升级到NODEJS_18_X。