Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
4f34936
First pass at converting this to be more usedful for BDCS
eric-swann-q2 Jan 15, 2019
ce1eb09
First pass at converting this to be more usedful for BDCS
eric-swann-q2 Jan 15, 2019
31854e8
Updated naming to make sure it will work as a plugin
eric-swann-q2 Jan 16, 2019
e895ac1
Fixed syntax error
eric-swann-q2 Jan 16, 2019
2d61abb
Fixed syntax error
eric-swann-q2 Jan 16, 2019
ab5f58c
Fixed undefined healthCheckId
eric-swann-q2 Jan 16, 2019
246cbfe
Fixes to api registration
eric-swann-q2 Jan 16, 2019
905e0f0
Deploying to secondary
eric-swann-q2 Jan 16, 2019
331aec0
Deploying to secondary fixes
eric-swann-q2 Jan 16, 2019
b2e3bae
Updates to allow for stub deployment of an api gateway so that the ba…
eric-swann-q2 Jan 17, 2019
0e1ef85
Fixed regional routing
eric-swann-q2 Jan 17, 2019
2c071a8
Fixed health check location to point to API Gateway
eric-swann-q2 Jan 17, 2019
1345f66
Fixed health check location to point to API Gateway
eric-swann-q2 Jan 17, 2019
ea239c8
Updated documentation and prepared for publication
eric-swann-q2 Jan 19, 2019
3f0140a
Added Travis.yml
eric-swann-q2 Jan 19, 2019
fb2a6aa
Added Travis.yml
eric-swann-q2 Jan 19, 2019
d81f70a
Added Travis badge to readme
eric-swann-q2 Jan 19, 2019
30b23b1
Added some extra tests
eric-swann-q2 Jan 20, 2019
d6fb606
Added some critical unit test
eric-swann-q2 Jan 21, 2019
ed5bb5b
Updated the readme to clarify a couple of things
eric-swann-q2 Jan 21, 2019
ea1346d
Updated the readme to clarify a couple of things
eric-swann-q2 Jan 21, 2019
62d30d4
Updated the readme to clarify a couple of things
eric-swann-q2 Jan 21, 2019
17a0e44
Just a readme fix
eric-swann-q2 Jan 21, 2019
c88e0a0
Set Miniumum prototcal version
eric-swann-q2 Feb 19, 2019
2265a5c
Set Miniumum prototcal version
eric-swann-q2 Feb 19, 2019
89f3a63
Set Miniumum prototcal version
eric-swann-q2 Feb 19, 2019
912a2b8
Updated references
eric-swann-q2 Jul 30, 2019
8c6595a
Updated serverless template
eric-swann-q2 Jul 30, 2019
3b761fe
Merge pull request #3 from unbill/BDCS-1630
eric-swann-q2 Aug 5, 2019
1816d17
Added capability to specify failover type
eric-swann-q2 Sep 25, 2019
e333710
Updated git-ignore
eric-swann-q2 Sep 25, 2019
4f12232
Merge pull request #4 from unbill/Failover_Type
eric-swann-q2 Sep 26, 2019
a5fd1ec
If the DNS is configured for failover routing policy, don't specify a…
brian-creasy-q2 Sep 26, 2019
3ee45c7
Removed region property when not needed
eric-swann-q2 Sep 26, 2019
6d7b744
Removed region property when not needed
eric-swann-q2 Sep 26, 2019
eb341e6
Changes to support method dependency
eric-swann-q2 Sep 26, 2019
b9affb5
Merge from master
eric-swann-q2 Sep 26, 2019
a2a76e2
Merge pull request #7 from unbill/BDCS-1949
eric-swann-q2 Sep 27, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/test/
44 changes: 16 additions & 28 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,30 +1,18 @@
{
"env": {
"browser": true,
"commonjs": true,
"es6": true
},
"extends": "eslint:recommended",
"parserOptions": {
"ecmaVersion": 2018,
"sourceType": "module"
},
"rules": {
"indent": [
"error",
2
],
"linebreak-style": [
"error",
"unix"
],
"quotes": [
"error",
"single"
],
"semi": [
"error",
"always"
]
}
"env": {
"browser": true,
"commonjs": true,
"es6": true
},
"extends": "eslint:recommended",
"parserOptions": {
"ecmaVersion": 2018,
"sourceType": "module"
},
"rules": {
"indent": ["error", 2],
"quotes": ["error", "single"],
"semi": ["error", "never"],
"no-var": ["error", "never"]
}
}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules
*.log
.DS_Store
.npmrc
9 changes: 9 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
language: node_js
node_js:
- '8'
- '10'

