What is AWS Cloudformation? Pros and Cons?
Summary
TLDRThe video introduces AWS CloudFormation, an infrastructure as code service, emphasizing its importance in the software industry. It explains CloudFormation's benefits, such as simplifying deployment and enabling regional expansion, and compares it with other IaC tools like Terraform, Serverless Framework, AWS SAM, and AWS CDK. The speaker shares insights on the learning curve, potential pitfalls, and the concept of drift, concluding with advice on getting started, particularly recommending AWS SAM for beginners.
Takeaways
- π AWS CloudFormation is a favorite service for infrastructure as code (IaC) in the software industry, simplifying deployment and management of AWS resources.
- π CloudFormation uses template files written in YAML or JSON to define resources and their configurations, which can be created, updated, and managed through AWS.
- π§ The service allows for incremental updates and automatic rollbacks in case of issues, providing a safe and efficient way to manage infrastructure changes.
- π CloudFormation is particularly useful for regional expansion, enabling easy replication of infrastructure across different AWS regions.
- π Key concepts in CloudFormation include template files, stacks (logical groupings of resources), and change sets (preview of changes before deployment).
- π Pros of using CloudFormation include ease of use, support for code reviews, integration with CI/CD pipelines, and a large community for support.
- β οΈ Learning curve and potential dangers from seemingly innocent changes are among the cons, as well as the risk of 'drift' if resources are manually modified outside of CloudFormation.
- π Comparison with other IaC tools like AWS SAM, Serverless Framework, Terraform, and AWS CDK shows that while they have their unique features, they all compile down to CloudFormation.
- π Getting started with CloudFormation is recommended to begin with AWS SAM due to its straightforward CLI tool and support for rapid development cycles.
- π οΈ For beginners, start by installing SAM, reading AWS CloudFormation documentation, and experimenting with basic resources like Lambda functions and S3 buckets.
Q & A
What is AWS CloudFormation?
-AWS CloudFormation is an infrastructure as code service provided by Amazon Web Services that allows users to define and deploy resources through template files written in YAML or JSON, which can then be uploaded to AWS for creation and management of those resources.
Why is learning AWS CloudFormation considered an important skill in the software industry?
-Learning AWS CloudFormation is important because it enables developers to manage and provision AWS resources in a reproducible and automated manner, which is crucial for scaling applications, ensuring consistency, and integrating with continuous integration and continuous deployment (CI/CD) pipelines.
What are the key concepts of AWS CloudFormation?
-The key concepts of AWS CloudFormation include template files (in YAML or JSON) that define resources, stacks which are logical groupings of resources, and change sets that represent the differences between the current state and the desired state of the infrastructure.
What are the benefits of using AWS CloudFormation?
-Benefits of using AWS CloudFormation include ease of use, support for regional expansion, the ability to introduce code review mechanisms for infrastructure changes, easy integration with CI pipelines, and a large community for support and troubleshooting.
What are some potential drawbacks or challenges when using AWS CloudFormation?
-Drawbacks of AWS CloudFormation include a steep learning curve initially, the risk of inadvertently causing issues with seemingly innocent changes (like renaming resources), and the concept of drift, where manual changes outside of CloudFormation can lead to inconsistencies and deployment failures.
How does AWS CloudFormation compare to other infrastructure as code solutions like Terraform, Serverless Framework, AWS SAM, and AWS CDK?
-AWS CloudFormation is the underlying technology used by AWS SAM and the Serverless Framework, both of which simplify the deployment of serverless applications. Terraform is a provider-agnostic tool that can manage resources across multiple cloud providers. AWS CDK is a newer offering that allows developers to define infrastructure using actual programming languages like JavaScript or TypeScript, offering more flexibility and familiar programming constructs.
What is the recommended starting point for beginners to learn AWS CloudFormation?
-For beginners, it is recommended to start with AWS SAM, which provides a CLI tool for quick development cycles and is straightforward to use. This approach allows new learners to get hands-on experience with CloudFormation templates and understand the basics before diving into more complex scenarios.
How can AWS CloudFormation be integrated into a continuous integration and continuous deployment (CI/CD) pipeline?
-AWS CloudFormation can be integrated into a CI/CD pipeline by attaching the YAML or JSON template files to CI tools like GitHub hooks. Changes to these files can trigger a pipeline in AWS through services like AWS CodePipeline, automatically deploying the infrastructure updates defined in the templates.
What is 'drift' in the context of AWS CloudFormation?
-Drift refers to the state where the actual configuration of resources in AWS does not match the expected configuration as defined in the CloudFormation stack. This can occur if changes are made directly through the AWS console or CLI, outside of the CloudFormation management process, leading to inconsistencies and potential deployment failures.
How can one mitigate the risk of data loss due to changes in AWS CloudFormation?
-To mitigate the risk of data loss, it is important to understand the implications of changes in CloudFormation templates, especially when it comes to resource names and configurations that can lead to resource replacement. Additionally, maintaining version control over the infrastructure code and thoroughly reviewing changes before deployment can help prevent accidental data loss.
What is the recommended approach for troubleshooting AWS CloudFormation issues?
-For troubleshooting AWS CloudFormation issues, it is recommended to first understand the concept of change sets and the differences they represent. If problems arise, reviewing the CloudFormation logs and the status of the resources can provide insights. Since all tools like SAM, Serverless Framework, Terraform, and CDK compile down to CloudFormation, understanding the underlying CloudFormation processes is crucial for debugging.
Outlines
π Introduction to AWS CloudFormation
The speaker expresses excitement about discussing AWS CloudFormation, a favorite service due to its importance in the software industry. The video aims to provide a simple understanding of CloudFormation. It begins with defining CloudFormation using a relatable example of building a REST API with API Gateway and Lambda Function. The speaker then explains the complexity of managing AWS resources manually and introduces CloudFormation as a solution to define, create, and manage AWS resources through template files, emphasizing its ease of use and benefits like automatic rollback in case of issues.
π Key Concepts of CloudFormation
The speaker delves into the key concepts of CloudFormation, starting with the creation of template files in YAML or JSON, which contain resources representing AWS components. An example of a Lambda function in YAML format is provided. The speaker then explains the concept of 'stacks' as logical groupings of templates and resources, and 'change sets' as diffs between updates that allow for incremental and previewed changes. The benefits of CloudFormation are highlighted, including simplicity, regional expansion support, code review integration, and CI pipeline compatibility, along with a large community for support.
π Pros and Cons of CloudFormation
The speaker discusses the pros and cons of using CloudFormation. The pros include ease of use, support for regional expansion, the ability to integrate with code reviews and CI pipelines, and a strong community for support. The cons are the initial steep learning curve, the potential danger of seemingly innocent changes leading to resource deletion, and the concept of 'drift' where manual changes outside CloudFormation can cause out-of-sync issues. The speaker advises treating the AWS account as read-only to avoid drift and emphasizes the importance of understanding CloudFormation's nuances.
π Comparison with Other IaC Solutions
The speaker compares CloudFormation with other Infrastructure as Code (IaC) solutions like AWS SAM, Serverless Framework, Terraform, and AWS CDK. AWS SAM and Serverless Framework are similar and both use CloudFormation under the hood, with SAM being AWS-supported. Terraform is noted for its provider-agnostic approach, suitable for managing resources across multiple cloud providers. AWS CDK is highlighted as a newer offering that allows infrastructure to be coded in familiar programming languages with constructs like loops and conditionals. The speaker points out that all these tools compile down to CloudFormation, making knowledge of CloudFormation essential for debugging.
π Getting Started with CloudFormation
The speaker suggests using AWS SAM for beginners due to its simplicity and the ease of using a CLI tool for quick development cycles. The process of getting started with SAM and CloudFormation is recommended, starting with basic resources like Lambda functions and S3 buckets. The speaker plans to release a follow-up video on getting started with SAM and CloudFormation for serverless application development. The video concludes with a call to action for viewers to explore more AWS and software engineering content on the speaker's channel and to like and subscribe.
Mindmap
Keywords
π‘AWS CloudFormation
π‘Infrastructure as Code (IaC)
π‘YAML
π‘Stacks
π‘Change Sets
π‘Continuous Integration (CI)
π‘Serverless Application Model (SAM)
π‘Serverless Framework
π‘Terraform
π‘AWS Cloud Development Kit (CDK)
π‘Drift
Highlights
Introduction to AWS CloudFormation, one of the favorite AWS services of the speaker.
Explanation of why AWS CloudFormation is an important skill in the software industry, though it can be intimidating to learn.
Overview of what to expect from the video, including an introduction to CloudFormation, key concepts, pros and cons, comparison with other IaC solutions, and how to get started.
Simple example to illustrate the concept of CloudFormation using AWS services like API Gateway and Lambda Function.
Discussion on the complexity of managing AWS resources manually and the solution provided by CloudFormation.
Explanation of how CloudFormation works as an Infrastructure as Code (IaC) provider, allowing the creation and deployment of AWS resources through template files.
The benefits of using CloudFormation, such as ease of use, support for regional expansion, and automated rollback in case of errors.
Key concepts of CloudFormation including template files in YAML or JSON, resources, stacks, and change sets.
Pros of CloudFormation like simplicity, regional expansion support, code review mechanisms, and CI integration.
Cons of CloudFormation, including the steep learning curve, potential dangers of seemingly innocent changes, and the issue of drift.
Comparison of CloudFormation with other IaC solutions like AWS SAM, Serverless Framework, Terraform, and AWS CDK.
Recommendation to start with AWS SAM for beginners due to its simplicity and quick development cycles.
Advice on how to get started with CloudFormation by installing SAM, reading documentation, and experimenting with basic AWS resources.
Mention of a follow-up video on getting started with SAM and CloudFormation for developing serverless applications.
Encouragement for viewers to explore the speaker's channel for more AWS, software engineering, and system design videos.
Transcripts
what is going on guys i am very very
excited about this video because i
finally get to talk to you about one of
my favorite aws services
aws cloud formation and the reason that
i wanted to make this video is not only
because i love aws cloudformation
but because i think it is such an
important skill right now
especially in the software industry but
it could be kind of intimidating to
learn
so what i wanted to do in this video is
just kind of give you a very simple
understanding of what cloudformation is
so in terms of what to expect we're
first going to talk about
what is cloud formation and i'm going to
explain to you with a very simple
example
second we're going to talk about the key
cloud formation concepts
from there we're going to talk about the
pros and cons of using cloud formation
and then from there we're going to talk
about how it compares to some other
popular infrastructure as
code solutions such as terraform
serverless framework aws sam
also known as serverless application
model and
aws cdk which is cloud development kit
and then finally i'm going to talk to
you about how to get started learning
cloud formation
for your next project so first of all
let's explain
what cloudformation is through a very
very simple example
so let's say you're just getting started
on aws and you go ahead on us east one
you're in the aws
console you want to build a rest api and
you're going to use api gateway combined
with a lambda function because it's
super super
easy to build rest apis and by the way i
have a whole video on this and i think i
have one where you can set this up in
eight clicks or something like that
i'll put that in the description so
you're having a good time in aws console
you're doing all this stuff manually
you decide hey i need a database i need
my dynamodb table so you go ahead and
create that
and then you decide later hey i also
needs an s3 bucket to store some of my
log data or some other metadata about my
app
you go ahead and create that and you're
like hey i need some roles that go along
with my lambda function now to access
this stuff
okay then i want aws athena to perform
analytics
i want to create some users for my
business users to access athena
then they gotta get logins and passwords
then you gotta get permissions to them
as well
and you can see this is getting very
very difficult to manage just in this
very simple example
and then what's worse after that well
your boss comes to you and says hey dan
your application is doing really well
we want to move it over to eu west one
because we want to serve
our european customers too and then
you've got to do this and you've got to
do this all through the console
and you better hope you remembered the
name of every resource you
created and all the permissions that you
added and you better hope that you
didn't forget anything because then all
this isn't going to work
and you just feel like this guy this
isn't a good feeling to have to
kind of copy paste all this stuff so no
one wants to feel like this guy no one
wants to look this sad this upset this
frustrated
so there must be a better way what is
the better way
and this is where cloudformation comes
in so wouldn't it be nice
wouldn't it be nice instead of going
into the console and clicking
a thousand buttons and creating all
these things and having to manage them
and remember them
that we can instead write a document
write a file a template file that
defines how each of these things are
created
how they are constructed every
connection between them all the
permissions
and have that all written as code and
wouldn't it be nice
if we can upload that to aws and say aws
can you go ahead
and deploy this file and create your api
gateway create your lambda function
create your roles create your dynamodb
table your s3 bucket
your athena databases your users your
everything wouldn't it be nice if we can
just upload a simple file
to somewhere and get aws to do this
well this is what aws cloudformation is
it is an infrastructure as code provider
that allows you to do
just what i demonstrate it allows you to
create and define
a file and then upload that to aws
cloudformation which is this guy here
and aws cloudformation through a single
click will take that file and go
and deploy every single thing in this
diagram
for you and then give you status updates
on the way to say yeah this is done
that's done that's done
and then oops what if something goes
wrong maybe your lambda function is
having a problem
it'll automatically roll back for you
wouldn't that be nice
well that's exactly what aws
cloudformation is and that's why it's so
awesome
it's so easy to use all you do is define
your template files
you upload them there's a couple
different means to upload them which
we'll get to in a second
it's great for regional expansion so if
you want to move all this stuff to a
different region if your business is
quickly growing then it's great for that
it's got a whole bunch of other benefits
but this is the main idea you write a
template file
you upload that to cloudformation in
this case and that is responsible for
creating
all of this different stuff here that is
what cloudformation is in a nutshell
so let's move on to the key concepts of
cloudformation now
uh so the first one is that you create
these
uh template files that are in either
yaml or
json now for whatever reason yaml has
really taken off i don't know why you
would expect that everyone would use
json
but it seems like the community has
decided that yaml is the way to go
and i've been doing this for a while and
i gotta say it looks pretty clean when
you use yaml compared to json so i'm
all for that but anyways you define
these templates and these template files
contain
resources and the resources are
essentially all the aws things that you
want to create
your you know s3 buckets your sqs cues
your
im rolls your users everything that goes
with it
so that is the first concept so what do
these templates even look like
well this is a example of a lambda
function
in a yaml format so what are we looking
at here well this is the name
of your resource and the type of your
resource is a lambda function
and then you're defining some properties
on that lambda function and you're
saying the handler's
input file is the index.handler you're
seeing it has a role called this guy
and this example is actually doing
something fairly interesting typically
what you would do with the lambda
function
is in the code section here you would
give it a zip file that's located in s3
but what they're doing here is actually
kind of interesting it's it's a little
bit of a shortcut so they're using
substitution
to do some inline javascript so all this
javascript down here this is going to be
the definition of your lambda function
and then finally it lets you specify the
runtime of it
now this is how you would define in this
case a lambda function but it's the same
format for every other aws resource you
just specify the type
if you want an sqsq you put that here if
you want an s3 bucket you put that here
there's recipes that you can follow and
this stuff is very very well documented
so that is the first concept you kind of
define these yaml or json files that are
called templates and they contain it of
us
resources so the second key concept is
something called stacks
and these are the things that are the
logical groupings of your templates and
their resources so maybe you would
set this up on an application level so
every application has a different stack
you can combine multiple template files
together so you can kind of sum them up
and deploy them all at once
with the same stack you can also create
something called
nested stacks where you can have kind of
graph like relationships between your
stacks if you want to deploy something a
little bit more complex
but that's stacks and the third main
concept to know about is something
called change sets
and what change sets are are basically a
diff
between what cloudformation has from
your previous upload
and what you are attempting to upload so
they are the diff between those two
things
similar to what you would see on git if
you have a diff between two git commits
uh so what change sets basically do is
show you a preview of what
cloudformation is going to do in its
incremental update
so cloudformation always updates
incrementally it always looks at what
has
changed since your last upload and only
performs updates on things that have
changed so that's how cloud formation
works it works in incremental steps
so those are the key concepts now let's
talk about some of the pros and cons of
cloudformation so in terms of the pros i
kind of mentioned a lot of them here
but it makes your life just a whole lot
easier it's very simple and quick to
whip together some recipes that can do
some pretty complicated things
like i said it's also great for regional
expansion so you can very very quickly
deploy this out to multiple different
regions
with just a couple clicks second it
allows you to introduce code review
mechanisms for infrastructure changes
i can't tell you how many times i've
seen people accidentally fat finger
something
and delete either a queue a database a
bucket a file
something on aws and you just think why
why did you do this to yourself so using
infrastructure as code and cloud
formation in particular you can add an
additional layer of verification to your
infrastructure
change process through code reviews so
instead of someone just going in there
and making changes directly in the
console without anyone knowing
you can kind of release your
infrastructure updates through a change
management process
that is backed by code reviews uh the
third main pro is that you can very
easily integrate this with the ci
pipeline ci stands for continuous
integration
so you can attach your yaml or json
template files to
things like github hooks and based on
changes to your files it'll
automatically trigger a
pipeline in aws through code pipeline
and deploy all your changes through
cloudformation
so it's very very quick and easy to get
started with this and introduce a full
ci pipeline for your infrastructure
changes
fourth it's got a huge community support
cloudformation has been around for many
years
uh it's not a new service by any means
there's tons of stack overflow help tons
of community volunteers that'll help you
kind of work through some of your
problems so
you're not alone if you face some issues
with cloud formation
now in terms of the cons every great
thing has its set of weaknesses and
cloud formation is no different
so the first con is that it's a little
bit of a steep learning curve
and i would say that this is less true
more recently because like i said it's
got a large community support and
there's tons of examples out there
but it's just a little bit difficult
getting started because there's a lot of
concepts at play and a lot of different
recipes and things that can go wrong
that can impact you so i would say it's
got a steep learning curve but once you
learn the main concepts this stuff is
cake like it's very very easy to
understand
the second main con is that i learned
this the hard way which is that innocent
looking changes can be dangerous
and what i mean by this is that in my
particular case
if you change the name of a resource
such as a dynamodb
table or a database instance or whatever
changing the name will
cause cloudformation to delete that
thing and spin up a new one
and when it deletes it there goes all
your data so
you gotta understand the nuances of
cloudformation formation because
unfortunately these things do exist and
it can't come to bite you so you just
kind of need to be aware of them before
you get started
and the third one is there's this
concept of drift and it can be painful
if you're not aware of it
and drift is this concept that
cloudformation keeps a snapshot of what
it
thinks the state of your aws account is
and all the resources that are tied to
your cloudformation stack
and it kind of persists this snapshot
and that snapshot typically only changes
when you perform an update through a
change set through that process that i
spoke to you
before about however if you come
you know through your aws console or
through to your aws cli
and you make a modification directly to
some of the resources that your
cloudformation stack is in charge of
maintaining
then that causes drift which is an out
of sync issue where cloudformation
thinks
that your resource is set up in this way
but in fact on aws
it is set up in a different way so what
i'm trying to say here is that when you
start
using cloudformation to manage your
resources you kind of need to
treat your aws account as read-only you
shouldn't be making manual changes
in your account anymore that'll cause a
concept called drift
and it can actually cause your
deployments to fail on cloud formation
uh so be aware of drift it's i label it
as a con but maybe it's just kind of a
negative feature about cloud formation
so we talked about what's good and
what's bad now let's talk about
uh kind of how does it compare to some
other popular infrastructure as
code solutions uh so the first one that
i want to talk about is aws sam stands
for serverless application management
and under the hood sam actually uses
cloudformation
it's great for setting up like it says
serverless applications so lambdas api
gateways
it really helps you build serverless
applications very quickly
now on the other side of that coin is
the serverless framework which i would
say
is pretty much a direct competitor to
aws sam
but interestingly serverless also uses
cloud formation under the hood
but it uses kind of a wrapper language
on top of it
that you need to use but it looks very
very similar to what cloudformation
looks like
so these are very very similar sam and
serverless there's not too much
differences between them but
you know one is supported and built by
aws one is not so
take that as your deciding factor
perhaps
now the next popular one is terraform
and what terraform is great at
is if you have a kind of mix and match
scenario where some of your
infrastructure may be on
azure some of it may be on aws some of
it may be elsewhere
in another cloud provider terraform is a
great wrapper on top
of cloud infrastructure concepts which
allows you to be provider agnostic
a lot of people like to say that
terraform is more dedicated to
infrastructure i don't think i would
necessarily agree with that but that's
kind of what the community has decided
and then finally there's aws cloud
development kit and this is kind of a
newer offering from aws
and cdk allows you to write actual
javascript or typescript or some other
languages as well
and declare your infrastructure as code
in your template files as opposed to
using
this json or yaml notation so it allows
you to use
constructs like if statements for loops
all that kind of stuff that you would
expect in a standard programming
language and because of that it allows
you to do some very interesting and
flexible things
so this is kind of the newer hotter
thing to learn right now cloud
development kit
now another thing that i wanted to point
out was that all of these sam
serverless terraform and cdk all compile
down to cloud formation to deploy to aws
so regardless of which one of these
things that you choose
if you're ever facing problems with any
of these frameworks
you're probably going to need to know
how cloud formation works to debug the
problem
so it's a very good starting point very
good foundational
skill to learn because it's going to be
present in all of these different
frameworks and actually some of the
notation is almost identical
to what you would see in a cloud
formation template file
in yaml now if you're just getting
started i would suggest to probably
learn sam first and the reason i say
this is because
if you're trying to get started through
the console it's not a very good process
in terms of development cycles
you kind of got to upload a new template
file every time you make a change
try it out see if it fails you know make
a change again upload it try it out
yada yada yada now if you're using sam
it comes with a handy cli tool in fact
these all do so maybe this applies to
all these different ones but
i i learned on sam i think it's
straightforward but anyways because
you're using a cli
tool to update your cloudformation stack
your very very quick cycles because you
just define your cloudformation file
locally so it allows you to test things
out kind of just get your feet wet and
experiment a little bit
so i would definitely use sam when
you're getting started in terms of like
mechanically what should you do to get
started install sam
read some of the documentation on aws
cloudformation and just get started with
something basic like a lambda function
and maybe like an s3 bucket just get
your feet wet and just create some stuff
like anything you learn by doing and
cloud formation is no exception
so i'm going to be coming out with a
follow-up video to this which is kind of
getting started with sam and getting
started with cloudformation to develop
serverless applications so i'll put that
in the description section when it is
available
and if you like this video be sure to
check out my channel i have a whole
bunch of aws
and software engineering system design
videos available on my channel
and as always please don't forget to
like and subscribe and i'll see you next
time
Browse More Related Video
Day-16 | Infrastructure as Code | #terraform #IaC
How To Deploy Serverless SAM Using Code Pipeline (5 Min) | Using AWS Code Build & Code Commit
Intro to AWS - The Most Important Services To Learn
How to Run a Python Docker Image on AWS Lambda
AWS Cloudformation Step by Step Tutorial - Create a DynamoDB Table!
Top 50+ AWS Services Explained in 10 Minutes
5.0 / 5 (0 votes)