Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mediafellows/s3-website-deploy
A deploy method implemented in JS for deploying FE artefacts to a AWS S3 website hosting bucket and invalidate Cloudfront cache
https://github.com/mediafellows/s3-website-deploy
javascript npm-package website-hosting
Last synced: 9 days ago
JSON representation
A deploy method implemented in JS for deploying FE artefacts to a AWS S3 website hosting bucket and invalidate Cloudfront cache
- Host: GitHub
- URL: https://github.com/mediafellows/s3-website-deploy
- Owner: mediafellows
- Created: 2025-01-20T12:39:54.000Z (21 days ago)
- Default Branch: master
- Last Pushed: 2025-01-30T13:26:39.000Z (11 days ago)
- Last Synced: 2025-01-30T13:29:08.746Z (11 days ago)
- Topics: javascript, npm-package, website-hosting
- Language: JavaScript
- Homepage:
- Size: 190 KB
- Stars: 0
- Watchers: 6
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# S3 website deploy
Provides a simple deploy method that hides all the complexity of deploying new frotend artefacts to a typical AWs S3 website hosting setup.
Only works if the [s3-website setup](https://docs.aws.amazon.com/AmazonS3/latest/userguide/HostingWebsiteOnS3Setup.html) is fronted by [Cloudfront](https://repost.aws/knowledge-center/cloudfront-serve-static-website).
Note that this can be achieved using usual infrastructure provisioners like Terraform, Cloudformation, Ansible etc. and is not the scope of this package.All you have to to is to call the deploy method with the domain name(s) you want to update (i.e. Cloudfront alias) and the local dir of the Frontend
artefacts that should be copied to S3.This deploy takes care of those steps:
1. Find Cloudfront distributions for given domain(s)
2. Extract bucket names from Cloudfront distribution(s)
3. Cleanup of S3 bucket (i.e. delete all present files)
4. Upload new files to S3 bucket(s)
5. Invalidates Cloudfront cache(s) to ensure new content is servedYou can provide a list of domains as you might want to upload the same artefacts for multiple Cloudfront distributions (or even buckets), in case you serve them with distributions for TLS cert reasons.
## Install and usage
To install from GH repo you need to add this to your `.npmrc` first:
```
@mediafellows:registry=https://npm.pkg.github.com/
```After that you can install the package with either npm or yarn like this:
```
npm install @mediafellows/[email protected]
```Once installed you can include the website deploy method like this:
```javascript
import { S3WebsiteDeploy } from '@mediafellows/s3-website-deploy';// some other code
// name of the AWS profile configured in ~/.aws/credentials to be used to the deploy
const awsProfile = 'production'
// AWS s3 bucket region
const awsRegion = 'us-east-1'
// Slack secret webhook URL (optional) to send deploy message to
const slackUrl = 'https://hooks.slack.com/services/XXX/YYY/ZZZ'const deployer = new S3WebsiteDeploy(awsProfile, awsRegion, slackUrl)
// dir with website artefacts to be uploaded to s3
const buildDir = "dist/"// domains used to select all the Cloudfront distros in question, one domain per CF distro is enough to select them
const domains = ['my-domain.bar', 'another-doman.com']// Run deploy
deployer.deploy(domains, buildDir)
```This will run the deploy for you, as desribed above. You AWS credentials should have the following permissions.
On relevant buckets:
```
"s3:List*"
"s3:Get*"
"s3:Put*"
"s3:DeleteObject"
```On relevant Cloudfront distribtions:
```
"cloudfront:CreateInvalidation"
"cloudfront:GetDistribution"
"cloudfront:GetDistributionConfig"
"cloudfront:GetInvalidation"
"cloudfront:List*"
```This module is meant to use configured credential profiles from `~/.aws/credentials`. But setting AWS ENV variables should also work.