Diwali Deal : Flat 20% off + 2 free self-paced courses + $200 Voucher  - SCHEDULE CALL

AWS CloudFormation Interview Questions and Answers for Beginners and Advanced

Introduction

AWS CloudFormation is a tool by Amazon Web Services (AWS) that helps automate the creation and management of AWS infrastructure resources. It's crucial because it simplifies the process of setting up and managing complex cloud environments. As a beginner you can use it to quickly deploy resources by writing templates that define what they need, while professionals can leverage its power to manage large-scale infrastructures efficiently. 

Our AWS CloudFormation interview questions and answers for both beginners and advanced can help you showcase an understanding of Cloud Formations basics, like creating templates and deploying stacks, demonstrates competency in infrastructure management, which is highly valued in cloud computing roles.

Q1: What Is AWS CloudFormation?

A: Before you deploy any application code, the first requirement is that infrastructure exists where you will deploy the code. AWS CloudFormation aims to alleviate previous deployment issues with the use of a service that allows you to describe your infrastructure with standardized JSON or YAML template syntax. The template contains the infrastructure that AWS will deploy and all the related configuration properties. When you submit this template to the AWS CloudFormation service, it creates a stack, which is a logical group of resources that the template describes.

Q2: How Can You Create And Delete Stacks In AWS?

A: In AWS CloudFormation, resources are managed as stacks. You can create, update, and delete a group of resources by doing the same with stacks. All resources in a stack are defined by its CloudFormation template.

Q3: What Happens When One Of The Resources In A Stack Cannot Be Created Successfully?

A: CloudFormation automatically rolls back the stack to its previous stable state if any resource creation fails. This ensures that stacks are either fully created or not at all, simplifying management.

Q4: What Are The Limitations Of AWS CloudFormation?

A: CloudFormation can only manage resources within one region, templates must be in JSON or YAML, and stacks can only be created or updated one at a time

Q5: How Is AWS CloudFormation Different From AWS Elastic Beanstalk?

A: CloudFormation is for defining and managing infrastructure resources using templates, while Elastic Beanstalk is for deploying and managing applications without worrying about infrastructure. CloudFormation gives more control over individual resources, while Elastic Beanstalk automates the deployment process and provides less flexibility.

Q6: What Are “Stacks” In AWS CloudFormation?

A: A stack represents a collection of resources to deploy and manage by AWS CloudFormation. When you submit a template, the resources you configure are provisioned and then make up the stack itself. Any modifications to the stack affect underlying resources. For example, if you remove an AWS::EC2::Instance resource from the template and update the stack, AWS CloudFormation causes the referred instance to terminate.

Q7: What Is Metadata In A Template?

A: The Metadata section of a template allows you to provide structured details about the template. For example, you can provide Metadata about the overall infrastructure to deploy and which sections correspond to certain environments, functional groups, and so on. The Metadata you provide is made available to AWS CloudFormation for reference in other sections of a template or on Amazon EC2 instances being provisioned by AWS CloudFormation

Q8: What Are “Change Sets” In AWSCloudFormation?

A: There may be times where you would like to see what changes will occur to resources when you update a template, before the update occurs. Instead of submitting the update directly, you can generate a change set. A change set is a description of the changes that will occur to a stack, should you submit the template. If the changes are acceptable, the change set itself can execute on the stack and implement the proposed modifications. This is especially important in situations where there is a potential for data loss.

Q9: What Is Infrastructure As Code (IaC) Model?

A: Using an infrastructure as code (IaC) model, instead of manually provisioning or using scripting languages, helps remove the dependency on human intervention when you create and manage infrastructure over time. You can use tools such as AWS CloudFormation to deploy infrastructure from a declarative template syntax. For example, a typical provisioning script that uses the AWS Command Line Interface (AWS CLI) includes many procedural steps that are prone to error because of invalid inputs, incorrect command syntax, and resource dependency conflicts. AWS CloudFormation templates provide the ability to validate inputs and automatically detect dependencies between resources.

Q10: How Can You Simplify The Template Authoring Process?

A: As templates grow in size and complexity, there may be situations where you use certain components repeatedly across multiple templates, such as common resources or mappings. Transforms allow you to simplify the template authoring process through a powerful set of macros you use to reduce the amount of time spent in the authoring process. AWS CloudFormation transforms first create a change set for the stack. Transforms are applied to the template during the change set creation process.

