@capraconsulting/webapp-deploy-lambda

中文文档
2.5.201发布于 2026/11/09Apache-2.0TypeScriptES Module零依赖构建来源已验证近 30 天下载 1.3万

CDK construct for deploying a webapp release to S3 and CloudFront

原始使用文档
文档目录4 节
  1. Preserving old files
  2. Triggering a deployment
  3. Development
  4. Notes

CDK Construct for deploying a webapp release

This project contains a CDK Construct for an AWS Lambda Function to handle deployment of a bundled static web application to a S3 bucket while preserving files from previous deployments within a time threshold.

What it does:

  1. Fetch deployment log from S3
  2. Fetch bundled artifact and extract locally with optional filtering
  3. Upload all non-html files to S3
  4. Upload html files to S3
  5. Add uploaded items to deployment log
  6. Delete old items from S3
  7. Prune old deployments from deployment log
  8. Store deployment log to S3 for next run
  9. Optionally invalidate CloudFront distribution

Preserving old files

A single-page application using code splitting will cause the client to defer loading lots of files. To avoid a deployment disrupting the user, we cannot delete the previous files (e.g. using aws s3 sync --delete), as that would cause the client to get 404 errors when navigating through the app. CloudFront will in many cases hide this issue for most of the users due to its edge caches, but it will still be an issue for users that haven't updated the application since the day before.

One way of handling this would be to never delete any files from the S3 bucket. That means the bucket will fill up with a lot of old files. This project approaches it differently by deleting old files.

A user that still uses an application deployed five days ago should not be disrupted. To keep this promise we keep the newest deployment that happened more than five days ago, and delete files from older ones that no longer have any reference to them.

Triggering a deployment

aws lambda invoke \
  --function-name my-deploy-lambda \
  --payload '{
    "ResourceProperties": {
      "artifactS3Url": "s3://my-bucket/my-release.tgz"
    },
    "RequestType": "Update"
  }' \
  /tmp/out.log

Development

Testing locally:

$ uv sync

# Adjust to your project. See config.py for full list.
$ export TARGET_BUCKET_URL=s3://my-website/web
$ export EXPIRE_SECONDS=86400
$ export DEPLOY_LOG_BUCKET_URL=s3://my-website/deployments.log
$ export CF_DISTRIBUTION_ID=EKJ2IPY1KTEAR1

# Adjust artifact path.
$ uv run python -m webapp_deploy.main s3://my-bucket/my-release.tgz

Notes

  • To avoid a race condition in using and updating the deployment log, no concurrent execution of the lambda should be allowed.

版本与发布记录

@capraconsulting/webapp-deploy-lambda 共发布 232 个版本,首次发布于 2020/06/18;过去 12 个月发布了 199 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
2.5.201latest2026/11/09今天
2.5.2002026/11/081 天前
2.5.1992026/11/036 天前
2.5.1982026/11/027 天前
2.5.1972026/11/017 天前
2.5.1962026/10/319 天前

其他发布通道:alpha → 2.0.0-alpha.1。

关于 @capraconsulting/webapp-deploy-lambda 的常见问题

@capraconsulting/webapp-deploy-lambda 是什么?

CDK construct for deploying a webapp release to S3 and CloudFront

如何安装 @capraconsulting/webapp-deploy-lambda?

在项目目录运行 npm install @capraconsulting/webapp-deploy-lambda,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:constructs(^10.0.0)、aws-cdk-lib(^2.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@capraconsulting/webapp-deploy-lambda 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@capraconsulting/webapp-deploy-lambda 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@capraconsulting/webapp-deploy-lambda 可以商用吗?

@capraconsulting/webapp-deploy-lambda 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@capraconsulting/webapp-deploy-lambda 的下载量有多少?

根据 npm 官方下载统计,@capraconsulting/webapp-deploy-lambda 在 2026/10/09 – 2026/11/07 这 30 天内被下载 13,270 次,日均约 442 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@capraconsulting/webapp-deploy-lambda 还在维护吗?

最新版本 2.5.201 发布于 2026/11/09(今天);至今共发布 232 个版本,其中过去 12 个月发布了 199 个;首次发布于 2020/06/18。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。