Skip to content
Branch: master
Find file History
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
..
Failed to load latest commit information.
.gitignore
README.md
handler.py
serverless.yml
template.yaml
test_handler.py

README.md

Python-style formating macro

This directory contains a CloudFormation macro to add Python-style string formating to your CloudFormation template.

With it, you'll be able to do formatting as follows:

Parameters:
  stage:
    Type: String
    Default: dev
    AllowedValues:
      - dev
      - staging
      - prod
Resources:
  MySNSTopic:
    Type: AWS::SNS::Topic
    Properties:
      TopicName: "MyTopic-{stage}" # <-- Python templating
Transform:
  - VariableSubstitution

For a full walkthrough on how and why to use this, check out my blog post on CloudFormation macros.

Usage

After cloning this directory, you can use this macro as follows:

  1. Deploy and register the macro in your AWS account.

    Install the Serverless Framework to easily deploy Lambda functions.

    Then, run serverless deploy to deploy the macro and register it as VariableSubstitution in your AWS account.

  2. Use the macro in your CloudFormation templates:

    Use the macro by adding a Transform property to your CloudFormation template:

    Resources:
      MySNSTopic:
        Type: AWS::SNS::Topic
        Properties:
          TopicName: "MyTopic-{stage}" # <-- Python templating
    Transform:
      - VariableSubstitution
    There is a template provided in `template.yaml` that you can deploy with the following command:
    
    aws cloudformation deploy \
      --stack-name sns-topic-variables \
      --template-file template.yaml
You can’t perform that action at this time.