https://github.com/daaru00/serverless-plugin-static-website
Serverless plugin to easily deploy a static website frontend
https://github.com/daaru00/serverless-plugin-static-website
aws s3 serverless static-site
Last synced: 3 days ago
JSON representation
Serverless plugin to easily deploy a static website frontend
- Host: GitHub
- URL: https://github.com/daaru00/serverless-plugin-static-website
- Owner: daaru00
- Created: 2019-03-17T11:28:55.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2022-02-12T21:34:20.000Z (over 4 years ago)
- Last Synced: 2025-08-31T07:17:37.634Z (10 months ago)
- Topics: aws, s3, serverless, static-site
- Language: JavaScript
- Size: 90.8 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Serverless Static Website
[](https://www.npmjs.com/package/serverless-plugin-static-website)
A [serverless](https://serverless.com) plugin to create an S3 bucket to hosting your static website, it will automatically set public permissions and provide a specific deploy command.
## Usage
### Installation
```bash
$ npm install serverless-plugin-static-website --save-dev
```
or using yarn
```bash
$ yarn add serverless-plugin-static-website
```
### Configuration
```yaml
plugins:
- serverless-plugin-static-website
custom:
frontend:
bucket: ${self:service}-${self:provider.stage} # Provide a bucket name
dir: './frontend' # Set frontend directory to publish
cacheControl: '31536000' # Set max-age cache control, default: 31536000
deploy: 'sync' # Set deploy strategy to cp (upload every time all files), or sync (upload only newer files), default: sync
```
## CloudFront
If you want to enable CloudFront distribution in front of S3 bucket add `cdn` configurations to `custom.frontend` key:
```yaml
custom:
frontend:
# ...frontend configuration..
cdn:
enabled: true
aliases: # Set aliases, default empty (default CloudFront domain)
- www.mywebsite.com
priceClass: PriceClass_All # Set price class, default: PriceClass_100
certificate: 'arn:aws:acm:region:account-id:certificate/certificate-id' # Set custom certificate
```
### Website information
At the end of `serverless deploy` you will see inside "Service Information" section the websites bucket's URL:
```
Service Information
service: myservice
stage: dev
region: eu-west-1
stack: myservice-dev
resources: 6
frontend: http://myservice-test.s3-website-eu-west-1.amazonaws.com <-- here thr URL to visit
api keys:
None
endpoints:
None
functions:
hello: myservice-test-hello
layers:
None
```
## Commands
### Deploy files
Deploy static websites files:
```bash
$ serverless deploy frontend
```
this will sync your configured frontend directory with S3 bucket.
_Note: this command is a wrapper of `aws s3 cp --recursive`, so you must have the [AWS CLI](https://docs.aws.amazon.com/en_us/cli/latest/userguide/cli-chap-install.html) installed._
### Empty bucket
Remove all objects from bucket:
```bash
$ serverless remove frontend
```
### Cleaning
When you destroy the environment with `serverless remove` the created bucket will be emptied automatically to permit the deletion.