Packages

package model

A DSL to create consistent, type-safe AWS CloudFormation templates.

The low-level DSL closely adheres to the objects and parameters in the CloudFormation template JSON specification. If you intend to use this DSL to create CloudFormation templates, it would behoove you to familiarize yourself with the CloudFormation documentation.

In addition to the low-level, DSL, there are several higher-order builders and convenience methods. See com.monsanto.arch.cloudformation.model.simple.Builders for more information on these helper methods.

For a discussion of the features and approach of this library, read our blog post.

Sample usage:

import com.monsanto.arch.cloudformation.model._
import com.monsanto.arch.cloudformation.model.resource._
import com.monsanto.arch.cloudformation.model.simple.Builders._

object SimpleVPC extends VPCWriter {
  val ownerParameter = StringParameter(
    name = "Owner",
    Description = Some("Individual responsible for this template"),
    MinLength = Some(StringBackedInt(1)),
    MaxLength = Some(StringBackedInt(64)),
    AllowedPattern = Some("[-_ a-zA-Z0-9]*"),
    ConstraintDescription = Some("Can contain only alphanumeric characters, spaces, dashes and underscores.")
  )
  val keyNameParameter = `AWS::EC2::KeyPair::KeyName_Parameter`(
    name = "KeyName",
    Description = Some("Name of an existing EC2 KeyPair to enable SSH access to the instances"),
    ConstraintDescription = Some("Value must be a valid AWS key pair name in your account.")
  )
  val allowSSHFromParameter = CidrBlockParameter(
    name = "AllowSSHFrom",
    Description = Some("The net block (CIDR) that SSH is available to.")
  )
  val simpleParameters = Seq(
    ownerParameter,
    keyNameParameter,
    allowSSHFromParameter
  )

  val simpleConditions = Seq(
    Condition(
      name = "ShouldDisablePassword",
      function = `Fn::Equals`(
        a = ParameterRef(ownerParameter),
        b = StringToken("rms")
      )
    )
  )

  val amazonLinuxAMIMapping = Mapping[AMIId](
    "AmazonLinuxAMI",
    Map(
      "us-east-1"      -> Map("AMI" -> AMIId("ami-1ecae776")),
      "us-west-1"      -> Map("AMI" -> AMIId("ami-d114f295")),
      "us-west-2"      -> Map("AMI" -> AMIId("ami-e7527ed7")),
      "eu-west-1"      -> Map("AMI" -> AMIId("ami-a10897d6")),
      "ap-southeast-1" -> Map("AMI" -> AMIId("ami-68d8e93a")),
      "ap-southeast-2" -> Map("AMI" -> AMIId("ami-fd9cecc7")),
      "ap-northeast-1" -> Map("AMI" -> AMIId("ami-cbf90ecb"))
    )
  )
  val simpleMappings = Seq(amazonLinuxAMIMapping)

  val simpleResourceAndOutputs = withVpc(CidrBlock(10, 0, 0, 0, 16)) { implicit vpc =>
    val (internetGatewayResource, gatewayToInternetResource) = withInternetGateway
    val publicRouteTable = withRouteTable("Public", 1)
    val publicRouteTableRoute = publicRouteTable.withRoute(
      visibility = "Public",
      routeTableOrdinal = 1,
      routeOrdinal = 1,
      connectionBobber = InternetGatewayRoute(ResourceRef(internetGatewayResource))
    )
    val gatewayStuff = Template.fromResource(internetGatewayResource) ++
      gatewayToInternetResource ++
      publicRouteTable ++
      publicRouteTableRoute
    val withinAZ = withAZ("us-east-1a") { implicit az =>
      withSubnet("PubSubnet1", CidrBlock(10, 0, 0, 1, 24)) { implicit pubSubnet =>
        val bastionName = "bastion"
        val bastion = ec2(
          name = bastionName,
          InstanceType = "t2.micro",
          KeyName = ParameterRef(keyNameParameter),
          ImageId = `Fn::FindInMap`[AMIId](MappingRef(amazonLinuxAMIMapping), `AWS::Region`, "AMI"),
          SecurityGroupIds = Seq(),
          Tags = AmazonTag.fromName(bastionName),
          UserData = Some(`Fn::Base64`(
            `Fn::Join`("",
              Seq[Token[String]](
                "#!/bin/bash -v\n",
                "yum update -y --security\n",
                "# EOF\n"
              )
            )
          ))
        )
        val sshToBastion = ParameterRef(allowSSHFromParameter) ->- 22 ->- bastion
        Template.fromSecurityGroupRoutable(bastion) ++
          bastion.map(_.withEIP("BastionEIP").andOutput("BastionEIP", "Bastion Host EIP")) ++
          Template.collapse(sshToBastion)
      }
    }
    gatewayStuff ++
      withinAZ
  }
  val simpleTemplate = simpleResourceAndOutputs ++
    Template(
      AWSTemplateFormatVersion = Some("2010-09-09"),
      Description = Some("Simple template"),
      Parameters = Some(simpleParameters),
      Conditions = Some(simpleConditions),
      Mappings = Some(simpleMappings),
      Resources = Seq.empty,
      Outputs = None
    )
  writeStaxModule("vpc-simple.json", simpleTemplate)
}
SimpleVPC

