https://github.com/traviswimer/serverless-respat-static-cloudfront
https://github.com/traviswimer/serverless-respat-static-cloudfront
Last synced: about 1 year ago
JSON representation
- Host: GitHub
- URL: https://github.com/traviswimer/serverless-respat-static-cloudfront
- Owner: traviswimer
- License: mit
- Created: 2018-07-23T16:36:10.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2018-07-26T19:00:09.000Z (almost 8 years ago)
- Last Synced: 2025-05-15T11:12:40.975Z (about 1 year ago)
- Language: JavaScript
- Size: 65.4 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# serverless-respat-static-cloudfront
> Resource pattern to setup a Cloudfront distribution for a static site hosted on S3.
## Usage
This package is intended for use with the **serverless-respat plugin**. ([install/usage info](https://github.com/traviswimer/serverless-respat)).
Install:
`npm install --save-dev serverless-respat-static-cloudfront`
Add patterns to the "custom" object in your serverless config file:
```javascript
"custom": {
"serverless-respat": {
prefix: "${self:service}-${opt:stage}",
patterns: [
{
pattern: require("serverless-respat-static-cloudfront"),
config: {
domain: "YOURDOMAIN",
region: '${self:provider.region}',
use_https: true,
default_root_object: "index.html",
certificate_arn: 'ACM_CERT_ARN',
origins: [
{
id: "ApiGatewayOrigin",
path: "/my-api",
domain: {
"Fn::Join": [
"",
[
{
// "ApiGatewayRestApi" is generated by Serverless
"Ref": "ApiGatewayRestApi"
},
".execute-api.${self:provider.region}.amazonaws.com"
]
]
},
path_pattern: "api/*"
}
]
}
}
]
}
}
```
Before this will work, you need to create an S3 bucket with the same name as your domain. A good choice for deploying your static site to the bucket is the [serverless-finch](https://github.com/fernando-mc/serverless-finch) plugin.
**You will also need to setup Route53 (or other DNS service) to point to the Cloudfront resource created**
## Config options
* **pattern_name** (string, _default: "StaticCloudfront"_) - A pattern name included in resource names.
* **use_https** (boolean, _default: true_) - If true, you site will use HTTPS
* **domain** (string, REQUIRED) - Your website domain name
* **region** (string, REQUIRED) - AWS region
* **default_root_object** (string, REQUIRED) - The root file used from your S3 bucket
* **certificate_arn** (string, REQUIRED) - The ARN for the ACM certificate to use for HTTPS
* **origins** - (array) List of objects defining the origins to include
* **id** - (string, REQUIRED) ID to use for the origin
* **path** - (string, REQUIRED) The origin path
* **path_pattern** - (string, REQUIRED) Pattern to use for the origin
* **domain** - (string, REQUIRED) The domain the origin should point to. (An API Gateway, etc.)