AWS Cloudformation Step by Step Tutorial - Create a DynamoDB Table!

Be A Better Dev
19 Dec 202020:43

Summary

TLDRThis tutorial video introduces AWS CloudFormation, guiding viewers through key concepts and the process of creating a CloudFormation stack via the console. It covers the creation of a template file in YAML or JSON format, defining AWS resources like a DynamoDB table and IAM role. The video demonstrates deploying resources, managing changes with change sets, and the convenience of stack deletion to clean up resources systematically. It provides a hands-on example and emphasizes the benefits of Infrastructure as Code using CloudFormation.

Takeaways

  • πŸ“ The video is a guide for beginners on getting started with AWS CloudFormation.
  • πŸ“‘ It introduces the concept of creating a template file in JSON or YAML format, which defines all AWS resources for deployment.
  • πŸ”‘ The script demonstrates using a YAML template to create a DynamoDB table and an IAM role for access.
  • πŸš€ The process involves creating a stack in AWS CloudFormation, which is a logical grouping of AWS resources.
  • πŸ”„ Change sets are used for modifying properties of resources without redeploying the entire stack.
  • πŸ“š The script provides an example of a 'dynamotemplate.yml' file, detailing the structure and properties for a DynamoDB table.
  • πŸ”— The 'DependsOn' attribute in the template file specifies the order of resource creation, ensuring dependencies are met.
  • πŸ›  The video shows how to use the AWS console to create a stack and deploy resources from the template file.
  • πŸ” It explains the importance of specifying the correct IAM role with necessary permissions for resource creation.
  • πŸ›‘ The script mentions the automatic rollback feature of CloudFormation, which reverts to the previous state in case of deployment errors.
  • πŸ—‘οΈ Finally, the video demonstrates how to delete a CloudFormation stack, which also deletes all associated resources, emphasizing caution due to its impact.

Q & A

  • What is the main focus of the video script?

    -The video script focuses on explaining the key concepts of AWS CloudFormation, demonstrating how to create a template file, set up a CloudFormation stack, and deploy resources to an AWS account.

  • What is the purpose of a CloudFormation template file?

    -A CloudFormation template file is a definition file that specifies all the AWS resources to be created when the file is uploaded into CloudFormation.

  • What are the two formats that CloudFormation template files can be in?

    -CloudFormation template files can be in JSON or YAML (YML) format, with YAML being the convention most commonly used by the community.

  • What is a CloudFormation stack and what is its role?

    -A CloudFormation stack is a logical grouping of AWS resources that belong to a project. It is used to specify the initial template file to deploy and to manage the resources as a collective unit.

  • What is a change set in the context of AWS CloudFormation?

    -A change set in AWS CloudFormation is used to modify properties of a resource. It allows you to create a preview of the changes needed before applying them to the stack, ensuring incremental updates to resources.

  • How does the 'depends on' attribute in a template file work?

    -The 'depends on' attribute in a CloudFormation template file specifies that the creation of one resource is dependent on the successful creation of another resource, ensuring a particular order of deployment.

  • What is the advantage of using 'depends on' relationships in a CloudFormation template?

    -Using 'depends on' relationships helps in creating a nested sequence of resources that need to be deployed in a certain order, which is crucial for resources that have a specific dependency like a Lambda function needing a log group.

  • What is the process of modifying a CloudFormation stack after its initial creation?

    -To modify a CloudFormation stack, you need to create a change set with the updated template file, preview the changes, and then execute the change set to apply the modifications to the stack.

  • What does CloudFormation do if it detects an error during the deployment process?

    -If CloudFormation detects an error during the deployment process, it will automatically roll back the stack to its previously known state to prevent further issues.

  • How can you delete all the resources associated with a CloudFormation stack?

    -You can delete all the resources associated with a CloudFormation stack by deleting the stack itself. This action will trigger CloudFormation to clean up all underlying resources that were part of the stack.

  • What is the importance of having termination protection enabled on production CloudFormation stacks?

    -Termination protection is important on production CloudFormation stacks to prevent accidental deletion of the stack, which could lead to significant downtime or loss of critical infrastructure.

Outlines

00:00

πŸš€ Introduction to AWS CloudFormation

This video is aimed at helping beginners get started with AWS CloudFormation. It covers key concepts and provides a step-by-step guide to setting up a CloudFormation stack to deploy resources to an AWS account. The video emphasizes the creation of a template file in JSON or YAML format, with YAML being the preferred format in the community.

