An open API service indexing awesome lists of open source software.

https://github.com/traviswimer/serverless-respat-static-cloudfront


https://github.com/traviswimer/serverless-respat-static-cloudfront

Last synced: about 1 year ago
JSON representation

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