The above code utilizes the DSL to create a simple AWS VPC utilizing a single Availability Zone having a single public subnet and a single "bastion" instance. The template output is the IP address of the EIP it creates. It also shows examples of creating and using Parameters and Mappings. A Condition is created but not used.

Linear Supertypes
AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. model
  2. AnyRef
  3. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Type Members

  1. case class AMIIdParameter(name: String, Description: Option[String], Default: Option[Token[MappingRef[AMIId]]], AllowedValues: Option[Seq[String]], ConstraintDescription: Option[String], ConfigDefault: Option[String] = None) extends Parameter with Product with Serializable
  2. case class AWS::EC2::KeyPair::KeyName_Parameter(name: String, Description: Option[String], ConstraintDescription: Option[String] = None, Default: Option[String] = None, ConfigDefault: Option[String] = None) extends Parameter with Product with Serializable
  3. case class AWS::EC2::SecurityGroup_Parameter(name: String, Description: Option[String], Default: Option[Token[ResourceRef[AWS::EC2::SecurityGroup]]] = None, ConfigDefault: Option[String] = None) extends Parameter with Product with Serializable
  4. case class AWS::EC2::Subnet_Parameter_List(name: String, Description: Option[String], ConfigDefault: Option[String] = None) extends Parameter with Product with Serializable
  5. case class AWS::EC2::VPC_Parameter(name: String, Description: Option[String], Default: Option[VpcId] = None, ConfigDefault: Option[String] = None) extends Parameter with Product with Serializable
  6. case class AWS::RDS::DBInstance::Engine_Parameter(name: String, Description: Option[String], Default: Option[Token[AWS::RDS::DBInstance::Engine]] = None, ConfigDefault: Option[String] = None) extends Parameter with Product with Serializable
  7. case class AWS::RDS::DBSubnetGroup_Parameter(name: String, Description: Option[String], Default: Option[String] = None, ConfigDefault: Option[String] = None) extends Parameter with Product with Serializable
  8. sealed abstract class AmazonFunctionCall[LogicalReturnType] extends AnyRef

    Created by Ryan Richt on 2/15/15

  9. case class AnyToken[R](value: R)(implicit evidence$11: JsonFormat[R]) extends Token[R] with Product with Serializable
  10. implicit final class AwsStringInterpolator extends AnyVal

    Provides a string interpolator to assist in the concatenation of

    Provides a string interpolator to assist in the concatenation of

    The following:

    import com.monsanto.arch.cloudformation.model._
    
    val param = ParameterRef(StringParameter("that"))
    val fun = aws"test$param"

    Will generate the following FunctionCall definition:

    FunctionCallToken(`Fn::Join`("", Seq(StringToken("test"), param)))
  11. case class BooleanParameter(name: String, Description: Option[String] = None, Default: Option[Boolean] = None, ConfigDefault: Option[String] = None) extends Parameter with Product with Serializable
  12. case class BooleanToken(value: Boolean) extends Token[Boolean] with Product with Serializable
  13. case class CidrBlockListParameter(name: String, Description: Option[String], Default: Option[Seq[CidrBlock]] = None, ConfigDefault: Option[String] = None) extends Parameter with Product with Serializable
  14. case class CidrBlockParameter(name: String, Description: Option[String], Default: Option[CidrBlock] = None, ConfigDefault: Option[String] = None) extends Parameter with Product with Serializable
  15. case class Condition(name: String, function: Token[String]) extends Product with Serializable

    Created by bkrodg on 2/16/15.

  16. case class ConditionFnRef(c: Condition) extends NestableAmazonFunctionCall[String] with Product with Serializable
  17. sealed trait ConditionFunctionNestable[LogicalReturnType] extends AnyRef
  18. case class ConditionRef(c: Condition) extends Product with Serializable
  19. class EnumFormat[T] extends JsonFormat[T]
  20. case class Fn::And(fn: Seq[ConditionFunctionNestable[String]]) extends NestableAmazonFunctionCall[String] with Product with Serializable
  21. case class Fn::Base64(toEncode: Token[String]) extends AmazonFunctionCall[String] with Product with Serializable
  22. case class Fn::Equals(a: Token[String], b: Token[String]) extends NestableAmazonFunctionCall[String] with Product with Serializable
  23. case class Fn::FindInMap[R](mapName: Token[MappingRef[R]], outerKey: Token[String], innerKey: Token[String]) extends AmazonFunctionCall[String] with Product with Serializable
  24. case class Fn::GetAZs(region: Token[String]) extends AmazonFunctionCall[Seq[String]] with Product with Serializable
  25. case class Fn::GetArtifactAtt(artifactName: String, attributeName: String) extends AmazonFunctionCall[String] with Product with Serializable
  26. case class Fn::GetAtt(args: Seq[String]) extends AmazonFunctionCall[String] with Product with Serializable
  27. case class Fn::GetParam(artifactName: String, jsonFileName: String, keyName: String) extends AmazonFunctionCall[String] with Product with Serializable
  28. case class Fn::If[R](conditionName: Token[ConditionRef], valIfTrue: Token[R], valIfFalse: Token[R])(implicit evidence$2: JsonFormat[R]) extends AmazonFunctionCall[R] with Product with Serializable
  29. case class Fn::ImportValue(importValue: Token[String]) extends AmazonFunctionCall[String] with Product with Serializable
  30. case class Fn::Join(joinChar: String, toJoin: Seq[Token[String]]) extends AmazonFunctionCall[String] with Product with Serializable
  31. case class Fn::Not(fn: ConditionFunctionNestable[String]) extends NestableAmazonFunctionCall[String] with Product with Serializable
  32. case class Fn::Or(fn: Seq[ConditionFunctionNestable[String]]) extends NestableAmazonFunctionCall[String] with Product with Serializable
  33. case class Fn::Select[R](index: Token[StringBackedInt], listOfObjects: Token[Seq[R]])(implicit evidence$1: JsonFormat[R]) extends AmazonFunctionCall[R] with Product with Serializable
  34. case class Fn::Split(delimiterChar: String, toSplit: Token[String]) extends AmazonFunctionCall[Seq[String]] with Product with Serializable
  35. case class Fn::Sub(template: Token[String], subs: Option[Map[Token[String], Token[String]]] = None) extends AmazonFunctionCall[String] with Product with Serializable
  36. case class FunctionCallSeqToken[R](call: AmazonFunctionCall[Seq[R]]) extends Token[Seq[R]] with Product with Serializable
  37. case class FunctionCallToken[R](call: AmazonFunctionCall[R]) extends Token[R] with Product with Serializable
  38. trait HasTemplate extends AnyRef
  39. case class If[R](conditionName: Token[String], valIfTrue: Token[R], valIfFalse: Token[String] = `AWS::NoValue`)(implicit evidence$3: JsonFormat[R]) extends AmazonFunctionCall[R] with Product with Serializable
  40. case class InputParameter(ParameterKey: String, ParameterValue: JsValue = "<changeMe>".toJson) extends Product with Serializable
  41. case class IntToken(value: Int) extends Token[Int] with Product with Serializable
  42. case class JsonWritable[T](thing: T)(implicit evidence$1: JsonWriter[T]) extends Product with Serializable

    Wrapper for anything that can be written to Json.

    Wrapper for anything that can be written to Json. Useful to allow specifying a Map of String -> JsonWritable that can take any value that can be written out as Json.

  43. case class Mapping[A](name: String, map: Map[String, Map[String, A]])(implicit formatter: JsonFormat[A]) extends Product with Serializable

    Created by Ryan Richt on 2/15/15

  44. case class MappingRef[R](m: Mapping[R]) extends Product with Serializable
  45. sealed abstract class NestableAmazonFunctionCall[LogicalReturnType] extends AmazonFunctionCall[LogicalReturnType] with ConditionFunctionNestable[LogicalReturnType]
  46. case class NumberParameter(name: String, Description: Option[String] = None, MinValue: Option[StringBackedInt] = None, MaxValue: Option[StringBackedInt] = None, ConstraintDescription: Option[String] = None, Default: Option[StringBackedInt] = None, AllowedValues: Option[Seq[StringBackedInt]] = None, ConfigDefault: Option[String] = None) extends Parameter with Product with Serializable
  47. case class Output[R](name: String, Description: Option[String] = None, Value: Token[R], Export: Option[Token[String]] = None)(implicit format: JsonFormat[Token[R]]) extends Product with Serializable

    Created by Ryan Richt on 2/15/15

  48. sealed abstract class Parameter extends AnyRef

    Created by Ryan Richt on 2/15/15

  49. case class ParameterRef[R](p: Parameter { type Rep = R }) extends AmazonFunctionCall[R] with Product with Serializable
  50. sealed abstract class PseudoParameterRef extends Token[String]
  51. case class ResourceRef[R <: Resource[R]](r: R) extends AmazonFunctionCall[R] with Token[String] with Product with Serializable
  52. case class StringBackedInt(value: Int) extends Product with Serializable
  53. case class StringListParameter(name: String, Description: Option[String] = None, Default: Option[Seq[String]] = None, NoEcho: Option[Boolean] = None, ConfigDefault: Option[String] = None) extends Parameter with Product with Serializable
  54. case class StringParameter(name: String, Description: Option[String] = None, MinLength: Option[StringBackedInt] = None, MaxLength: Option[StringBackedInt] = None, AllowedPattern: Option[String] = None, ConstraintDescription: Option[String] = None, Default: Option[String] = None, AllowedValues: Option[Seq[String]] = None, NoEcho: Option[Boolean] = None, ConfigDefault: Option[String] = None) extends Parameter with Product with Serializable
  55. case class StringToken(value: String) extends Token[String] with Product with Serializable
  56. case class Template(Description: Option[String] = None, Parameters: Option[Seq[Parameter]] = None, Conditions: Option[Seq[Condition]] = None, Mappings: Option[Seq[Mapping[_]]] = None, Resources: Seq[Resource[_]], Routables: Option[Seq[SecurityGroupRoutable[_ <: Resource[_]]]] = None, Outputs: Option[Seq[Output[_]]] = None, AWSTemplateFormatVersion: Option[String] = None) extends Product with Serializable

    Template is the container for all the elements of your AWS CloudFormation template.

    Template is the container for all the elements of your AWS CloudFormation template.

    // create the template
    val simpleTemplate = Template(
      Description = Some("Simple S3 Bucket Template"),
      Resources = Seq(
        `AWS::S3::Bucket`(
          name = "S3Bucket",
          BucketName = Some("UniqueBucketForSimpleTemplate")
        )
      )
    )
    Description

    See description

    Parameters

    See parameters

    Conditions

    See conditionals

    Mappings

    See mappings

    Resources

    See resources

    Outputs

    See outputs

    AWSTemplateFormatVersion

    See version

  57. trait TemplateBase extends HasTemplate

    Finds all val/lazy val/def in the class (using reflection) that produce elements of a template and builds a template from them.

    Finds all val/lazy val/def in the class (using reflection) that produce elements of a template and builds a template from them. This search for:

    • Parameter
    • Condition
    • Mapping
    • Resource
    • SecurityGroupRoutable
    • Output
    • Template
    • HasTemplate
  58. sealed trait Token[R] extends AnyRef
  59. case class UNSAFEFunctionCallToken[R](call: AmazonFunctionCall[String]) extends Token[R] with Product with Serializable
  60. trait VPCWriter extends AnyRef

    Created by Ryan Richt on 6/19/15

  61. case class UNSAFEToken[R](value: String) extends Token[R] with Product with Serializable
    Annotations
    @deprecated
    Deprecated

    (Since version Feb 20 2015) use ParameterRef or ResourceRef instead