05:02

πŸ“‹ Creating and Deploying a CloudFormation Stack

The process of creating a CloudFormation stack involves defining a template file and specifying it during stack creation. The stack groups AWS resources logically, and upon deployment, CloudFormation provisions resources like DynamoDB tables and IAM roles as specified in the template file. The video also introduces the concept of change sets, which allow for modifications to the stack by updating the template file and applying the changes.

10:03

πŸ”§ Template File Walkthrough

The video demonstrates an example of a CloudFormation template file named 'dynamotemplate.yml.' This file includes definitions for resources like a DynamoDB table and IAM policies. Key aspects such as specifying resource properties and using the 'depends on' attribute to manage resource creation order are discussed. The importance of defining properties correctly for different AWS services is highlighted.

15:03

πŸ› οΈ Advanced Configuration and Change Sets

Advanced configuration options for CloudFormation stacks are explored, including parameter injection for dynamic values, tagging, and IAM role permissions. The video explains the process of creating and applying change sets to update existing stacks, demonstrating a modification to the provisioned throughput of a DynamoDB table. The CloudFormation console's validation and review steps ensure correct template syntax and preview changes before execution.

20:04

πŸ“€ Deleting a CloudFormation Stack

The video concludes by demonstrating the deletion of a CloudFormation stack, which automatically cleans up all associated resources. It emphasizes the importance of enabling termination protection on production stacks to prevent accidental deletions. The viewer is reminded to be cautious with the delete stack function to avoid unintended disruptions to their environment.

Mindmap

Keywords

πŸ’‘AWS CloudFormation

AWS CloudFormation is a service offered by Amazon Web Services (AWS) that allows users to create and manage AWS resources using templates. It is a key concept in the video as it is the main topic being discussed. The script describes how to use CloudFormation to deploy resources to an AWS account, emphasizing its role in infrastructure management.

πŸ’‘Template file

A template file in the context of AWS CloudFormation is a JSON or YAML file that defines the AWS resources required for a project. The video script mentions creating a template file as the first step in using CloudFormation, highlighting its importance in specifying the resources to be created, such as a DynamoDB table and an IAM role.

πŸ’‘Stack

In AWS CloudFormation, a stack is a logical grouping of AWS resources that are deployed together. The script explains how to create a stack in the CloudFormation console and how it serves as a container for the resources defined in the template file, emphasizing its organizational role in managing related resources.

πŸ’‘Change sets

Change sets in AWS CloudFormation are used when modifications are needed to the resources defined in a stack. The video script describes the process of creating a change set with a modified template file and applying it to update the stack, illustrating how CloudFormation handles incremental changes to infrastructure.

πŸ’‘DynamoDB

DynamoDB is a NoSQL database service provided by AWS, and it is used as an example in the script to demonstrate how to create a database table through a CloudFormation template. The video explains the process of defining a DynamoDB table in the template file and how CloudFormation uses this definition to create the actual table in AWS.

πŸ’‘IAM role

An IAM role, or Identity and Access Management role, is an AWS service that defines a set of permissions for accessing AWS resources. The script mentions creating an IAM role in the template file to allow access to the DynamoDB table, showing how CloudFormation can set up the necessary permissions automatically.

πŸ’‘YAML

YAML, which stands for 'YAML Ain't Markup Language,' is a human-readable data serialization standard used for configuration files and similar tasks. The video script notes that YAML has become a convention for CloudFormation template files, despite JSON also being an option, indicating a preference within the AWS community.

πŸ’‘Depends on

The 'Depends on' keyword in a CloudFormation template file specifies a dependency between resources, dictating the order in which they should be created. The script uses this keyword to illustrate how to ensure that certain resources, like an IAM policy, are created before others that depend on them.

πŸ’‘Provisioned throughput

Provisioned throughput in DynamoDB refers to the capacity units allocated for read and write operations on a table. The script includes an example where the provisioned throughput is modified from 5 to 10, demonstrating how CloudFormation can be used to adjust resource configurations.

πŸ’‘Infrastructure as Code (IaC)

Infrastructure as Code (IaC) is a practice where infrastructure is defined and managed using code-based tools, which in this video is AWS CloudFormation. The script touches on the benefits of IaC, such as version control and repeatability, through the lens of using CloudFormation to manage AWS resources.

Highlights

Introduction to AWS CloudFormation for beginners.

Key concepts of AWS CloudFormation are discussed.

Demonstration of creating a template file for AWS resources.

Template files can be in JSON or YAML format, with YAML being the community convention.

Explanation of how to set up a CloudFormation stack via the console.

Creating a stack involves specifying an initial template file.

CloudFormation deploys resources by reading the template file.

Introduction to the concept of change sets for modifying stack properties.

Creating a change set generates a preview of incremental changes.

Example of a template file that creates a DynamoDB table and IAM role.

Details of the template file structure, including resource properties and types.

The 'DependsOn' attribute for creating resources in a specific order.

How to create an IAM policy and attach it to a role within the template.

Availability of the template file for download in the description section.

Step-by-step guide to creating a stack in the AWS console.

Explanation of stack parameters and their use for dynamic value injection.

The importance of specifying the correct IAM role for resource creation permissions.

Demonstration of stack creation, including the review and creation process.

Observation of stack creation progress and resource ordering.

Verification of the created DynamoDB table in the AWS console.

Modifying the template file to update provisioned throughput.

Creating and executing a change set to update the stack.

Observation of the stack update process and confirmation of changes.

Discussion on the advantages of CloudFormation for infrastructure management.

Demonstration of stack deletion and automatic resource cleanup.

Recommendation to enable termination protection for production stacks.

Transcripts

play00:00

if you've been struggling getting

play00:01

started with aws cloud formation

play00:03

then this is going to be the video for

play00:04

you so in this video we're going to talk

play00:06

about some of the key concepts of aws

play00:09

cloud formation

play00:10

then i'm going to walk you through the

play00:11

console and show you how to set up a

play00:13

cloudformation stack

play00:14

and how to use it to deploy resources to

play00:17

your aws account

play00:18

so let's just jump right into it and

play00:19

start going over what we have in front

play00:21

of us here

play00:22

so the first thing that we need to worry

play00:23

about in terms of cloudformation

play00:25

is creating a template file so that's

play00:28

the first thing that we're going to do

play00:30

after we go through the concepts here

play00:32

we're going to create this template file

play00:34

and a template file is just basically a

play00:36

definition file of all of the aws

play00:39

resources that you're going to be

play00:40

creating

play00:41

when you upload this file into

play00:43

cloudformation in the next few minutes

play00:45

i'm going to show you an example of what

play00:46

one looks like that creates a dynamodb

play00:49

table and an iam role that allows you to

play00:51

access it

play00:52

so that's the first thing we need to do

play00:54

create the template file and the

play00:56

template files can either be in json or

play00:58

yml format

play01:00

for whatever reason yml has really

play01:02

picked up it's really

play01:03

kind of been selected as the convention

play01:05

that the community seems to use for the

play01:06

most part

play01:07

don't ask me why i thought it would be

play01:09

json but it is what it is

play01:11

so just keep that in mind so after we

play01:13

create this template yml

play01:14

file uh we're going to go into aws

play01:17

cloudformation and we are going to

play01:18

create a stack

play01:20

that is going to be our second task and

play01:23

when we create a stack we have to

play01:24

specify an initial

play01:26

template file that we want to deploy to

play01:29

that stack and the stack is just

play01:30

basically like a logical grouping of the

play01:33

aws resources that are going to belong

play01:35

to

play01:35

this project so after we create the

play01:38

stack one of the settings is obviously

play01:40

to define the template file

play01:42

so we're going to select that template

play01:43

file and we're going to tell

play01:44

cloudformation to

play01:46

deploy this stack using this template

play01:49

file that we just specified

play01:50

then cloudformation is going to go out

play01:52

it's going to go to services like

play01:53

dynamodb

play01:55

it's going to go dynomo yep it's going

play01:58

to go to iam

play02:00

and it's going to create all the

play02:01

resources that we specified in step

play02:03

number one over here

play02:05

so that's the basic idea of how you

play02:07

initially get your resources created in

play02:09

cloud formation

play02:11

what comes after that is a concept

play02:13

called change sets

play02:14

so say we want to modify one of the

play02:16

properties of our file over here we want

play02:19

to change some value maybe from

play02:21

x to y or something like that so how

play02:23

this works in cloud formation

play02:25

is you need to create a change set and

play02:28

re-upload that modified file

play02:30

into cloudformation and apply the change

play02:33

set

play02:34

to the stack that you originally created

play02:36

what that's going to do is generate a

play02:38

preview

play02:39

of the changes that it needs to make the

play02:41

incremental changes

play02:43

that is um so if we changed x to y

play02:46

it's going to detect that you know what

play02:47

a resource change and it's going to need

play02:49

to make

play02:50

a modification to that resource when the

play02:52

change set gets executed

play02:54

so like i kind of alluded to we're going

play02:56

to upload that new file we're going to

play02:58

execute the change set

play02:59

and then again cloudformation is going

play03:01

to go out to dynamo

play03:03

or whatever we're modifying in this case

play03:05

and change the value of the dynamodb

play03:08

table so that's what we're going to do

play03:09

in this video i want to walk you through

play03:11

now what the template file looks like

play03:12

because that's an important

play03:14

component of this whole question so

play03:16

let's head over there now all right so

play03:18

here we are looking at a template file

play03:20

and this template file is just called

play03:22

dynamotemplate.yml

play03:24

so let's go through some of the

play03:25

resources here and see what's actually

play03:27

going on

play03:28

uh so the first thing you notice is that

play03:29

we're just specifying a version that's

play03:31

fine you just specify the version that

play03:32

you're going to be using

play03:33

this seems to be the convention here we

play03:36

have resources that we're going to be

play03:37

creating

play03:38

so we're creating a orders table here a

play03:41

named resource called orders table

play03:43

that's going to be a dynamodb table we

play03:46

specify our table name here inside the

play03:48

properties field

play03:50

just keep in mind that whatever resource

play03:52

type you're going to be creating

play03:54

all the properties are going to be

play03:55

different for instance if i were

play03:56

creating a lambda function you wouldn't

play03:58

expect to put a table name

play04:00

for a lambda function it would probably

play04:01

be something like function name so just

play04:03

keep that in mind when you're specifying

play04:04

your properties here

play04:06

so all of these things like attribute

play04:08

definitions author name

play04:09

attribute type string these are all

play04:11

specific properties to dynamodb

play04:14

and we're kind of setting these values

play04:16

through this cloudformation template

play04:18

so you see there's a lot of things that

play04:19

you can specify here such as attribute

play04:21

definitions

play04:22

the key schema if you want this key to

play04:25

be a hash key

play04:26

if you want this key to be a range key

play04:29

you can specify

play04:30

pretty much anything that you can

play04:31

specify in the aws console

play04:33

provided that cloudformation supports

play04:35

the resource type

play04:36

so even further time to lift

play04:38

specification it's a great feature of

play04:40

dynamodb

play04:42

they can also specify things like the

play04:43

provision throughput so the scaling

play04:45

factors on your table

play04:47

so down below over here we have a

play04:49

different resource but i just want to

play04:51

call your attention to this

play04:52

important detail here this depends on a

play04:56

line

play04:56

and what we're doing in this case is

play04:59

we're specifying the name of a different

play05:01

resource dyno db

play05:03

query policy and you see that this thing

play05:06

right here this is what we're referring

play05:08

to right so when i say depends on

play05:10

in this dynamodb table i'm saying the

play05:12

creation of this dynamodb table

play05:14

is dependent on this policy being

play05:17

created first

play05:18

and this can be anything it can be a iam

play05:21

role

play05:22

it can be a lambda function it could be

play05:24

an sqs

play05:25

uh queue it could be anything that you

play05:27

want you can create these complex

play05:29

depends on relationships

play05:30

just by specifying uh depends on here

play05:33

and then creating kind of a nested

play05:34

sequence of things that you want to

play05:36

deploy

play05:37

in a certain order and this makes sense

play05:39

for things that have

play05:40

a particular order in which they need to

play05:43

be created

play05:44

such as a log group on a lambda function

play05:47

the lambda function needs to exist

play05:49

before the law group can exist for that

play05:50

lambda function

play05:52

so there's a whole bunch of use cases

play05:53

here this is a nifty little thing that i

play05:54

wish i knew about earlier

play05:56

uh which is why i wanted to bring it up

play05:57

here and then down here we're creating a

play06:00

dynamo to be query policy

play06:02

we're naming it the dynamodb query

play06:04

policy and by the way these can be two

play06:05

different things

play06:06

um the name of the resource in your

play06:09

cloudformation yml file and the actual

