Templates

As we have already mentioned, we will be providing a specification document called a Template to the service. A template can be created in a text editor and written either in JSON or YAML. We can also use the AWS CloudFormation Designer or any other What You See Is What You Get (WYSIWYG) design tool that's compatible with AWS CloudFormation. In the template, we define each resource and how that resource should be configured. Within a template, we will find the following sections:

  • AWS Template Format VersionThe AWS Template Format Version is an optional component of the template and will denote the CloudFormation template version that the template conforms to.
  • DescriptionThe description can include any arbitrary string of text that will help us to understand what the template does and what services are deployed. The description must always follow the template format version section, otherwise it is optional.
  • MetadataIn the metadata section, we can optionally include any information that we would like to pass to the services and instances that are being deployed. This can be represented as tags or other information that needs to be passed on to the environment.
  • ParametersThe parameters represent the values to be passed to the resources section. This is an optional part of the template that can be used whenever creating a resource and when we would like certain information to be provided at run time into the configuration of the resource. For example, an instance type can be specified as a parameter to an EC2 resource that's being created.
  • MappingsMappings can optionally be created to apply the appropriate parameters to the appropriate environment or region. For example, we can create mappings for the AMI ID to use, depending on the region that the CloudFormation template is being deployed in.
  • ConditionsConditions can optionally determine whether a resource is created or not, depending on a certain value. For example, we can create a condition that creates a load balancer and an autoscaling group for the application, but only when the environment tags denote the deployment as production.
  • TransformThe Transform section can optionally be used with AWS Serverless components such as AWS Lambda to define specifics and versions of the AWS Serverless Application Model to be used in the template.
  • ResourcesThis is the only mandatory part of the template as it defines the actual resources that the CloudFormation service will be creating. Here, we specify all of our networks, routers, gateways, EC2 instances, databases, S3 buckets, and so on.
  • OutputsWhen required, we can use the Outputs section to return a certain piece of information upon deployment. For example, when creating a load balancer, we would like to know the address of the load balancer instead of having to look it up with a separate task. We can simply specify the URL of the load balancer to be outputted upon template creation.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset