What is AWS Cloudformation?

In Simplest terms, cloud computing means storing and accessing the data and programs on remote servers that are hosted on the internet instead of the computer’s hard drive or local server. It is also referred to as Internet-based computing.

Features of the cloud:

  • No up-front investment
  • Lowering operating cost
  • Highly scalable
  • Easy access
  • Reducing business risks and maintenance expenses

Amazon Web Services is a subsidiary of Amazon.com that provides on-demand cloud computing platforms to individuals, companies, and governments, on a paid subscription basis.

Why do we need AWS Cloudformation?

Just imagine that you have to develop an application that uses various AWS resources. When it comes to creating and managing those resources, it can be highly time-consuming and challenging. It can become difficult for you to develop the application when you are spending the whole time in managing those AWS resources. What if we have a service for that? So here comes AWS Cloudformation in the picture.

What is AWS Cloudformation?



This is a service provided by AWS that helps you create and manage the resources so that you can spend less time managing those resources and more time focusing on your applications that run in AWS. You just have to create a template which describes all the resources you require, then AWS Cloudformation will take care of managing and provisioning all the resources. AWS provides a Cloudformation designer for designing the template wherein you can put all the resources. You can also define the dependencies of all the resources that are needed. You can also reuse your templates to replicate your infrastructure in multiple environments and regions. 

Getting Started with AWS Cloudformation

Our template is created in JSON or YAML script. We will be discussing the JSON script in this article. JSON is a text-based format that represents structured data on the basis of JavaScript object syntax. It carries the AWS resources details in the structured format according to which AWS infrastructure is created.

Structure of Cloudformation JSON Template

  • Format version: It defines the version of a template.
  • Description: Any extra description or comments about your template are written in the description of the template.
  • Metadata:  It can be used to provide further information using JSON  objects.
  • Parameters: Parameters are used when you want to provide custom or dynamic values to the stack during runtime. Therefore, we can customize templates using parameters.
  • Mappings: Mapping in the JSON template helps you to map keys to a corresponding named value that you specify in a conditional parameter.
  • Conditions: Conditions are used to define if certain resources are created or when the resource’s properties are assigned to a value when the stack is created.
  • Transform: Transform helps in reusing the template components by building a simple declarative language for AWS CloudFormation.
  • Resources: In this, you can specify the properties of  AWS resources (AWS EC2 instance, S3 bucket, AWS lambda ) you want in your stack.
  • Output: The output defines the value which is generated as an output when you view your own stack properties.

Installing EC2 instance and LAMP package(Apache, MySQL, and PHP) on top of it using AWS Cloudformation

Using AWS cloudformation, we will be creating a template using which instance will be launched and the LAMP package will be installed on top of it automatically

Step 1: Go to the Cloudformation dashboard on the AWS management console. Click on create the stack.

AWS Cloudformation 1

Step 2: You will be redirected to this webpage. We will be using a sample template of Lamp Stack in this. Select the option: Use a sample template. Select the Lamp Stack template. Click on View in Designer to view the design of the template.



AWS Cloudformation 2

Step 3: Now you will be redirected to the designer page which shows the design of the template. It shows the instance which will be created with Apache and MySQL installed over it. It also shows the security groups attached to the security purpose of the instance. Here you can design your own infrastructure accordingly.

AWS Cloudformation 3

Step 4: These are the components of the template which we discussed earlier. Rename the template accordingly.

AWS Cloudformation 4

Step 5: This is the code written in JSON format which contains all the specifications and dependencies about the infrastructure to be created.

AWS Cloudformation 5

Step 6: Now click on the cloud-shaped upload button to come out of the designer.

AWS Cloudformation 6

Step 7: We will come back to the same web page. Click on Next.



AWS Cloudformation 7

Step 8: Specify the desired stack name over here

AWS Cloudformation 8

Step 9: Mention the name of the database you want to create on the MySQL database. Also, specify the password and name of db-user.

AWS Cloudformation 9

Step 10: Choose the instance type. Select any available key pair which will be used in making an SSH connection with the instance. Click on Next.

AWS Cloudformation 10

Step 11: You don’t have to worry about the advanced settings. Click on Next.

AWS Cloudformation 11

Step 12: Click on create a stack. The instance will be created with the LAMP package installed on it. You can easily work with PHP and MySQL on the instance.

AWS Cloudformation 12

Attention reader! Don’t stop learning now. Get hold of all the important CS Theory concepts for SDE interviews with the CS Theory Course at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.