play06:12

name of the entity that you're going to

play06:14

create

play06:15

in iem in this case so you can name this

play06:17

you know like whatever you want

play06:19

and keep dying would be query policy the

play06:21

same and you see the depends on still

play06:23

work so

play06:23

this name can be anything you want is

play06:25

basically what i'm trying to tell you

play06:26

here

play06:27

uh then we create a policy document uh

play06:29

we want to allow dynamo to be query

play06:32

should probably specify the arn of the

play06:33

table i'm about to create but that's a

play06:35

video for another day

play06:37

and then we're going to apply this

play06:39

policy to a role

play06:41

so this role is defined down here and

play06:44

we have some you know basic attributes

play06:46

giving it the sds assume role permission

play06:48

if you don't know what that means don't

play06:50

even worry about it it really doesn't

play06:51

matter

play06:52

so this is the the general idea of

play06:54

creating a

play06:56

template file that has a dynamodb table

play06:58

in it i'm going to be making this code

play06:59

available to you so if you want to try

play07:01

this out yourself

play07:02

check out the description section for a

play07:04

download to this particular file

play07:06

so now that we have this let's head over

play07:08

into the aws console

play07:10

where we will create a stack using this

play07:13

template file and then we're gonna we're

play07:14

gonna modify some of the attributes i'm

play07:16

going to change this from 5 to 10 later

play07:18

and then create a change set and show

play07:20

you how cloudformation responds when you

play07:22

want to modify something

play07:23

so that's coming up in this video so

play07:25

let's move over into the console now

play07:28

alrighty so here we are in the aws

play07:30

console so let's go over to

play07:32

cloudformation

play07:33

cloudformation there we go

play07:37

and so i already have a stack set up

play07:39

here for my website so let's just ignore

play07:40

that we're going to go to the top right

play07:42

over here

play07:43

and we're going to click on create stack

play07:44

and then we're going to say with new

play07:46

resources

play07:47

so this kind of brings up a wizard here

play07:49

where you can specify a whole bunch of

play07:50

different attributes

play07:52

um a couple options in terms of the

play07:54

prerequisites so

play07:55

we've already created a template like i

play07:57

already have one saved

play07:58

to local to disk you can also if you're

play08:00

just getting started use the

play08:02

samples that are available to you here

play08:04

and there's a designer functionality

play08:06

where you can actually drag and drop

play08:08

things

play08:09

and create things kind of through a

play08:10

visual ui haven't had a lot of success

play08:13

with this unfortunately but

play08:14

um if you're trying to set something up

play08:16

that maybe a little bit foreign to you

play08:17

can check that out and maybe just kind

play08:19

of

play08:19

ballpark how everything is going to fit

play08:21

together so let's specify a template

play08:23

down here

play08:25

so there is an option just to refer to a

play08:27

template that is stored in s3

play08:30

uh we don't need that so we're just

play08:31

going to say upload a template file

play08:33

it's asking us to upload a template file

play08:36

i'm going to click on choose

play08:37

i'm going to click on my dynamodb

play08:39

template file here

play08:41

there's a validation step that happens

play08:43

behind the scene so if you have a

play08:45

issue with your template syntax maybe

play08:47

you forgot a space or a tab it should

play08:49

tell you right here

play08:51

so you can actually click this view and

play08:52

designer button i'm not going to do that

play08:54

in this video but this will show you

play08:56

what this template looks like in a ui

play08:59

and it's got a whole bunch of

play09:00

new features where it shows you all the

play09:02

interconnections between them

play09:04

so if you have a little bit of time go

play09:05

check that out since ours is pretty

play09:08

simple we don't need to do that it's

play09:09

just a dynamodb table with a policy and

play09:11

a role so

play09:12

let's just move on so gonna click next

play09:15

now in the bottom right

play09:17

okay now we need to create a stack name

play09:19

so let's just call this dynamodb demo

play09:22

tv demo that looks good

play09:25

the parameter section i didn't take

play09:27

advantage of this in this video but if

play09:29

you want to

play09:30

dynamically inject values into your

play09:33

template

play09:34

and then substitute um a variable with

play09:36

that value you can do that

play09:38

so for instance if you want to use the

play09:40

same template file

play09:41

to deploy to both your test and your

play09:43

production

play09:44

environments um you can pass in a

play09:47

dynamic parameter

play09:49

into your cloudformation stack and then

