auremar - Fotolia
Deploying and configuring AWS resources can be time consuming and error-prone. If you ever had to configure an application stack using someone else's janky documentation, you will appreciate AWS CloudFormation.
Amazon Web Services (AWS) CloudFormation allows developers to capture the state of existing platforms, tailor them to additional requirements and redeploy them as needed, in an automated way. It is designed to streamline the process of managing resources, such as storage, servers and security controls.
A look inside AWS CloudFormation
An AWS resource includes an AWS instance, storage mechanism or AWS service. You can describe an EC2 instance by specifying an image, an instance type, a block device and a key name. Resource descriptions are essentially lists with logical identifiers, a type specification and a list of properties. But resources include more than EC2 instances. For example, your template can specify resources related to autoscaling, logging, network interfaces, DynamoDB, Elastic Beanstalk, Elastic Load Balancer, OpsWorks, Relational Database Service and Simple Storage Service.
Templates support parameters, so you can pass variable data as needed. This is especially useful for varying security information, such as authentication keys. You can specify basic constraints on parameters, such as allowed values or patterns, and a maximum and minimum length.
If you need slightly different configurations in test and development than you will in production, mappings can help. Mappings are sets of key value pairs that can act like functions to return values based on a key. For example, you can specify a mapping that takes a region name as the input, then outputs the name of authentication key.
Templates can create resources conditionally based on the state of the environment the template executes. Additional servers can be added to a cluster if an environment parameter such as "expected_load" is set too large.
AWS CloudFormation has some limitations. You can run up to 20 stacks. And when you design templates, you are limited to using up to 100 mappings, 60 parameters and 60 outputs.
As with other configuration management tools, CloudFormation lets developers copy and edit templates to create what they need for a particular platform. Before hard-coding templates to particular applications, generalize them to work in multiple situations. For example, a single template could be used to launch test-and-dev environments as well as production platforms. You can also use environment variables to implement location-specific or load-specific features.
Using templates and CloudFormer tools
Writing JSON files from scratch is not for everyone. AWS provides a number of templates from community repositories such as GitHub. The CloudFormer tool is available if you have an existing set of AWS resources you want to reuse. CloudFormer can detect these resources and produce a template to recreate the resources.
One you have a CloudFormation template, you can create a stack using either the AWS Management Console or the AWS command-line interface. You can also list, delete and update stacks from the console or interface. However, updating a stack may disrupt your application.
CloudFormation allows for three types of updates: updates without interruption, updates with some interruption, and replacement. Each has increasing levels of interruption on your application; the CloudFormation documentation on updates has additional information.
There is no charge for using AWS CloudFormation; AWS will bill you for the resources you deploy and services you use.
About the author:
Dan Sullivan holds a Master of Science degree and is an author, systems architect and consultant with more than 20 years of IT experience. He has had engagements in advanced analytics, systems architecture, database design, enterprise security and business intelligence. He has worked in a broad range of industries, including financial services, manufacturing, pharmaceuticals, software development, government, retail and education. Dan has written extensively about topics that range from data warehousing, cloud computing and advanced analytics to security management, collaboration and text mining.