cfndsl-slides



cfndsl-slides

0 0


cfndsl-slides


On Github stevenjack / cfndsl-slides

CFNDSL

Steven Jack

  • Contract developer at the BBC
  • Started working on the world service sites
  • Now part of the Core team for responsive news
  • Worked on a number on a couple of projects in cosmos (kaleidoscope & election-data)
Welcome everyone, and all listening in salford.

Talk contents

  • What is CFNDSL?
  • Examples
  • Why did we choose it?
  • How has it helped us?
  • How did we build upon it?
  • Questions
N/A

What is CFNDSL?

"The cnfdsl gem provides a simple DSL that allows you to write equivalent templates in a more friendly language and generate the correct json templates from the CLI"

CloudFormation {
  Description "Test"

  Parameter("One") {
    String
    Default "Test"
    MaxLength 15
  }

  Output(:One,FnBase64( Ref("One")))

  Resource("MyInstance") {
    Type "AWS::EC2::Instance"
    Property("ImageId","ami-14341342")
  }

}
  • Clean DSL format and easy to read
  • CLI tool that is passed the template to generate the JSON from
  • Validates the resource types and properties and checks for invalid refs

What is CFNDSL?

bash-3.2$ cfndsl /path/to/my/template.rb

{
    "AWSTemplateFormatVersion": "2010-09-09",
    "Description": "Test",
    "Outputs": {
        "One": {
            "Value": {
                "Fn::Base64": {
                    "Ref": "One"
                }
            }
        }
    },
    "Parameters": {
        "One": {
            "Default": "Test",
            "MaxLength": 15,
            "Type": "String"
        }
    },
    "Resources": {
        "MyInstance": {
            "Properties": {
                "ImageId": "ami-14341342"
            },
            "Type": "AWS::EC2::Instance"
        }
    }
}
  • Clean DSL format and easy to read
  • CLI tool that is passed the template to generate the JSON from
  • Validates the resource types and properties and checks for invalid refs

Examples

AWS::SQS::Queue (DSL)

Parameter "SQSRetentionPeriod" do
  String
  Description "The Retention period for the queues generated in this example"
end

queues = [
  'TestOne',
  'TestTwo'
]

queues.each do |name|

  Resource "#{name}Queue" do
    Type "AWS::SQS::Queue"
    Property "MessageRetentionPeriod", Ref("SQSRetentionPeriod")
  end

end

Examples

AWS::AutoScaling::AutoScalingGroup (Output)

{
    "AWSTemplateFormatVersion": "2010-09-09",
    "Parameters": {
        "SQSRetentionPeriod": {
            "Default": 300,
            "Description": "The Retention period for the queues generated in this example",
            "Type": "String"
        }
    },
    "Resources": {
        "TestOneQueue": {
            "Properties": {
                "MessageRetentionPeriod": {
                    "Ref": "SQSRetentionPeriod"
                }
            },
            "Type": "AWS::SQS::Queue"
        },
        "TestTwoQueue": {
            "Properties": {
                "MessageRetentionPeriod": {
                    "Ref": "SQSRetentionPeriod"
                }
            },
            "Type": "AWS::SQS::Queue"
        }
    }
}
end

Examples

AWS::SQS::Queue (Output)

{
    "AWSTemplateFormatVersion": "2010-09-09",
    "Parameters": {
        "SQSRetentionPeriod": {
            "Default": 300,
            "Description": "The Retention period for the queues generated in this example",
            "Type": "String"
        }
    },
    "Resources": {
        "TestOneQueue": {
            "Properties": {
                "MessageRetentionPeriod": {
                    "Ref": "SQSRetentionPeriod"
                }
            },
            "Type": "AWS::SQS::Queue"
        },
        "TestTwoQueue": {
            "Properties": {
                "MessageRetentionPeriod": {
                    "Ref": "SQSRetentionPeriod"
                }
            },
            "Type": "AWS::SQS::Queue"
        }
    }
}
end

Examples

The samples folder in the cfndsl repo has an example that builds the standard cloudformation autoscaling template:

Why did we choose it?

  • The frameworks supplied python tool didn't have ElastiCache support.
  • We wanted something that would allow us to model our cloudformation in something other than JSON.
  • The election-data components were written in ruby.
  • It was the most active ruby based cloudformation repo at the time of investigation.

How has it helped us?

  • We now have our infrastructure modelled in the same language as our applications.
  • We can use ruby to keep our templates DRY.
  • Editing the templates is substantially easier than with pure JSON.

Why did we build upon it?

  • Managing stacks still required the parameters to be manually updated through the GUI.
  • Updating multiple components with shared resources was time consuming.
  • Didn't want to be leaving the terminal!

Why did we build upon it?

gem install bbc-cosmos-tools

bash-3.2$ bbc-cosmos-tools stack update election-data-renderer --env=test
  • CLI tool for removing some of the complexities of managing multiple components in cosmos.
  • Allows stack, deployment and config related tasks to be performed against the cosmos API.
  • One central place to store all resources and configuration for a given project.
  • Talk about SQS queue ARN for IAM Role and Queue name for renderer

Questions?

Thank you