play09:51

set up your resources such that they are

play09:53

named and appended to them at the end

play09:55

is the name of the environment so it

play09:57

would be either test or production

play09:59

in this case so it's a great way to

play10:00

dynamically set values

play10:02

i'm not going to go through it in this

play10:04

video because it is a more of an

play10:05

advanced topic but just know that that

play10:07

option exists

play10:08

so let's move on now click on next and

play10:12

a whole bunch of other options available

play10:13

to you so if you want to specify some

play10:15

tags for your cloudformation

play10:17

stack go ahead and do that this could be

play10:18

useful for grouping your applications

play10:21

together

play10:21

if you have a whole bunch of resources

play10:23

that are going to be created out of this

play10:25

we're going to skip that here and the

play10:27

next section is the permission section

play10:29

so what it's asking for here

play10:30

is a iam role that has the permissions

play10:33

to create the resources that you're

play10:35

about to

play10:36

create from the template file so if you

play10:39

don't specify a role here it'll

play10:40

automatically

play10:41

as it's telling you if you don't choose

play10:43

a role cloudformation uses permissions

play10:45

based on your user credentials

play10:47

now since i am a root user i don't need

play10:50

any special permissions

play10:51

i have all the permissions so

play10:52

administrator access

play10:54

but if you don't have that you may need

play10:57

to create a role here

play10:58

that has the correct permission so in

play11:00

this example

play11:02

you would need to give a role the

play11:04

permission to

play11:05

create a dynamo table create a iam

play11:08

policy

play11:08

and create a role it would need those

play11:11

three things

play11:13

i have a video on that if you want to go

play11:14

check it out i'll put that in the

play11:15

description section below

play11:17

on how to create a im role and policy

play11:20

and attach it to there

play11:21

uh okay so moving on a little bit more a

play11:24

whole bunch of more detailed things so

play11:26

in terms of stack policy

play11:28

you can set a policy here as to how you

play11:31

want it to behave

play11:33

so you can upload a file here that

play11:35

contains the definition of that

play11:36

things like preventing uh deletion of

play11:39

your stack if someone fat fingers

play11:40

something and you know accidentally

play11:42

clicks delete stack

play11:43

stuff like that that can all be

play11:44

configured through this file here i wish

play11:46

they had kind of a nice ui to do that

play11:48

but you know unfortunately we got we got

play11:50

what we got

play11:51

uh in terms of rollback configuration

play11:52

you can set some alarms to say

play11:54

you know if something happens as as a

play11:56

result of this deployment and it

play11:58

triggers some sns topic

play12:00

then automatically roll back the

play12:01

creation of the stack that's a useful

play12:03

thing that i didn't really talk about

play12:05

which was that

play12:05

um cloud formation will automatically

play12:08

roll back

play12:09

to its previously known state if it

play12:11

detects that there's an error during the

play12:13

deployment process so pretty neat

play12:15

functionality

play12:16

i'm going to minimize that notification

play12:18

options if you want sns topic alerts

play12:21

for every state as the resources are

play12:23

being created so every state update like

play12:25

dynamodb table created dynamodb table

play12:28

updated things like that you can specify

play12:29

an arn here

play12:30

and i don't know maybe make a lambda

play12:32

function or something that listens to it

play12:34

and does something special

play12:35

not what we're going to do here and then

play12:38

stack creation options so

play12:40

more things and this is where the i

play12:42

believe the stack policy comes into

play12:44

place it affects things like this

play12:46

not 100 sure though but we're going to

play12:48

leave this stuff as default as it

play12:49

doesn't really matter for this exercise

play12:52

and just move on to the creation step so

play12:54

on the bottom right now i'm going to

play12:55

click on

play12:56

next and this should be the last step so

play12:59

we can set our parameters

play13:00

configure options and this is just a

play13:02

review step

play13:03

so we're just going to scroll all the

play13:05

way down you have to click this checkbox

play13:07

here which says that

play13:09

cloudformation is going to create iem

play13:10

resources and that's because i left that

play13:13

role blank in the middle i'm the the

play13:15

root user so it's going to create a role

play13:17

that has all the permissions i need for

play13:20

this exercise so let's click this

play13:22

box here and now we're going to click on

play13:24

create a stack and watch the magic

play13:25

happen

play13:26

so let's click on this guy and so what

play13:29

do we see here so we see

play13:30

