npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@capraconsulting/webapp-deploy-lambda

v2.3.0

Published

CDK construct for deploying a webapp release to S3 and CloudFront

Downloads

13,456

Readme

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:

python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt

# 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.
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.