Introduction to AWS CloudFormation

Introduction to AWS CloudFormation

This is an absolute beginners guide to getting started with AWS CloudFormation.

The standard definition is "AWS CloudFormation is a service that gives developers and businesses an easy way to create a collection of related AWS resources and provision them in an orderly and predictable fashion".

AWS CloudFormation helps in provisioning and managing stacks of AWS resources based on ‘templates’ that you create to model your infrastructure architecture.

Using CloudFormation, you can manage anything from a simple AWS EC2 instance to a complex multi-tier, multi-region application.

CloudFormation can be used to define simple things like an Amazon VPC subnet as well as provisioning services like EMR, Kinesis etc.

It is easy to get started with CloudFormation. You simply create a template which is basically a JSON file that serves as the blueprint to define the configuration of all the AWS services and resources that make up your infrastructure or application stack. You can also select a sample pre-built template as a starting point and customize it to fit your needs.

For example, if you want to create a wordpress application, then you can start with a default LAMP (Linux, Apache, MySQL, PHP) stack template that includes an EC2 and RDS instance.

CloudFormation Template

  • JSON document which describes a configuration to be deployed in an AWS account
  • When deployed, refers to a “stack” of resources
  • The Template is a document and not a “script”
  • Templates can include several major sections:
  • – AWSTemplateFormatVersion
  • – Description
  • – Metadata
  • – Parameters
  • – Mappings
  • – Conditions
  • – Resources
  • – Outputs

Please note that the Resources section is the only section that is mandatory.

The first character in the CloudFormation template must be an open brace ({), and the last character must be a closed brace (}).

No alt text provided for this image

AWS CloudFormation is a way of treating Infrastructure as code

? Versioned, auditable blueprints

? Quick to deploy, repeatable

? Enables versioning, CI/CD for infrastructure

Once you have your template, you just upload it to AWS CloudFormation which will automatically provision and configure your AWS resource stack. You can upload or modify your template using the AWS Console, AWS CLI or using AWS SDK.

As a very simple example, if you want to create an S3 bucket using cloudformation, then you will create a template like this:

{

   "Resources" : {

       "Name-of-your-bucket" : {

           "Type" : "AWS::S3::Bucket"

           }

       }

}

You need to replace “Name-of-your-bucket” with your bucket’s name.

And then,

1.   Cut and Paste the above code and save it as a file called myS3cftemplate.txt (you obviously can choose any name for your file).

2.    Go to your AWS Console, and then to the CloudFormation Service.

3.    Click on ‘create a stack.’

4.    Give your stack a name.

5.    Click on Upload a template to Amazon S3 and choose myS3cftemplate.txt.

6.    Click Next.

7.    Click Next.

8.    Click on Create.

You should see “CREATE_COMPLETE” when finished. That's it!

If you now go to your S3 dashboard, you should see a new bucket. You may also notice another bucket named cf-templates-xxxxxx . If you go into this bucket you will see the myS3cftemplate.txt file you uploaded. You can use this again by just referencing the http link the next time.

Although this is a very simple template, it helps demonstrate how you can use a CloudFormation template for simplifying infrastructure management.

CloudFormation also lets you use version control for your templates just like version control of software code.

Using CloudFormation templates to provision your infrastructure gives you the flexibility of being able to replicate your infrastructure very easily. If you want to create different stages (Development stack, Testing stack, Production stack, etc), CloudFormation makes this a very easy and automated task for you.

The best part is that there is NO CHARGE for using CloudFormation. It is totally free. You only pay for the actual services and resources that it helps provision. https://aws.amazon.com/cloudformation/pricing/

To get started, visit https://aws.amazon.com/cloudformation

You can get sample code and CloudFormation templates here: https://aws.amazon.com/cloudformation/templates/

Parag Sahasrabudhe

Engineering leader - Translation services, Amazon exports and expansion

5 å¹´

Very well written Vinayak !

赞
回复

要查看或添加评论,请登录

Vinayak Raghuvamshi的更多文章

社区洞察

其他会员也浏览了