our stack over here on the left we see

play13:34

here let me just minimize here so this

play13:36

doesn't look too funky oh that's weird

play13:38

okay never mind

play13:39

we see create in progress so this stack

play13:41

is being created

play13:42

going to click on the refresh button

play13:44

you're going to see this stuff change

play13:45

over time

play13:46

so this is the initial stack here dyno

play13:48

would be demo remember i had that

play13:51

depends on thing in my dynamodb table so

play13:54

we can see here

play13:55

the order in which it's creating the

play13:57

resources it's

play13:59

it's choosing the query role or the

play14:01

orders table query rule

play14:03

ahead of the dynamodb table because we

play14:06

specified

play14:07

that depends on in the template file

play14:10

so it respects the ordering which is

play14:12

pretty cool so you see here

play14:15

after a bunch of things change but let's

play14:17

just go through this one by one

play14:18

so we see here that the orders table

play14:20

query role was uh created

play14:22

successfully we see the policy started

play14:24

creating progress

play14:25

we see um okay there's a different step

play14:28

here for that that's fine

play14:30

we see it successfully created and then

play14:32

finally the orders table is getting

play14:34

going now so we should just keep an eye

play14:36

on this

play14:37

so the orders table was created

play14:38

successfully and the stack is now done

play14:41

so if i click on refresh nothing's going

play14:42

to happen anymore now so let's just go

play14:44

over really quick to dynamodb

play14:46

and just verify that our table is

play14:48

actually there right or else what is all

play14:50

this for

play14:51

uh so clicking on that let's see dynamo

play14:54

what do you got for us

play14:55

and there's our table so it's got

play14:57

authors table prod which is what we

play14:59

named it in the template file

play15:01

it's got our author name which was our

play15:03

hash key and our sort key

play15:05

which is book title so everything seemed

play15:07

to work pretty well that's great for us

play15:10

so the next step is we wanted to modify

play15:13

something on this

play15:14

um template file that we created so

play15:16

let's go modify our template file now

play15:18

just with a small change

play15:19

and see how that impacts our

play15:21

cloudformation stack

play15:23

so here's the original template file i'm

play15:25

just going to make a small innocent

play15:27

change

play15:28

provision through but we're going to

play15:29

change this value from 5 to

play15:31

10. i'm just going to click on control

play15:33

save now so now this is saved to my disk

play15:37

so now what do we need to do what we

play15:39

want to create a

play15:40

change set so there we go so we're going

play15:43

to click on stack

play15:44

actions when we are in our stack so

play15:46

dynamically demo in this case

play15:48

click on stack actions in the top right

play15:51

and then we are going to create a change

play15:53

set

play15:54

for the current stack and this is

play15:56

basically the repeat

play15:57

of the step that we did when we

play15:59

initially created the stack so

play16:01

same thing is going to happen here you

play16:03

can you know use your current one or you

play16:04

can replace it

play16:06

i'm going to replace it with the one

play16:07

that we just modified

play16:09

so upload file and then just choose the

play16:12

updated one there everything's looking

play16:15

good click on next

play16:16

no parameters keep on moving none of

play16:19

this matters

play16:21

keep on moving none of this matters

play16:23

again and

play16:25

this should finally be the last one so

play16:27

create change set so the change set is a

play16:29

preview of how the stack will be

play16:30

configured before creating the stack

play16:32

it allows you to examine various

play16:34

configurations before executing the

play16:35

change set

play16:36

so as it kind of describes here

play16:38

cloudformation is going to diff

play16:39

what it has on file of what it thinks

play16:42

the current state is of your dynamodb

play16:44

table or your stack in this case and

play16:46

then it's going to compare it with what

play16:48

you just uploaded so it's basically a

play16:49

git diff between

play16:50

template files so we're gonna click on

play16:52

create change set

play16:54

and after a moment here so yeah it's

play16:56

still creating it's probably just gonna

play16:58

take a second here

play16:59

to create the diff it was pretty quick

play17:01

because this was a small file so let's

play17:02

see what we got going

play17:04

on so we see here that a modification is

play17:06

required

play17:07

for the orders table so it detected that

play17:10

nothing changed with the iam role

play17:12

nothing changed with the policy but

play17:15

something did change with the table

play17:17

so it's smart enough to detect that and

play17:19

now it knows that when i go and execute

play17:21

this change set

play17:22