Q11: How Can Custom Resource Be Successful In AWS CloudFormation?

A: For a custom resource to be successful in AWS CloudFormation, the resource provider must return a success response to the presigned Amazon S3 URL that you provide in the request. If you do not provide a response, the custom resource will eventually time out. This is especially important with regard to update and delete actions. The custom resource provider will need to respond appropriately to every action type (create, update, and delete) for both successful and unsuccessful attempts. If you do not provide a response to an update action, for example, the entire stack update will fail after the custom resource timeout, and this results in a stack rollback.

Q12: What Is AWS CloudFormation Designer?

A: AWS CloudFormation Designer is a web-based graphical interface used to design and deploy AWS CloudFormation templates. You can design templates with a drag-and-drop interface of resource objects. You can create connections to make relationships between resources, which automatically update dependencies between them. When you are ready to deploy, you can submit the template directly to AWS CloudFormation or download it in JSON or YAML format.

AWS CloudFormation Designer keeps track of resource positions and relationships with metadata information in AWS::CloudFormation::Designer. Since no other service or component uses this information, it is safe to leave as is within your template.

Q13: What Does The AWS Serverless Application Model Add On Top Of CloudFormation?

A: AWS Serverless Application Model (SAM) extends AWS CloudFormation for building and deploying serverless applications. It offers:

  • Simplified syntax: SAM makes it easier to define serverless resources in templates.

  • Packaging and deployment: It provides tools for packaging and deploying serverless apps to AWS.

  • Testing and debugging: SAM helps test and debug apps, allowing local testing and generating sample events for function testing.

  • Lifecycle management: It offers tools for updating apps with zero downtime.

Q14: How Can You Nest With The AWS::CloudFormation::Stack Resource?

A: You can manage stacks as resources within the service in AWS CloudFormation. A single parent stack can create one or more AWS::CloudFormation::Stack resources, which act as child stacks that the parent manages. The direct benefits of this are as follows:

  • You can work around template limits that AWS CloudFormation imposes.

  • It provides the ability to separate resources into logical groups, such as network, database, and web application.

  • It lets you separate duties. (Each team is responsible only for maintaining their respective child stack.)

You can increase the nesting levels with the AWS::Cloud Formation::Stack resources.

Q15: What Are Stack Set And Stack Instance?

A: A stack set acts as a logical container for stack information in an administrator account. Each stack set will contain information about the stacks you deploy to a single target account in one or more regions. You can configure stack sets to deploy to regions in a specific order and how many unsuccessful deployments are required to fail the entire deployment.

Stack instances allow you to manage stacks in a target account. For example, if a stack set deploys to four regions in a target account, you create four stack instances. An update to a stack set propagates to all stack instances in all accounts and regions.

 AWS CloudFormation Interview Questions and Answers for Advanced

Q16: How Does AWS CloudFormation Work help you?

A: AWS CloudFormation helps you automate creating and managing AWS infrastructure resources. Here's how it works:

  • Create a template: You write a CloudFormation template in JSON or YAML. This template defines the resources you want to create and their relationships.

  • Deploy the stack: You use the CloudFormation API or Management Console to create a stack based on your template.

  • Resource creation: CloudFormation reads your template and creates the specified resources in your AWS account, making sure to handle dependencies correctly.

  • Error handling: If there are any errors during resource creation, CloudFormation rolls back the process to a stable state.

  • Completion: Once all resources are successfully created, CloudFormation marks the stack as complete, and your resources are ready to use.

  • Updates and deletion: You can update the stack by modifying the template and creating a new stack. When you no longer need the resources, you can delete the stack, and CloudFormation will remove all associated resources.

Q17: What Is The Template Structure Of AWS CloudFormation?

