AWS Certification : How to Create and Use AWS CloudFormation Templates?

Are you preparing for AWS Certified Developer Associate certification exam? In this space, we are writing series of articles on topics which are covered in the developer associate certification exam. In this article, we are explaining one of the important concept AWS CloudFormation. You would expect lot of questions from this topic for developer associate exam. You can subscribe to us for receiving the further updates on this topic.

Developer Associate certification exam is the most easiest exam in the associate level, it is good idea to start your certification from this exam. Also we would recommend you to pass the solutions architect certification exam which covers the concepts of all the services offered in AWS.

 

Developer Associate Syllabus

Here is the snapshot of blueprint for developer associate is covered in the developer associate exam.

Amazon CloudFormation

Amazon Cloudformation helps developers and other IT professional to design templates that can be used to create aws resources. It’s like infrastructure as code. AWS Cloudformation includes the following features

  1. Its simple to use. It has a web interface which allows one to easily manage and work with aws resources.
  2. It supports the creation of a wide range of aws resources, right from EC2 resources to Elastic Load Balancer.
  3. You can create templates which is infrastructure as code. These templates can be re-used to create resources for multiple environments.
  4. One can customize the template and creation of resources via parameters.
  5. There is a Visual editor which allows one to have a visual representation of resources. One can then drag and drop resources and create the template accordingly.

Structure of a CloudFormation Template

A cloudformation template has the following structure

{
	"AWSTemplateFormatVersion" : "version date",
	"Description" : "JSON string",
	"Metadata" : 
	{
		template metadata
	},
	"Parameters" : 
	{
		set of parameters
	},
	"Mappings" : 
	{
	    set of mappings
	},
	"Conditions" : 
	{
	    set of conditions
	},
	"Transform" : 
	{
	    set of transforms
	},
	"Resources" : 
	{
	    set of resources
	},
	"Outputs" : 
	{
		set of outputs
	}
}

The description of the different section of the template are given below

  • Format Version – This specifies the AWS CloudFormation template version that the template conforms to.
  • Description – A text string that describes the template.
  • Metadata – Objects that provide additional information about the template.
  • Parameters – Specifies values that you can pass in to your template at runtime.
  • Mappings – A mapping of keys and associated values that you can use to specify conditional parameter values, similar to a lookup table. You can match a key to a corresponding value by using the Fn::FindInMap intrinsic function in the Resources and Outputs section.
  • Conditions – Defines conditions that control whether certain resources are created or whether certain resource properties are assigned a value during stack creation or update.
  • Transform – For serverless applications (also referred to as Lambda-based applications), specifies the version of the AWS Serverless Application Model (AWS SAM) to use.
  • Resources – Specifies the stack resources and their properties, such as an Amazon Elastic Compute Cloud instance or an Amazon Simple Storage Service bucket.
  • Outputs – Describes the values that are returned whenever you view your stack’s properties.

One of the key aspects for the Developer exam is to know how to setup cloudformation templates. So let’s look at the basic ways to create cloudformation templates

Basic CloudFormation Template

In this example, we will look at how to automate the creation of an EC2 instance from a particular AMI ID

  • Creating a template – Log into your AWS Console. You will see CloudFormation under the Management tools section.
  •  Click on Cloudformation. In the next screen click on Design template. This will allow you to create a custom template for cloudformation.

  • The template designer will show up. You have the option to either create the template via the designer or to create it via the JSON editor.

  • As an AWS Developer, you need to know the JSON structure for cloudformation templates. So let’s add the following code to the template designer.
{
"Resources" : {
   "MyEC2Instance" : {
       "Type" : "AWS::EC2::Instance",
           "Properties" : {"ImageId" : "ami-e5a51786"}
         }
     }
}

