In part one of the blog, I covered creating Amazon templates by using images created in Amazon Web Services, which can be viewed here. While using an image to create a template is very useful internally, it lacks in reusability. As a consultant, having an arsenal of scripts and standards that I can bring to each client is very important as it allows me to produce quality work consistently and quickly.
Luckily, Amazon gives us a way to create consistent templates across different services. By using JSON, Amazon allows the creation of templates programmatically. I can define a set of parameters and commands that will allow me to deploy a robust template, and automate a lot of the steps that it manually takes to create a new virtual machine.
Why use a JSON Template?
Besides the ability to create the same template across multiple Amazon accounts there are many other benefits that come along with it. With an AMI template everything had to be setup and configured before it could be saved as an image. With JSON we can create these parameters and then allow the template to configure our new VM in the background. Also, with JSON we can link to Amazon’s storage and install and configure software with the new VM, run PowerShell Scripts for configuration, and even define a multi-tiered server farm.
All of this comes at a price though. JSON templates are not easy to setup. It takes working knowledge of JSON, and when creating large templates it will become hard to manage and debug. When deciding on a template type to use, it is important to choose one that will fit your requirements.
Anatomy of a JSON Template
Parameters are user defined variables that allow for flexibility in creating the instance. When defining a parameter a description and type are required. There are many other values that can be defined such as Default value, or allowed values. Parameters will appear on screen when executing a template so that you can input values before launching your VM stack.
The resources section is where all of the steps of the template are located. This section consists of the “AWS::CloudFormation::Init” section. This is where you will setup your configuration parameters that tell what configuration to launch and in what order. Within each configuration, you can create VM’s from AMI’s or Amazon pre-configured templates, run command prompts or PowerShell scripts, and install software that is stored within AWS.
Using a JSON Template
Once your template is fully created, you must deploy it. To deploy log into your AWS console. From there select CloudFormation from the Deployment & Management section of the console home screen. From here, select the create stack to deploy your template.
From here you can select sample templates, upload your template from your local PC, or deploy from your Amazon storage.
From here you will be asked to enter the required parameters you created within your template. Once your form is filled in, just sit back and wait for it to be created.
When to use a template
Now that we have seen both ways of creating templates in Amazon Web Services, it is important to choose the correct template for your situation. Each has its pros and cons.
While the JSON template takes more time to create, it is versatile and can be easily used in a wide variety of situations. It comes in handy when deploying large-scale environments, or multiple environments within different AWS systems.
While the AMI template is great for rolling out single use machines that you may need configured a certain way. Having a quick server that is preconfigured with software and services, creating testing or development environments becomes an easy task. Also, having a preconfigured server makes it easy to expand an existing environment that is already configured to connect to your existing environment easily, expanding and retracting for your needs.
For more information and examples of templates, click here.