the only thing i need to do is modify

play17:24

the authors table in this case

play17:26

if you click on some of these guys you

play17:28

can see some of the interesting

play17:30

properties i don't think inputs has

play17:32

anything no it doesn't it's a

play17:34

template this shows you basically what

play17:35

you just uploaded um you know nothing

play17:37

special here you can see

play17:39

the recapacity units got set to 10 so

play17:41

everything is looking good

play17:43

and then this thing i believe does shows

play17:45

you a diff if i'm not mistaken

play17:47

no it doesn't um but it does show you

play17:50

some of the guts of how cloud formation

play17:52

works right like oh here it is

play17:53

so target provision throughput uh

play17:56

attribute properties and these must be

play17:58

passed in dynamically

play18:00

and we're seeing it's going to do a

play18:01

direct modification so this just shows

play18:03

you kind of what's going on under the

play18:05

hood in cloud formation

play18:06

it must use this kind of syntax to

play18:09

delineate how the modification is going

play18:11

to actually take place and it kind of

play18:13

gives you a neat little preview of it

play18:14

too which is pretty neat

play18:16

um so let's go back here so all we need

play18:19

to do now to actually update the stack

play18:21

with that new value is just click on

play18:22

this bright orange button in the top

play18:23

right

play18:24

go click on execute and then if we

play18:26

refresh this guy now

play18:28

remember this is our stack page like the

play18:30

previous run

play18:31

completed now we see update in progress

play18:33

i'm gonna click on that

play18:35

and it's still gonna update this may

play18:37

take a little time because provision

play18:38

throughput sometimes takes a little bit

play18:40

but we're not going to dwell on this if

play18:42

this takes too long

play18:44

because it was just something minor so

play18:47

from here the other interesting part of

play18:49

cloud formation a real big advantage of

play18:51

it

play18:51

actually is that now if i want to delete

play18:54

everything in this application

play18:56

like i want to delete the table i want

play18:57

to create delete the

play18:59

policy i want to delete the role i don't

play19:01

need to worry about going to clean all

play19:03

that

play19:04

stuff up all i could need to do is

play19:06

delete the dynamodb demo stack

play19:09

and when it gets deleted confirmation is

play19:11

going to take care of deleting

play19:13

all the underlying resources as well

play19:15

that are associated with it so let's

play19:17

just demonstrate that now

play19:18

so you can see here this finally

play19:20

completed let's just head over to

play19:22

dynamo again really quick just to show

play19:24

you and prove that

play19:26

everything did change uh click on that

play19:31

really quick here authors table prod oh

play19:33

wait i just saw it so provisioned

play19:35

there you go so provisioned capacity is

play19:38

now

play19:38

10. previously it was five so we do see

play19:41

that it did indeed work

play19:43

uh so let's just demonstrate the

play19:44

deletion step now and kind of what

play19:45

happens after that

play19:47

so i'm gonna go to the top right here

play19:49

actually oh it's just this button here

play19:50

the delete button

play19:52

so just be careful with this i mean if

play19:54

you have a whole environment that

play19:55

is backed by a cloud formation stack

play19:57

this is a good way to ruin a company

play19:59

or like ruin a product just by clicking

play20:01

this so just be very very very careful

play20:04

with this

play20:04

this is the reason it's always a good

play20:06

idea to have the termination protection

play20:08

enabled

play20:09

on your production cloud formation

play20:11

stacks

play20:12

so i'm going to click on delete now i'm

play20:14

going to click on delete stack

play20:16

and if we refresh this and just watch

play20:18

the event stream

play20:19

we're gonna see everything is going to

play20:21

get torn down

play20:22

and we're going to be left with

play20:24

basically a clean slate

play20:26

um so this is cloud formation i have

play20:28

another great video on infrastructure

play20:30

as code in general and how cloud

play20:31

formation kind of compares to some other

play20:33

providers such as terraform serverless

play20:35

and some other ones

play20:36

i'll put that on the right here so be

play20:37

sure to check that out if you like this

play20:39

video don't forget to like and subscribe

play20:41

and i'll see you next time

Rate This
β˜…
β˜…
β˜…
β˜…
β˜…

5.0 / 5 (0 votes)

Related Tags
AWS CloudFormationTemplate FileStack CreationDynamoDBIAM RoleResource DeploymentChange SetsInfrastructure as CodeCloud StackAWS Tutorial