The resources section tells the cloudformation template that we want to work with an aws resource.

  • Next we are defining a variable for our resource which is called MyEC2Instance
  • Next we want the type of resource to be a AWS::EC2::Instance
  • And finally we want our instance to be of the image id ami-e5a51786. Note that this image id is in the Singapore region. It is also an AMI for a windows instance.

You can add the code to the template section.

Once done , you can click on the Validate template option in the left hand corner.  It’s the icon with the tick mark.

  • Next click on the cloud like button to create a stack from the code
AWS Cloudformation- Create Stack
  •  In the next screen, you can accept the default settings and click on the next button.

  • Next you just need to give a name for the stack and click on the Next button.

In the next screen you have the ability to add a role or a tag. For now you can leave the default settings as it is and click on the Next button.

  • In the final screen, you can click on the Create button

  • If you now go to your EC2 dashboard, you will see one instance now running. This has been created by the Cloudformation template.

  • And now if you go back to the cloudformation template , you will see that the status is complete.

Note: – If any resource creation in the template fails, the entire template is rolled back.

 CloudFormation Functions

Cloudformation has support for functions known as intrinsic functions. Some of the key functions are given below

  • Fn::FindInMap – The intrinsic function Fn::FindInMap returns the value corresponding to keys in a two-level map that is declared in the Mappings section.
  • Fn::GetAtt – The Fn::GetAtt intrinsic function returns the value of an attribute from a resource in the template.
  • Fn::GetAZs – The intrinsic function Fn::GetAZs returns an array that lists Availability Zones for a specified region.
  • Fn::Join – The intrinsic function Fn::Join appends a set of values into a single value, separated by the specified delimiter. If a delimiter is the empty string, the set of values are concatenated with no delimiter.

Let’s look at an example of using a function

  • Again let’s create a cloudformation stack, but this time let’s add the below code
{
   "Resources": {
      "MyEC2Instance": {
          "Type": "AWS::EC2::Instance",
              "Properties": {
                 "ImageId": "ami-e5a51786"
               }
           }
      },
   "Outputs": {
       "Availability": {
           "Description": "The Instance ID",
            "Value":
       { "Fn::GetAtt" : [ "MyEC2Instance", "AvailabilityZone" ]}
      }
   }
}

Now in the above stack, we are using the Fn::GetAtt function to get the AvailabilityZone as an output in which the resource is created.

  •  Now create a stack based on the above template with the same settings, but this time you can give a  different name for the stack.

Now when the template creation is done, and you see the output tab, you will see the AZ as an output in which the EC2 instance is created.

Final Points to Remember About CloudFormation

  • Cloudfromation has a web interface which allows one to easily manage and work with aws resources.
  • It supports the creation of a wide range of aws resources, right from EC2 resources to Elastic Load Balancer.
  • You can create templates which is infrastructure as code. These templates can be re-used to create resources for multiple environments.
  • If any resource creation in the template fails, the entire template is rolled back.
  • Cloudformation has the support for functions known as intrinsic functions. Some of them are given below
    • Fn::FindInMap
    • Fn::GetAtt
    • Fn::GetAZs
    • Fn::Join

Summary

In this article we have explained about how to create and use AWS CloudFormation Templates. This is one of the most important service offered by Amazon Web Services (AWS) that will help the developers to model the templates for their AWS resources . You would expect lot of questions from this topic in your certification exam. 

If you are preparing for the AWS certifications exam and looking for any help, please send us a mail or call to our customer support team. 

 

About Pavan Gumaste

Pavan Rao is a programmer / Developer by Profession and Cloud Computing Professional by choice with in-depth knowledge in AWS, Azure, Google Cloud Platform. He helps the organisation figure out what to build, ensure successful delivery, and incorporate user learning to improve the strategy and product further.

0 thoughts on “AWS Certification : How to Create and Use AWS CloudFormation Templates?”

Leave a Comment

