aws-sam-typescript-webpack-backend Monorepo部署方案

aws-sam-typescript-webpack-backend 的结构思路挺清晰,每个 Lambda 函数都是独立的包,还能共享代码,不会一份逻辑写好几遍。这套方案比较适合做中大型项目,尤其是你在搞 Monorepo 的情况下,Webpack 配合 Lambda Layer 可以把依赖打得干净,部署包超小,上传快、冷启动也快。

AWS SAM搭后端的时候,最大的问题之一就是本地调试 Monorepo 超麻烦。这个仓库就挺聪明,把Yarn workspaceTypeScriptWebpack配一起,了 SAM 默认不支持 Monorepo 的尴尬。你不需要再搞什么复杂路径映射,直接写业务逻辑就行。

每个函数目录里都能单独配置自己的handler.ts,打包的时候通过 Webpack 去掉没用的依赖,基本就一个小几百 KB 的包,贼干净。要复用工具类或中间件,也不用复制粘贴,在shared模块里统一维护,用 Layer 搞定。

部署方式也是按函数来拆的,虽然是 Monorepo,但每个函数都可以单独构建、部署,配合 CI/CD 自动化还蛮省心。哦对了,写单元测试也顺,项目结构一目了然,用jest测就行。

如果你正在折腾Serverless + TypeScript + Monorepo,又觉得 SAM 太死板,可以看看这个项目。哪怕不照搬,用来参考项目结构和 Webpack 配置也有价值。

zip
aws-sam-typescript-webpack-backend-main.zip 预估大小:39个文件
folder
aws-sam-typescript-webpack-backend-main 文件夹
file
.gitignore 62B
folder
functions 文件夹
file
package.json 480B
folder
get-customer-by-id-function 文件夹
file
package.json 270B
folder
src 文件夹
folder
domain 文件夹
file
get-customer-by-id-repository.ts 164B
file
get-customer-by-id-service.ts 502B
folder
infrastructure 文件夹
file
get-customer-by-id-ddb-repository.ts 761B
folder
application 文件夹
file
get-customer-by-id-processor.ts 997B
file
app.ts 1KB
file
tsconfig.json 154B
file
webpack.config.ts 783B
folder
create-customer-function 文件夹
file
package.json 270B
folder
src 文件夹
folder
domain 文件夹
file
create-customer-service.ts 791B
file
create-customer-repository.ts 161B
folder
infrastructure 文件夹
file
create-customer-ddb-repository.ts 623B
folder
application 文件夹
file
create-customer-processor.ts 1KB
file
app.ts 1KB
file
yarn.lock 205KB
file
template.yml 4KB
file
package.json 784B
folder
layers 文件夹
folder
application-layer 文件夹
file
package.json 449B
file
yarn.lock 19KB
folder
build 文件夹
file
package.json 648B
file
tsconfig.json 415B
file
LICENSE 1KB
file
README.md 10KB
folder
openapi 文件夹
file
customer.yaml 3KB
folder
shared 文件夹
file
package.json 649B
folder
src 文件夹
folder
customer 文件夹
file
customer-entity.ts 412B
file
customer-model.ts 319B
file
customer-api.ts 359B
file
environment.ts 118B
file
index.ts 269B
folder
common 文件夹
file
error.ts 313B
file
handler.ts 1KB
file
aws-ddb.ts 614B
file
logger.ts 211B
file
tsconfig.json 246B
file
yarn.lock 205KB
file
.editorconfig 189B
zip 文件大小:198.29KB