GithubHelp home page GithubHelp logo

manemarron / serverless-plugin-var-substitution Goto Github PK

View Code? Open in Web Editor NEW
0.0 0.0 0.0 640 KB

Serverless plugin to substitute variables in compiled cloudformation template

License: MIT License

JavaScript 100.00%

serverless-plugin-var-substitution's Introduction

serverless-plugin-var-substitution

Serverless plugin to substitute variables in compiled cloudformation template

Add a variable substitution syntax so that serverless can maintain the normal syntax.

This is especially useful for stage variables in a swagger definition for Api Gateway.

...
custom:
    varSubstitution:
        pattern: '##'
        variables:
        - stageVariables.ConnectionId
        - search: something_random
          replace: something_more_random
Resources:
    ApiGatewayRestApi:
        Type: AWS::ApiGateway::Deployment
        Properties:
            Body:
                paths:
                    '/some/path':
                        get:
                            x-amazon-apigateway-integration:
                                connectionId: ##stageVariables.ConnectionId##
                                otherProperty: ##something_random##
...

You just need to specify a pattern and the variables you will replace. The default pattern is ##.

The plugin is run after the serverless package command is executed.

The parameters can be configured using the custom section in the serverless.yml file:

...
custom:
    varSubstitution:
        pattern: &&
        variables:
        - 'some string word'
        - search: 'some word'
          replace: 'some other word'
...

For the above example, the plugin would search for all occurences in the compiled CloudFormation template of &&some string word&& and replace them for ${some string word} and also all occurences of &&some word&& and replace them with some other word.

Getting Started

  1. Install plugin from npm:
npm install --save-dev serverless-plugin-var-substitution
  1. Add to the plugins section of your serverless.yml:
plugins:
  - serverless-plugin-var-substitution
  1. Include variables in your CloudFormation templates.

Configuration

The plugin can be configured by setting the next parameters in the custom.varSubstitution object:

  • pattern: String. The prefix and suffix that will be searched for. Defaults to '##'.

  • variables: Array. The words that will be searched for to replace. Can be of 2 types:

    • String. Searches for the word and replaces it with ${word}
    varSubstitution:
        variables:
        - 'some word'  # transformed to ${some word}
    • Object. Searches for the word in the 'search' property and replaces it with the word in the replace property.
    varSubstitution:
        variables:
        - search: 'some word'  # transformed to 'some other word'
          replace: 'some other word'

More Info

Heavily influenced by serverless-plugin-time-substitution

serverless-plugin-var-substitution's People

Contributors

manemarron avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.