Value Members

  1. implicit def eitherAfuncA2OptionEitherAfuncA[A](v: Either[A, AmazonFunctionCall[A]]): Option[Either[A, Token[A]]]
  2. implicit val instantFormat: JsonFormat[Instant]
  3. implicit def lift2Option[A](a: A): Option[A]
  4. implicit def parameter2TokenString(parameter: StringParameter): Token[String]
  5. implicit lazy val stringTokenFormat: JsonFormat[Token[String]]

    This is to assist in creating Output[Token[String]] objects as it allows the formatter to be in scope.

  6. object AMIIdParameter extends DefaultJsonProtocol with Serializable
  7. object AWS::AccountId extends PseudoParameterRef with Product with Serializable
  8. object AWS::EC2::KeyPair::KeyName_Parameter extends DefaultJsonProtocol with Serializable
  9. object AWS::EC2::SecurityGroup_Parameter extends DefaultJsonProtocol with Serializable
  10. object AWS::EC2::Subnet_Parameter_List extends DefaultJsonProtocol with Serializable
  11. object AWS::EC2::VPC_Parameter extends DefaultJsonProtocol with Serializable
  12. object AWS::NoValue extends PseudoParameterRef with Product with Serializable
  13. object AWS::NotificationARNs extends PseudoParameterRef with Product with Serializable
  14. object AWS::RDS::DBInstance::Engine_Parameter extends DefaultJsonProtocol with Serializable
  15. object AWS::RDS::DBSubnetGroup_Parameter extends DefaultJsonProtocol with Serializable
  16. object AWS::Region extends PseudoParameterRef with Product with Serializable
  17. object AWS::StackId extends PseudoParameterRef with Product with Serializable
  18. object AWS::StackName extends PseudoParameterRef with Product with Serializable
  19. object AmazonFunctionCall extends DefaultJsonProtocol
  20. object AwsStringInterpolation

    Created by Tyler Southwick on 11/20/15.

  21. object BooleanParameter extends DefaultJsonProtocol with Serializable
  22. object CidrBlockListParameter extends DefaultJsonProtocol with Serializable
  23. object CidrBlockParameter extends DefaultJsonProtocol with Serializable
  24. object Condition extends DefaultJsonProtocol with Serializable
  25. object ConditionRef extends DefaultJsonProtocol with Serializable
  26. object Fn::Base64 extends DefaultJsonProtocol with Serializable
  27. object Fn::ImportValue extends Serializable
  28. object Fn::Sub extends Serializable
  29. object HasTemplate
  30. object InputParameter extends DefaultJsonProtocol with Serializable
  31. object JsonWritable extends Serializable
  32. object Mapping extends DefaultJsonProtocol with Serializable
  33. object MappingRef extends DefaultJsonProtocol with Serializable
  34. object NumberParameter extends DefaultJsonProtocol with Serializable
  35. object Output extends DefaultJsonProtocol with Serializable
  36. object Parameter extends DefaultJsonProtocol
  37. object ParameterRef extends DefaultJsonProtocol with Serializable
  38. object PseudoParameterRef extends DefaultJsonProtocol
  39. object ResourceRef extends DefaultJsonProtocol with Serializable
  40. object StringBackedInt extends DefaultJsonProtocol with Serializable
  41. object StringListParameter extends DefaultJsonProtocol with Serializable
  42. object StringParameter extends DefaultJsonProtocol with Serializable
  43. object Template extends DefaultJsonProtocol with Serializable
  44. object TemplateBase
  45. object Token extends DefaultJsonProtocol

Inherited from AnyRef

Inherited from Any

Ungrouped