AWS Lambda 初始化 Node.js 工程

AWS Lambda Node.js About 771 words

初始化项目

创建文件夹

mkdir lambda-test

进入文件夹

cd lambda-test

初始化工程

npm init -y

安装依赖

npm i -D typescript esbuild pg @types/pg @types/aws-lambda

编写构建脚本

package.json中编写构建脚本。

Windows 系统构建命令

"scripts": {
  "prebuild": "del /q dist",
  "build": "esbuild src/index.ts --bundle --minify --sourcemap --platform=node --target=es2020 --outfile=dist/index.js",
  "postbuild": "powershell -NoProfile -Command \"Compress-Archive -Path './dist/*' -DestinationPath './dist.zip' -Force\"",
  "test": "echo \"Error: no test specified\" && exit 1"
},

备注

如果不要带源码映射可以去掉--sourcemap,(Claude Code客户端代码就是因为不小心携带了sourcemap导致源码泄露)

esbuild src/index.ts --bundle --minify --platform=node --target=es2020 --outfile=dist/index.js

参考文档

https://docs.amazonaws.cn/en_us/lambda/latest/dg/lambda-typescript.html

Views: 15 · Posted: 2026-07-23

———         Thanks for Reading         ———

Give me a Star, Thanks:)

https://github.com/fendoudebb/LiteNote

扫描下方二维码关注公众号和小程序↓↓↓

扫描下方二维码关注公众号和小程序↓↓↓
Prev Post
Today In History
Browsing Refresh