install:
- npm install

script: 'npm run test'
10 changes: 10 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"eslint.validate": ["javascript"],
"eslint.autoFixOnSave": true,
"editor.tabSize": 2,
"editor.formatOnSave": true,
"prettier.singleQuote": true,
"prettier.semi": false,
"prettier.printWidth": 100,
"javascript.format.insertSpaceAfterFunctionKeywordForAnonymousFunctions": false
}
2 changes: 1 addition & 1 deletion LICESNSE → LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2018 Dante Consulting, Inc.
Copyright (c) Q2 Biller Direct Team

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
128 changes: 113 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,50 +1,148 @@
# serverless-multi-regional-plugin
# serverless-multi-region-plugin

This plugin will add the resources to configure API Gateway regional endpoints and a global endpoint with CloudFront.
[![Build Status](https://travis-ci.com/unbill/serverless-multi-region-plugin.svg?branch=master)](https://travis-ci.com/unbill/serverless-multi-region-plugin)

TLDR;
This plugin adds resources to configure API Gateway regional endpoints for the regions you specify and a global endpoint
in front of a CloudFront installation to front the regional APIs.

This plugin was forked from serverless-multi-regional-plugin, enhanced and simplified for a true turn-key experience.

## More details?

This plugin will:

- Set up API Gateways for your lambdas in each region
- Set up a custom domain in each region for the API Gateway and specify the appropriate base path
- Set up a basic HTTPS healthcheck for the API in each region
- Set up Route 53 for failover based routing with failover between regions based on the healthcheck created
- Set up CloudFormation in front of Route 53 failover with TLS 1.2 specified
- Set up Route 53 with the desired domain name in front of CloudFront

<img src="multi-regional-api.png" width="700">

1. Install plugin:
## Install plugin:

```
npm install serverless-multi-regional-plugin --save-dev
npm install serverless-multi-region-plugin --save-dev
```

2. Create your hosted zone and certificates
## Prerequisites: Create your hosted zone and certificates

Using the diagram above as an example the hosted zone would be for _example.com_ and the certificate would be for _\*.example.com_. Create the same certificate in each region to support the regional endpoints. The global endpoint requires a certificate in the us-east-1 region.

## Configuration

### Minimal configuration

> Using the diagram above as an example the hosted zone would be for _example.com_ and the certificate would be for _*.example.com_. Create the same certificate in each region to support the regional endpoints. The global endpoint requires a certificate in the us-east-1 region.
In this configuration, the necessary configuration for certificates and domain names will be derived from the primary domain name.
In addition, default healthchecks will be added for each region. It is assumed that your api has a '/healthcheck' endpoint.
See the Customized Configuration below to change the healthcheck path.

3. serverless.yml:
In your serverless.yml:

```
# Set up your plugin
plugins:
- serverless-multi-regional-plugin

# Add this to the standard SLS "custom" region
custom:
# The API Gateway method CloudFormation LogicalID to await. Defaults to ApiGatewayMethodProxyVarAny.
# Aspects of the templates must await this completion to be created properly.
gatewayMethodDependency: ApiGatewayMethodProxyVarAny

# Settings used for API Gateway and Route 53
dns:
# In this setup, almost everything is derived from this domain name
domainName: somedomain.example.com

# Settings used for CloudFront
cdn:
# Indicates which CloudFormation region deployment used to provision CloudFront (because you only need to provision CloudFront once)
region: us-east-1
```

### Customized Configuration

This is the configuration example from the original "serverless-multi-regional-plugin".
It's important to note that all of these settings can be used with the minimal configuration above
and they will override the convention-based settings.

```
# Set up your plugin
plugins:
- serverless-multi-regional-plugin

# Add this to the standard SLS "custom" region
custom:
# The API Gateway method CloudFormation LogicalID to await. Defaults to ApiGatewayMethodProxyVarAny.
# Aspects of the templates must await this completion to be created properly.
gatewayMethodDependency: ApiGatewayMethodProxyVarAny

# Settings used for API Gateway and Route 53
dns:
hostedZoneId: ZZZZZZZZZZZZZZ
domainName: ${self:service}.example.com
regionalDomainName: ${opt:stage}-${self:custom.dns.domainName}
# Explicity specify the regional domain name.
# This must be unique per stage but must be the same in each region for failover to function properly
regionalDomainName: ${self:custom.dns.domainName}-${opt:stage}
# Specify the resource path for the healthcheck (only applicable if you don't specify a healthcheckId below)
# the default is /${opt:stage}/healthcheck
healthCheckResourcePath: /${opt:stage}/healthcheck
# Settings per region for API Gateway and Route 53
us-east-1:
# Specify a certificate by its ARN
acmCertificateArn: arn:aws:acm:us-east-1:870671212434:certificate/55555555-5555-5555-5555-5555555555555555
# healthCheckId: 44444444-4444-4444-4444-444444444444
# Use your own healthcheck by it's ID
healthCheckId: 44444444-4444-4444-4444-444444444444
# Failover type (if not present, defaults to Latency based failover)
failover: PRIMARY
us-west-2:
acmCertificateArn: arn:aws:acm:us-west-2:111111111111:certificate/55555555-5555-5555-5555-5555555555555555
# healthCheckId: 33333333-3333-3333-3333-333333333333
healthCheckId: 33333333-3333-3333-3333-333333333333
failover: SECONDARY

# Settings used for CloudFront
cdn:
# Indicates which CloudFormation region deployment used to provision CloudFront (because you only need to provision CloudFront once)
region: us-east-1
# Aliases registered in CloudFront
# If aliases is not present, the domain name is set up as an alias by default.
# If *no* aliases are desired, leave an empty aliases section here.
aliases:
- ${self:custom.dns.domainName}
# headers:
# Add any headers your CloudFront requires here
headers:
- Accept
- Accept-Encoding
- Authorization
- User-Agent
- X-Forwarded-For
# Specify a price class, PriceClass_100 is the default
priceClass: PriceClass_100
# Specify your certificate explicitly by the ARN
# If the certificate is not specified, the best match certificate to the domain name is used by default
acmCertificateArn: ${self:custom.dns.us-east-1.acmCertificateArn}
# Set up logging for CloudFront
logging:
bucket: example-auditing.s3.amazonaws.com
prefix: aws-cloudfront/api/${opt:stage}/${self:service}
# webACLId:
# Add the webACLId to your CloudFront
webACLId: id-for-your-webacl
```
4. Deploy to each region

## Deploy to each region

You've got your configuration all set.

Now perform a serverless depoyment to each region you want your Lambda to operate in.
The items you have specified above are set up appropriately for each region
and non-regional resources such as CloudFront and Route 53 are also set up via CloudFormation in your primary region.

You now have a Lambda API with cross-region failover!!!

<img height="300" src="https://indiefilmto.com/wp-content/uploads/2016/05/bf93b516ffd153d5de526eac73a2d784_-success-kid-meme-needs-success-is-meme_704-396.jpg">

## Related Documentation
* [Building a Multi-region Serverless Application with Amazon API Gateway and AWS Lambda](https://aws.amazon.com/blogs/compute/building-a-multi-region-serverless-application-with-amazon-api-gateway-and-aws-lambda)

- [Building a Multi-region Serverless Application with Amazon API Gateway and AWS Lambda](https://aws.amazon.com/blogs/compute/building-a-multi-region-serverless-application-with-amazon-api-gateway-and-aws-lambda)
Loading