Scroll to Top
vceplus-200-125    | boson-200-125    | training-cissp    | actualtests-cissp    | techexams-cissp    | gratisexams-300-075    | pearsonitcertification-210-260    | examsboost-210-260    | examsforall-210-260    | dumps4free-210-260    | reddit-210-260    | cisexams-352-001    | itexamfox-352-001    | passguaranteed-352-001    | passeasily-352-001    | freeccnastudyguide-200-120    | gocertify-200-120    | passcerty-200-120    | certifyguide-70-980    | dumpscollection-70-980    | examcollection-70-534    | cbtnuggets-210-065    | examfiles-400-051    | passitdump-400-051    | pearsonitcertification-70-462    | anderseide-70-347    | thomas-70-533    | research-1V0-605    | topix-102-400    | certdepot-EX200    | pearsonit-640-916    | itproguru-70-533    | reddit-100-105    | channel9-70-346    | anderseide-70-346    | theiia-IIA-CIA-PART3    | certificationHP-hp0-s41    | pearsonitcertification-640-916    | anderMicrosoft-70-534    | cathMicrosoft-70-462    | examcollection-cca-500    | techexams-gcih    | mslearn-70-346    | measureup-70-486    | pass4sure-hp0-s41    | iiba-640-916    | itsecurity-sscp    | cbtnuggets-300-320    | blogged-70-486    | pass4sure-IIA-CIA-PART1    | cbtnuggets-100-101    | developerhandbook-70-486    | lpicisco-101    | mylearn-1V0-605    | tomsitpro-cism    | gnosis-101    | channel9Mic-70-534    | ipass-IIA-CIA-PART1    | forcerts-70-417    | tests-sy0-401    | ipasstheciaexam-IIA-CIA-PART3    | mostcisco-300-135    | buildazure-70-533    | cloudera-cca-500    | pdf4cert-2v0-621    | f5cisco-101    | gocertify-1z0-062    | quora-640-916    | micrcosoft-70-480    | brain2pass-70-417    | examcompass-sy0-401    | global-EX200    | iassc-ICGB    | vceplus-300-115    | quizlet-810-403    | cbtnuggets-70-697    | educationOracle-1Z0-434    | channel9-70-534    | officialcerts-400-051    | examsboost-IIA-CIA-PART1    | networktut-300-135    | teststarter-300-206    | pluralsight-70-486    | coding-70-486    | freeccna-100-101    | digitaltut-300-101    | iiba-CBAP    | virtuallymikebrown-640-916    | isaca-cism    | whizlabs-pmp    | techexams-70-980    | ciscopress-300-115    | techtarget-cism    | pearsonitcertification-300-070    | testking-2v0-621    | isacaNew-cism    | simplilearn-pmi-rmp    | simplilearn-pmp    | educationOracle-1z0-809    | education-1z0-809    | teachertube-1Z0-434    | villanovau-CBAP    | quora-300-206    | certifyguide-300-208    | cbtnuggets-100-105    | flydumps-70-417    | gratisexams-1V0-605    | ituonline-1z0-062    | techexams-cas-002    | simplilearn-70-534    | pluralsight-70-697    | theiia-IIA-CIA-PART1    | itexamtips-400-051    | pearsonitcertification-EX200    | pluralsight-70-480    | learn-hp0-s42    | giac-gpen    | mindhub-102-400    | coursesmsu-CBAP    | examsforall-2v0-621    | developerhandbook-70-487    | root-EX200    | coderanch-1z0-809    | getfreedumps-1z0-062    | comptia-cas-002    | quora-1z0-809    | boson-300-135    | killtest-2v0-621    | learncia-IIA-CIA-PART3    | computer-gcih    | universitycloudera-cca-500    | itexamrun-70-410    | certificationHPv2-hp0-s41    | certskills-100-105    | skipitnow-70-417    | gocertify-sy0-401    | prep4sure-70-417    | simplilearn-cisa    |
http://www.pmsas.pr.gov.br/wp-content/    | http://www.pmsas.pr.gov.br/wp-content/    |