A: AWS CloudFormation uses specific template syntax in JSON or YAML. (The primary dif- ference is YAML’s support of comments using the # symbol.) The high-level structure of a template is as follows:

{
"AWSTemplateFormatVersion": "2010-09-09",
"Description": "String Description",
"Metadata": { },
"Parameters": { },
"Mappings": { },
"Conditions": { },
"Transform": { },
"Resources": { },
"Outputs": { }
}

Of the previous properties, AWS CloudFormation requires only the Resources section. Each property can be in any order, with the exception that Description must follow the AWSTemplateFormatVersion command

Q18: What Are The Benefits Of AWS CloudFormation?

A: AWS CloudFormation helps automate the creation and management of AWS infrastructure resources. Here are some benefits:

  • Automation: CloudFormation makes it easier to create and handle resources automatically.

  • Reusability: You can reuse CloudFormation templates to create similar setups in different environments like development, staging, and production.

  • Version control: Templates can be stored in version control systems like Git to track changes.

  • Collaboration: You can share templates with teams, allowing them to use your setups for their own projects.

  • Predictability: CloudFormation ensures resources are deployed consistently, reducing errors.

  • Resource management: It manages all resources as a single unit (a stack), making it easier to understand and manage them.

  • Customization: You can customize resources and their configurations for more control.

Updating the Metadata Section of a Template

You cannot update template metadata by itself; you must perform an update to one or more resources when you update the Metadata section of a template.

"Metadata": {
"ApplicationLayer": {
"Description": "Information about resources in the app layer."
},
"DatabaseLayer": {
"Description": "Information about resources in the DB layer."
}
}

In the Metadata section of the template, you have the ability to specify properties that affect the behavior of different components of the AWS CloudFormation service, such as how template parameters display in the AWS CloudFormation console.

Q19: How Can You Use Parameters In Your Template?

A: You can use Parameters to provide inputs into your template, which allows for more flexibility in how this template behaves when you deploy it. Parameter values can be set either when you create the stack or when you perform updates.

The Parameters section must include a unique logical ID. A parameter must include a value, either a default or one that you provide. Lastly, you cannot reference parameters outside a single template.

AllowedValues Error

This example defines a String parameter named InstanceTypeParameter with a default value of t2.micro. The parameter allows t2.micro, m1.small, or m1.large. The Allowed Values section specifies what options you can select for this parameter in the AWS CloudFormation console. AWS CloudFormation will throw an error if you add a value not in AllowedValues.

 

"Parameters": {
"InstanceTypeParam": {
"Type": "String",
"Default": "t2.micro",
"AllowedValues": [ "t2.micro", "m1.small", "m1.large" ],
"Description": "Enter t2.micro, m1.small, or m1.large. Default is t2.micro."
}
}

Once you specify a parameter, you can use it within the template using the Ref intrinsic function. When AWS CloudFormation evaluates it, the Ref statement converts it to the value of the parameter.

 

"EC2Instance": {
"Type": "AWS::EC2::Instance”,
"Properties": {
"InstanceType": { "Ref": "InstanceTypeParam" },
"ImageId": "ami-12345678"
}
}

Q20: What Is The Use Of Mapping In A Template?

A: You can use the Mappings section of a template to create rudimentary lookup tables that you can reference in other sections of your template when you create the stack.

A common example of mappings usage is to look up Amazon EC2 instance AMI IDs based on the region and architecture type. Note in the following example that mappings entries may contain only string values. (Mappings does not support parameters, conditions, or intrinsic functions.)

"Mappings" : {
"RegionMap" : {
"us-east-1" : { "32" : "ami-6411e20d", "64" : "ami-7a11e213" },
"us-west-1" : { "32" : "ami-c9c7978c", "64" : "ami-cfc7978a" },
"eu-west-1" : { "32" : "ami-37c2f643", "64" : "ami-31c2f645" },
"ap-southeast-1" : { "32" : "ami-66f28c34", "64" : "ami-60f28c32" },
"ap-northeast-1" : { "32" : "ami-9c03a89d", "64" : "ami-a003a8a1" }
}
}

Q21: What Is AWS::Include Transform?

A: AWS::Include Transform acts as a tool to import template snippets from Amazon S3 buckets into the template being developed. When the template is evaluated, a change set is created, and the template snippet is copied from its location and is added to the overall template structure. You can use this transform anywhere in a template, except the Parameters and AWSTemplateFormatVersion sections.

When you use the AWS::Include Transform at the top level of a template, the syntax must match the example. (Note that the transform is declared as Transform .) This is especially useful if there is a set of common mappings that you use across multiple teams or template authors, as they can share this set and update it in one location.

{
"Transform" : {
"Name" : "AWS::Include",
"Parameters" : {
"Location" : "s3://MyAmazonS3BucketName/MyFileName.json"
}
}
}

When you use a transform in nested sections of a template, such as the Properties section of an AWS::EC2::Instance resource, use the following syntax. (Note that this is now an intrinsic function call.)

{
"Fn::Transform" : {
"Name" : "AWS::Include",
"Parameters" : {
"Location" : "s3://MyAmazonS3BucketName/MyFileName.json"
}
}
}

Q22: How Can You Use AWS::Serverless Transform?

A: You can use the AWS::Serverless Transform to convert AWS Serverless Application Model (AWS SAM) templates to valid AWS CloudFormation templates for deployment. AWS SAM uses an abbreviated template syntax to deploy serverless applications with AWS Lambda, Amazon API Gateway, and Amazon DynamoDB.

The following example creates a function that uses the serverless transform. When AWS CloudFormation evaluates the transform, the transform expands the template to include an AWS Lambda function and its IAM execution role.

Transform: AWS::Serverless-2016-10-31
Resources:
MyServerlessFunctionLogicalID:
Type: AWS::Serverless::Function
Properties:
Handler: index.handler
Runtime: nodejs4.3
CodeUri: 's3://testBucket/mySourceCode.zip'

Q23: How Can You Use Fn::FindInMap?

A: After you create mappings in AWS CloudFormation, you use the Fn::FindInMap intrinsic function to query information stored within the mapping table. Note that mappings have two key levels, and thus top-level and second-level keys must be supplied as inputs, along with the mapping name itself.

Consider the following Mappings section. The Fn::FindInMap call would return ami-c9c7978c.

 

"Mappings" : {
"RegionMap" : {
"us-east-1" : { "32" : "ami-6411e20d", "64" : "ami-7a11e213" },
"us-west-1" : { "32" : "ami-c9c7978c", "64" : "ami-cfc7978a" },
"eu-west-1" : { "32" : "ami-37c2f643", "64" : "ami-31c2f645" }

Q24: How Can You Find Out Which Availability Zones Are Usable In The AWS Region?

A: For each AWS region, different availability zones (with different names) are available. The specific availability zones will not always match between different accounts (in fact, two accounts with the same availability zone by name may not use the same physical location). Because of this, it is not easy to determine which availability zones are usable when you create a stack. The Fn::GetAZs intrinsic function returns a list of availability zones for the account in which the stack is being created.

To increase flexibility further and remove the need to hard-code a region in the template,

you can use the AWS::Region pseudo parameter to return the list of availability zones for the region in which the stack is being created.

Q25: How Can You Enforce AWS::CloudFormation::Init Metadata?

A: To enforce the AWS::CloudFormation::Init metadata, instances being provisioned in your template must call the cfn-init helper script as part of UserData execution (either in the AWS::EC2::Instance UserData property or in the same property of an AWS::AutoScaling::LaunchConfiguration resource). When doing so, you must provide the stack name and resource logical ID. Optionally, you can execute a configSet or list of configSets in the call.

You must pass UserData to instances in Base64 format. Thus, you call the Fn::Base64 function to convert the text-based script to a Base64 encoding.

"UserData" : { "Fn::Base64" :
{ "Fn::Join" : ["", [
"#!/bin/bash -xe\n",
"# Install the files and packages from the metadata\n",
"/opt/aws/bin/cfn-init -v ",
" --stack ", { "Ref" : "AWS::StackName" },
" --resource WebServerInstance ",
" --configsets InstallAndRun ",
" --region ", { "Ref" : "AWS::Region" }, "\n"
]]}

}

Q26: What Is The Use Of Custom Resources In AWS CloudFormation?

A: AWS CloudFormation uses custom resource providers to handle the provisioning and configuration of custom resources. Custom resource providers may be AWS Lambda functions or Amazon Simple Notification Service (Amazon SNS) topics. When you create, update, or delete a custom resource, either the AWS Lambda function is invoked or a message is sent to the Amazon SNS topic you configure in the resource declaration.

In the custom resource declaration, you must provide a service token along with any optional input parameters. The service token acts as a reference to where custom resource requests are sent. This can be either an AWS Lambda function or Amazon SNS topic. Any input parameters you include are sent with the request body. After the resource provider processes the request, a SUCCESS or FAILED result is sent to the presigned Amazon S3 URL you included in the request body. AWS CloudFormation monitors this bucket location for a response, which it processes once it is sent by the provider. Custom resources can provide outputs back to AWS CloudFormation, which are made accessible as properties of the custom resource. You can access these properties with the Fn::GetAtt intrinsic function to pass the logical ID of the resource and the attribute you desire to query.

AWS Solution Architect Training and Certification

  • Personalized Free Consultation
  • Access to Our Learning Management System
  • Access to Our Course Curriculum
  • Be a Part of Our Free Demo Class

Q27: What Is The Role Of Resource Relationships In AWS CloudFormation?

A: By default, AWS CloudFormation will track most dependencies between resources. There are, however, some exceptions to this process. For example, an application server may not function properly until the backend database is up and running. In this case, you can add a DependsOn attribute to your template to specify the order of creation. The DependsOn attribute specifies that creation of a resource should not begin until another completes. A resource can have a dependency on one or more other resources in a stack. The following code demonstrates that the resource EC2Instance has a dependency on MyDB, which means the instance resource will not begin creation until the database resource is in a CREATE_COMPLETE state.

{
"Resources" : {
"Ec2Instance" : {
"Type" : "AWS::EC2::Instance",
"Properties" : {
"ImageId" : {
"Fn::FindInMap" : [ "RegionMap", { "Ref" : "AWS::Region" }, "AMI" ]
}
},
"DependsOn" : "myDB"
},
"myDB" : {
"Type" : "AWS::RDS::DBInstance",
"Properties" : {
"AllocatedStorage" : "5",
"DBInstanceClass" : "db.m1.small",
"Engine" : "MySQL",
"EngineVersion" : "5.5",
"MasterUsername" : "MyName",
"MasterUserPassword" : "MyPassword"
}
}
}
}

Conclusion

JanBask Training's AWS courses can further enhance both beginners' and professionals' understanding of CloudFormation. Through comprehensive training, beginners can grasp the fundamentals and gain practical experience in using CloudFormation effectively. For professionals, advanced courses offered by JanBask Training can deepen their expertise, providing insights into best practices and advanced techniques for optimizing infrastructure deployment and management with CloudFormation.

Trending Courses

Cyber Security

  • Introduction to cybersecurity
  • Cryptography and Secure Communication 
  • Cloud Computing Architectural Framework
  • Security Architectures and Models

Upcoming Class

4 days 22 Nov 2024

QA

  • Introduction and Software Testing
  • Software Test Life Cycle
  • Automation Testing and API Testing
  • Selenium framework development using Testing

Upcoming Class

14 days 02 Dec 2024

Salesforce

  • Salesforce Configuration Introduction
  • Security & Automation Process
  • Sales & Service Cloud
  • Apex Programming, SOQL & SOSL

Upcoming Class

2 days 20 Nov 2024

Business Analyst

  • BA & Stakeholders Overview
  • BPMN, Requirement Elicitation
  • BA Tools & Design Documents
  • Enterprise Analysis, Agile & Scrum

Upcoming Class

5 days 23 Nov 2024

MS SQL Server

  • Introduction & Database Query
  • Programming, Indexes & System Functions
  • SSIS Package Development Procedures
  • SSRS Report Design

Upcoming Class

5 days 23 Nov 2024

Data Science

  • Data Science Introduction
  • Hadoop and Spark Overview
  • Python & Intro to R Programming
  • Machine Learning

Upcoming Class

4 days 22 Nov 2024

DevOps

  • Intro to DevOps
  • GIT and Maven
  • Jenkins & Ansible
  • Docker and Cloud Computing

Upcoming Class

-0 day 18 Nov 2024

Hadoop

  • Architecture, HDFS & MapReduce
  • Unix Shell & Apache Pig Installation
  • HIVE Installation & User-Defined Functions
  • SQOOP & Hbase Installation

Upcoming Class

4 days 22 Nov 2024

Python

  • Features of Python
  • Python Editors and IDEs
  • Data types and Variables
  • Python File Operation

Upcoming Class

12 days 30 Nov 2024

Artificial Intelligence

  • Components of AI
  • Categories of Machine Learning
  • Recurrent Neural Networks
  • Recurrent Neural Networks

Upcoming Class

5 days 23 Nov 2024

Machine Learning

  • Introduction to Machine Learning & Python
  • Machine Learning: Supervised Learning
  • Machine Learning: Unsupervised Learning

Upcoming Class

39 days 27 Dec 2024

Tableau

  • Introduction to Tableau Desktop
  • Data Transformation Methods
  • Configuring tableau server
  • Integration with R & Hadoop

Upcoming Class

4 days 22 Nov 2024