Shared Resources DSL

As mentioned in Shared Resources, the sns_topic is simply a convenience method that calls the resources and output methods that add sections to the CloudFormation template. Shared Resources inherit from the Jets::Stack class. By inheriting from the Jets::Stack class, Shared Resources are provided access to a general CloudFormation template DSL. Here are the main methods of that DSL:

DSL Method Description
parameter Adds a parameter to the template.
resource Adds a resource to the template.
output Adds an output to the template.

The main methods correspond to sections of the CloudFormation anatomy sections.

Each method has long, medium and short forms. Here are some contrived examples that show their different forms:

Parameters

class ParametersExample < Jets::Stack
  # long form
  parameter(InstanceType: {
    Default: "t2.micro" ,
    Description: "instance type" ,
  })
  # medium form
  parameter :Company, Default: "boltops", Description: "instance type"
  # short form
  parameter :AmiId, "ami-123" # default is ami-123
end

Resources

class ResourcesExample < Jets::Stack
  # long form
  resource(SnsTopic: {
    Type: "AWS::SNS::Topic",
    Properties: {
      Description: "my desc",
      DisplayName: "my name",
    }
  })
  # medium form
  resource(:SnsTopic2,
    Type: "AWS::SNS::Topic",
    Properties: {
      DisplayName: "my name 2",
    }
  )
  # short form
  resource(:SnsTopic3, "AWS::SNS::Topic",
    DisplayName: "my name 3",
  )
end

Outputs

class OutputsExample < Jets::Stack
  # long form
  output(VpcId: {
    Description: "vpc id",
    Value: ref(:VpcId), # same as: Value: "!Ref VpcId"
  })
  # medium form
  output :StackName, Value: "!Ref AWS::StackName"
  # short form
  output :Elb, "!Ref Elb" # same as
               # output :Elb, Value: "!Ref Elb"
  output :Elb2 # short form, same as:
               # output :Elb2, "!Ref Elb2"

end

The DSL provides full access to creating custom CloudFormation stacks and AWS resources. It is also easy extend the DSL with your own Shared Resource Extensions. This helps you remove duplication and keep your code concise.

Note: Rubyists may notice that the keys are CamelCase, not underscore. Both underscore and CamelCase work. Jets runs a custom Camelizer to transform the keys regardless of the casing. You can use either format. Once we get near CloudFormation land, it’s easier to think on CloudFormation terms. The resource method is at the mental boundary crossing. More thoughts: CloudFomation CamelCase vs Ruby Underscore Thoughts.