All Projects → santiagocardenas → serverless-cloudformation-sub-variables

santiagocardenas / serverless-cloudformation-sub-variables

Licence: MIT license
Serverless framework plugin for easily supporting AWS CloudFormation Sub intrinsic function variables

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to serverless-cloudformation-sub-variables

serverless-dynamodb-ttl
⚡️ Serverless Plugin to set DynamoDB TTL
Stars: ✭ 16 (-36%)
Mutual labels:  cloudformation, serverless-framework, serverless-plugin
cloudformation-coverage-roadmap
The AWS CloudFormation Public Coverage Roadmap
Stars: ✭ 993 (+3872%)
Mutual labels:  cloudformation, aws-cloudformation, cfn
Serverless Ide Vscode
Serverless IDE: Enhanced support for AWS SAM and CloudFormation in VS Code
Stars: ✭ 145 (+480%)
Mutual labels:  cloudformation, serverless-framework
Cloudformation Cli
The CloudFormation Provider Development Toolkit allows you to author your own resource providers and modules that can be used by CloudFormation.
Stars: ✭ 149 (+496%)
Mutual labels:  cloudformation, aws-cloudformation
cloudformation-resource-schema
The CloudFormation Resource Schema defines the shape and semantic for resources provisioned by CloudFormation. It is used by provider developers using the CloudFormation RPDK.
Stars: ✭ 77 (+208%)
Mutual labels:  cloudformation, aws-cloudformation
Perun
A command-line validation tool for AWS Cloud Formation that allows to conquer the cloud faster!
Stars: ✭ 82 (+228%)
Mutual labels:  cloudformation, aws-cloudformation
Cfn Python Lint
CloudFormation Linter
Stars: ✭ 1,770 (+6980%)
Mutual labels:  cloudformation, aws-cloudformation
Docs
Rapid CloudFormation: Modular, production ready, open source.
Stars: ✭ 209 (+736%)
Mutual labels:  cloudformation, aws-cloudformation
Quickstart Taskcat Ci
AWS Quick Start Team
Stars: ✭ 57 (+128%)
Mutual labels:  cloudformation, aws-cloudformation
StackJanitor
StackJanitor is a serverless, event-driven stack cleanup tool.
Stars: ✭ 37 (+48%)
Mutual labels:  cloudformation, cfn
serverless-discord-bot
A serverless Discord Bot template built for AWS Lambda based on Discord's slash commands and the slash-create library.
Stars: ✭ 37 (+48%)
Mutual labels:  cloudformation, aws-cloudformation
serverless-plugin-offline-kinesis-events
⚡ Serverless plugin that works with serverless-offline to allow offline testing of Serverless functions that are triggered by Kinesis events.
Stars: ✭ 15 (-40%)
Mutual labels:  serverless-framework, serverless-plugin
aws-cfn-ses-domain
AWS CloudFormation resources for Amazon SES domain and email identities
Stars: ✭ 45 (+80%)
Mutual labels:  cloudformation, aws-cloudformation
Cform Vscode
CloudFormation extension for Visual Studio Code
Stars: ✭ 73 (+192%)
Mutual labels:  cloudformation, aws-cloudformation
Cloudformation
Some CF templates
Stars: ✭ 123 (+392%)
Mutual labels:  cloudformation, aws-cloudformation
Cfn Create Or Update
Create or update CloudFormation stack also if no updates are to be performed.
Stars: ✭ 59 (+136%)
Mutual labels:  cloudformation, aws-cloudformation
Aws Cf Templates
A cloudonaut.io project. Engineered by widdix.
Stars: ✭ 2,399 (+9496%)
Mutual labels:  cloudformation, aws-cloudformation
serverless-fission
Use Fission through Serverless Framework https://serverless.com
Stars: ✭ 19 (-24%)
Mutual labels:  serverless-framework, serverless-plugin
Shorty.sls
Serverless URL shortener written in Python3 using the serverless framework
Stars: ✭ 35 (+40%)
Mutual labels:  cloudformation, serverless-framework
Aws Unifi Controller
Example of a Ubiquiti Unifi Controller in AWS using Network Load Balancer for TLS termination
Stars: ✭ 37 (+48%)
Mutual labels:  cloudformation, aws-cloudformation

serverless-cloudformation-sub-variables

Serverless framework plugin for easily supporting AWS CloudFormation Sub function variables

Add AWS CloudFormation Fn::Sub superpowers to your serverless.yml.

This includes:

  • Template parameter names e.g. ${SomeParameter}
  • Resource logical IDs e.g. ${SomeResource}
  • Resource attributes e.g. ${SomeResource.Attribute}
  • Pseudo parameters e.g. ${AWS::Region}
  • Literal variables e.g. ${!LiteralVariable}
  • Sub functions with key-value maps

The trick is to use #{Something} instead of ${Something} in your serverless.yml.

The plugin, during the package command, converts all the Sub function variables after the serverless variables are referenced and resolved, but before the CloudFormation template is packaged.

As part of the conversion, the Fn::Sub wrapper is also added to the string. That is, something like #{Foo}-Bar-#{AWS::Region} is converted to {"Fn::Sub": "${Foo}-Bar-${AWS::Region}"}. If Fn::Sub is already included in the direct parent node that contains the string with Sub function variables, then the Fn::Sub wrapper is not added (this is the case when declaring Sub functions with key-value maps or when you want to be more explicit in your serverless.yml).

This means that you can turn something like this:

service: awesome-service

plugins:
  - serverless-cloudformation-sub-variables
...
resources:
...
  Resources:
    SomeResource:
      Properties:
        SomeProperty:
          Fn::Sub:
          - '#{CustomVariable}-XYZ'
          - CustomVariable:
              Fn::ImportValue: ABC-#{AWS::StackName}
  Outputs:
    MyBaseURL:
      Value: https://#{ApiGatewayRestApi}.execute-api.#{AWS::Region}.amazonaws.com/${self:provider.stage}
      Export:
        Name: MyBaseURL
...

Into something like this:

...
  "Resources": {
    "SomeResource": {
      "Properties": {
        "SomeProperty": {
          "Fn::Sub": [
            "${CustomVariable}-XYZ",
            {
              "CustomVariable": {
                "Fn::ImportValue": {
                  "Fn::Sub": "ABC-${AWS::StackName}"
                }
              }
            }
          ]
        }
      }
    }
  }
  "Outputs": {
    "MyBaseURL": {
      "Value": {
        "Fn::Sub": "https://${ApiGatewayRestApi}.execute-api.${AWS::Region}.amazonaws.com/dev"
      },
      "Export": {
        "Name": "MyBaseURL"
      }
    }
  }
...

This works with anything in your serverless.yml that ends up in the Serverless service's CloudFormation template, including the Resources and Outputs sections (and virtually every other location where Fn::Sub is supported).

Getting Started

  1. Install plugin from npm:
npm install serverless-cloudformation-sub-variables
  1. Add to the plugins section of your serverless.yml:
plugins:
  - serverless-cloudformation-sub-variables
  1. Include strings in your serverless.yml that have Sub variables as #{Something} instead of ${Something}

More Info

Took a bit of inspiration from the following Serverless plugins, while looking for a more generic and simpler way to convert all kinds of non-custom Fn::Sub variables, anywhere in the Serverless service's CloudFormation template:

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].