0.0.6 • Published 7 years ago

serverless-global-templates v0.0.6

Weekly downloads
5
License
ISC
Repository
github
Last release
7 years ago

Serverless Global Templates Plugin

How to use

Install from npm

  1. Ensure your project has a valid package.json.
  2. Run npm install --save serverless-global-templates.
  3. Add serverless-global-templates to the list of plugins in serverless.yml. The plugins list is an array at the root level (an example serverless.yml is included in this project).
  4. Setup the templates under the custom property, example below.

Setup

The contents can be inlined, but creating a file for it is recommended.

serverless.yml

custom:
    globalTemplates:
        request:
            template:
                application/json: '${file(serverless.template.request)}'

serverless.template.request

#set( $body = $input.json("$") )

#define( $loop )
{
    #foreach($key in $map.keySet())
        #set( $k = $util.escapeJavaScript($key) )
        #set( $v = $util.escapeJavaScript($map.get($key)).replaceAll("\\\\'", "'") )
        "$k":
          "$v"
          #if( $foreach.hasNext ) , #end
    #end
}
#end

{
    "body": $body,
    "method": "$context.httpMethod",
    "principalId": "$context.authorizer.principalId",
    "stage": "$context.stage",
    "resourcePath" : "$context.resourcePath",
    "cognitoPoolClaims" : {
       "sub": "$context.authorizer.claims.sub"
    },
    #set( $map = $input.params().header )
    "headers": $loop,
    #set( $map = $input.params().querystring )
    "query": $loop,
    #set( $map = $input.params().path )
    "path": $loop,
    #set( $map = $context.identity )
    "identity": $loop,
    #set( $map = $stageVariables )
    "stageVariables": $loop
}
0.0.6

7 years ago

0.0.5

7 years ago

0.0.4

7 years ago

0.0.3

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago