‫So let's quickly
‫talk about CloudFormation Rollbacks.
‫It's very important to know how they work
‫in case they appear at the exam.
‫So if the stack creation fails,
‫so if you upload a stack and the stack creation fails,
‫by default, everything will roll back.
‫That means will get deleted.
‫And so we can look at the log to understand what happens.
‫But when you create the stack
‫you also have the option to disable the rollback
‫in order to troubleshoot what happened.
‫And gain a bit more insights into what was created.
‫If you update a stack,
‫so it was already created
‫and it's successful and now you update it,
‫if the update fails, the stack will automatically roll back
‫to the previous known working state,
‫which is the green state you just wanted to update.
‫And you get the ability in the log
‫to see what happened
‫thanks to error messages.
‫So this lecture is all about showing you how rollback works.
‫Okay, so let's practice failures.
‫So let's create a stack
‫and we'll upload a template file.
‫And the file I'm going to upload
‫is called triggerfailure.yaml, the number two.
‫So why is this file problematic?
‫Well, if you go into triggerfailure.yaml,
‫you look at the image ID of my EC2 instance,
‫it is an image ID that does not exist.
‫So therefore it's going to create a failure.
‫So let's click on next
‫and I'll call this one TriggerCreationFailure.
‫Click on next.
‫And here, under stack failure options,
‫we have two options.
‫Number one is to roll back all stack resources.
‫That means that they're going to be rolled back
‫to the previous known stable states
‫or we can preserve successfully provisioned resources.
‫And this will keep the successfully provisioned resources
‫and roll back any failed resources
‫to theIR last known stable states.
‫So if we do this,
‫which is the non-default option,
‫and then we click on next
‫and then submit,
‫as you can see,
‫we generate an SSH security group
‫and we generate a server security group.
‫And so as you can see,
‫I need to, first of all, there's one problem
‫that I didn't provide the group description.
‫So it's a good example of the failure of this.
‫So as you can see,
‫even though my server security group
‫was not able to be created
‫my SSH security group was able to be created.
‫And if I go into resources,
‫well one is still being kept.
‫Whereas if you had a creation
‫and by default it would fail,
‫it would delete everything.
‫So this could be the occasion
‫to just troubleshoot if you needed to.
‫But of course, because this leaves some remainders,
‫you need to absolutely delete the stack
‫to get rid of it.
‫So you cannot update the stack and fix things.
‫So we will delete it and now it's gone.
‫So this is showing you the option of what it is
‫when there is a create failure
‫and you can do the exact same thing.
‫So you can create a stack right now,
‫I'll create a stack based on a correct template
‫called just-ec2.yaml
‫and I'll call it FailureOnUpdate.
‫So right now we're good.
‫We know that this is going to work
‫because, well, this is the template
‫we've used from before.
‫So let's wait for things to be created
‫and as we can see, we're good.
‫So I'm going to update my stack
‫and if you don't see this button,
‫just refresh your page.
‫So update my stack,
‫but this time I will replace the template
‫with the template file named TriggerFailure.
‫So this time we'll have a group description called hello.
‫Next.
‫And here we have again the option to roll back
‫all stack resources
‫or to preserve successfully provisioned resources.
‫So we're now we'd say,
‫"Roll back everything and see what happens."
‫And then we'll do the second option right after.
‫So let's click on next
‫and then click on submit.
‫So this is going to create a few security groups
‫and then it's going to trigger a rollback.
‫So my security groups right now are being created.
‫Now they're done.
‫And as you can see,
‫the instance get created,
‫but then there was an update failed,
‫because, well, the invalid AMI was not found,
‫so therefore, what's going to happen?
‫Well, because we have specified everything to roll back,
‫then everything is going to roll back
‫based on the last known state.
‫And so that means that my server,
‫server security group
‫and SSH security groups should disappear.
‫So let's wait for these events to happen.
‫And as you can see right now,
‫my SSH security group
‫and server security group get deleted.
‫And similarly as an exercise,
‫if you update the stack,
‫but this time you choose,
‫again, the Trigger Failure
‫and we'll just enter description again.
‫And under stack failure option,
‫we just say,
‫"Preserve successfully provision resources."
‫Then you know what happens,
‫you can try it out on your own.
‫This would create SSH and server security groups
‫but it would not roll them back
‫in case there is a rollback happening,
‫a stack failure.
‫So this is up to you to choose what you want,
‫but both the behaviors can be desirable
‫based on the what you're trying to do.
‫So when you're done,
‫please go ahead and delete the stack
‫and you'll be good.
‫Alright, that's it.
‫I hope you liked it
‫and I will see you in the next lecture.