Skip to content

Commit

Permalink
Example: delimiters
Browse files Browse the repository at this point in the history
  • Loading branch information
aielo committed Mar 16, 2020
1 parent 03f71f3 commit e42a018
Show file tree
Hide file tree
Showing 8 changed files with 123 additions and 0 deletions.
35 changes: 35 additions & 0 deletions examples/delimiters/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
### Example: Delimiters

This example demonstrates the usage of **serverless-enhanced-config** with [*custom delimiters*](https://github.com/janl/mustache.js#custom-delimiters).

`serverless.yml` is used as an entry point for the Serverless Framework and **serverless-enhanced-config**, including:
- `service` and `provider` sections, which are mandatory in the Serverless Framework
- `serverless-enhanced-config` in the plugins section
- `custom.enhancedConfig`, containing in specific **serverless-enhanced-config** settings:
- The configuration template path at `template`
- Variables to be replaced in the template under `variables`
- Partials file paths under `partials`
- Custom delimiters under `delimiters`

The *actual* serverless configuration to be used by the Serverless Framework will be generated in runtime. You can easily check that with the `print` command.

Try it with `npm`:
```
$ git clone https://github.com/aielo/serverless-enhanced-config.git
$ cd serverless-enhanced-config/examples/delimiters/
$ npm install serverless -g
$ npm install
$ sls print
```
or `yarn`:
```
...
$ yarn global add serverless
$ yarn install
$ sls print
```

For debugging output, use `SLS_EC_DEBUG`:
```
$ SLS_EC_DEBUG=1 sls print
```
19 changes: 19 additions & 0 deletions examples/delimiters/includes/api-gateway.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Resources:
GatewayResponseDefault4XX:
Type: 'AWS::ApiGateway::GatewayResponse'
Properties:
ResponseParameters:
gatewayresponse.header.Access-Control-Allow-Origin: "'*'"
gatewayresponse.header.Access-Control-Allow-Headers: "'*'"
ResponseType: DEFAULT_4XX
RestApiId:
Ref: 'ApiGatewayRestApi'
GatewayResponseDefault5XX:
Type: 'AWS::ApiGateway::GatewayResponse'
Properties:
ResponseParameters:
gatewayresponse.header.Access-Control-Allow-Origin: "'*'"
gatewayresponse.header.Access-Control-Allow-Headers: "'*'"
ResponseType: DEFAULT_5XX
RestApiId:
Ref: 'ApiGatewayRestApi'
14 changes: 14 additions & 0 deletions examples/delimiters/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "serverless-enhanced-config-delimiters",
"version": "0.1.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"serverless-dotenv-plugin": "^2.3.2"
}
}
8 changes: 8 additions & 0 deletions examples/delimiters/partials/function.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[[ function.name ]]:
handler: [[ function.handler ]]
events:
- http:
path: [[ function.path ]]
method: [[ function.method ]]
cors: [[ function.cors ]]
authorizer: aws_iam
2 changes: 2 additions & 0 deletions examples/delimiters/partials/functions.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
functions:
[[> function ]]
2 changes: 2 additions & 0 deletions examples/delimiters/partials/plugins.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
plugins:
- serverless-dotenv-plugin
26 changes: 26 additions & 0 deletions examples/delimiters/serverless.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
service: delimiters

plugins:
- ../..

provider:
name: aws

custom:
enhancedConfig:
template: template.yml
variables:
service: delimiters
function:
name: myfunc
handler: handlers/myfunc.main
path: mypath/myfunc
method: get
cors: true
partials:
plugins: partials/plugins.yml
functions: partials/functions.yml
function: partials/function.yml
delimiters:
- '[['
- ']]'
17 changes: 17 additions & 0 deletions examples/delimiters/template.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
service: [[ service ]]

package:
individually: true

[[> plugins ]]

provider:
name: aws
runtime: nodejs12.x
stage: ${opt:stage, env:stage, 'dev'}
region: ${opt:region, env:region, 'us-east-1'}

[[> functions ]]

resources:
- ${file(includes/api-gateway.yml)}

0 comments on commit e42a018

Please sign in to comment.