How to Code Any AWS CloudFormation | Step By Step Coding

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello boys and girls I really wanted to teach you guys and girls how to code any confirmation so I thought instead of just giving you some formation and just going over it because that's easy I wanted to show you how I called any transformation in my professional life like how I start with the best template how do I search for syntaxes how do I build on top of it all the inner working of it and this is like I wanted to code with you guys and girls I mean sometimes you will see in this video that I'll start something and I did not find what I was hoping for some pivot and find alternative approach so that's why the video is a little long so take a break if you need to I did not wanted to break the video into two parts because I felt like it it will lose its continuity and the flow alright with that being said let's jump into it okay so what should we build so he c2 is a very very commonly used infrastructure however let's put a twist how about we also going to create I am role and then attach it to the AC to but this is also used in real-world projects where you have to use a specific I am role and we're gonna create this I am role in conformation as well also let's create a SNS topic however I just don't want to create a vanilla SNS topic so here is the twist we want to have a condition so we want to create a service topic with email we want to use one email if the environment is test and we want to use another email address if the environment is prod how about that and I'm going to show you how to look up a reference guide sample templates and stitch together pretty much any template you can think of alright so what are the things that will be involved mappings parameter pseudo parameters intrinsic functions conditionals outputs resource and a good bit of googling okay with that being said let's get started okay so the first thing I do is I pick a resource and try to get a sample template for it because you don't want to code everything from scratch like every transformation template will have some common sections right like parameter resources output I want to have a best template handy and then I can build on it so that I can see the sections copy paste all that good stuff so for our case I'm gonna start with the Amazon ec2 right because that's the biggest piece so what I'm gonna do is I'm going to search for Amazon ec2 sample template in the cloud formation so the first thing I search for is in the sample confirmation a template so I start simple plot formation template I generally click the first link okay and then browse sample templates by AWS service okay here we go Amazon ec2 okay and then I click view in designer why do I click view in designer it's because whether you want JSON or yomo you could change it here right so the default is JSON you can easily switch to llamó however I'm going to go back to Jason for this one it doesn't matter you can use the mo as well so I'm gonna copy all this then I'm gonna go back to my trusty if he's washed with your code I have the file open I'm gonna save this as a JSON file so we can have the syntax check and all that good stuff okay I named it code any confirmation underscore fashion one dot Jason I'm gonna pest this so what does this confirmation have so let's see so under parameter we have this key name and then instance type okay SSH location and then we have the mappings so this is handy right we already have the mappings depending on the region and architecture it's gonna pick up a my ID but we are gonna take a look at that so don't worry okay so then we have this ec2 instance however there is no instance role attached to the CC - so it's just gonna create a default role but we're gonna change that right and then we have the security group which is creating and it has couple of outputs okay now let's try to attach a role how about that so now to get the syntax of that I will generally search like this AWS ec2 cloud formation so this time I am looking for the actual type in confirmation like AWS : currency to clone : instance so I'm gonna click that okay so these are all the possible properties so which one will be the instance role okay I am instance profile so this is a possibility let's see let's go down okay there is no other thing as instance role or anything so let's click this I am instance profile so the type is string however it doesn't give us much information here right I was expecting for some sample example or something so I'm gonna go back to Google and I'm gonna type I am raw cloud formation so basically I'm looking for sin taxes on how to create a I am role so when I search for that I always look for the actual type so AWS : : i am : control so this is the documentation so let's click that so these are all the parameters I'm gonna scroll down to see if there are any examples okay there are some examples I am role with embedded policy and instance profiles this is good so what I'm gonna do is copy this so what it is doing let's see type is I am wrong and then it's allowing ec2 to assume this role so basically this role can be used by ec2 and then if you want this role to be used by something else like lambda or something so instead of ec2 you can just put lambda calm okay this is the policy document it's creating a policy called route and then it's allowing everything okay and that is generating a I am instance profile from that route role okay this sounds pretty good so we have to include this in the resources section okay so I'm gonna copy this however if you are in JSON be cognizant of this curly braces right okay so let's see I'm going to copy this I'm gonna leave the last two curly braces okay go back to our best template and then I'm gonna paste it here now with that past this here and then put our comma let's see okay routine strands profiles so this is the I am instance profile so I'm not copy this okay so the name of this property is I am instance profile so under properties I'm just going to put it here instance profile again this is a string remember just gonna graph this reference the instance profile role that is created this red color is scary isn't it okay so I we assigned a role to this okay so now let's do this Amazon SMS okay so I'm gonna go look for Amazon SMS example I always go back to the sample templates okay so we don't have SNS air so I'm just going to Google SMS CloudFormation okay and then I always click the colon colon one the actual documentation okay so this is the syntax and then I always look for an actual example we could use that but let me see there anything else there's nothing else so I want to copy this whole thing okay so back to our confirmation let us past this I want to do this after easy to put a comma here okay so we don't need these two different end points somewhere delete ones so in Visual Studio code if you click on a curly brace it shows the matching curly brace so that you know exactly what to delete so I'm going to delete this okay and this end point end point we have to do some magic because we have a conditional selection of the email so let's look up the protocol for emails I think it's just email but but let's take a look so protocol is under subscription okay so let's scroll up and try to find subscription ok subscription type list so it's basically at least like a third bracket thing and then let's click subscription protocol so basically we are looking for protocol type so if I click protocol see the protocol parameters of subscribe ok where is the protocol here we go protocol ok the protocol you want to use supported protocol HTTP HTTP email email JSON SMS sqs application lambda so email so I'm gonna go back to our JSON okay so I'm gonna make this email you know I don't know if this topic name is required or mandatory I'm gonna I'm gonna check actually okay topic name let me click this required no so I'm gonna remove it okay I will let CloudFormation create the topic name okay now this endpoint right so generally this is where you can put an email like if you want to put an email address what you could do is put a ref you can put like SMS email that means that you have to get a parameter named SMS email except the email for the user and then use it as endpoint however we want to do a conditional email right so now let's take a look at how condition works so go back to trusty Google but for mation condition okay conditions okay I'm going to click this how to use conditions okay logical ID intrinsic function so we probably want either F and if our FN equals but let's but let's take a look examples okay this is the money thing we want examples so this is how you set conditions this will set this create progress SS like true if environment type is equals to prod and then you can use this flag in actual resources this is actually good we can we can reuse this okay let's do this let's let's copy this conditions thing go back to our JSON okay and then remember conditions is it separate section not resources okay and then this environment type has to be a parameter so I'm going to go back this is the parameters and env type okay this is perfect so I'm gonna copy this so again if you are using JSON be mindful of the curly braces if you are using llamo be mindful of the indentations and also all the examples that we see here it's given in both Jason and llamo C so it doesn't really matter what you want to use again like people make a big deal out of it it's it's really like you guys and girls saw in the lecture it's really easy to change and all the examples in the SS documentation from the reference guide is actually given in both rameters how are they put it here default tense type string allowed bellows prod our test okay that sounds good so let's go back to the SMS okay so we down we have to use this flag to determine the end point of SNS let's go back to the conditions let's take a look at the if function right because that sounded kind of hopeful okay I wish there was a link here I guess I'm not to click here okay returns one value if the specified condition evaluates to true and another value if the specified condition and other stuff Falls okay this is perfect actually and then you give the condition name so we already have the condition name which is setting as true or false depending on the environment input and then I'm just gonna put two emails there one if value is true another if the value is false let's see if we have an example okay so yeah so it's pretty straightforward so hope security groups is gonna use if this flag is set to true it's gonna use this ref new security group if it is false is gonna use this existing security group however this case sets its referencing because it's probably creating in the confirmation or it's getting from the input parameter for us we I'm just gonna put the email limbs so let's do this so what I'm going to do is I'm going to copy this thing so this is a third bracket this is third bracket so it was funny I grew up in India and India the parenthesis here is called first bracket the curly braces here is called second bracket in India and this bracket is called hard bracket but anywhere in point so here let's pass this okay and what was the name of our flag conditions create progress SS how would it change this we change this as determining email how about that and take a note that this flag will become true if the environment type is and copy this down okay name of the condition is determine email and then if this is true so basically this is prod okay so now let's put the Prada mail how about when there's a problem in the prod we always emails Big Boss right about best company.com how about okay and then for this one okay if there's a problem in the test very we email developer at best company.com let's take a look at the outputs as well what are we outputting okay we are putting instance size D availabilities on public dns public IP I think this is a good stuff okay so one more thing I wanted to go over this mapping because you will encounter this a lot so let's make sure you guys and girls understand so the image ID is the property in question and then it has two properties to find in map so we should always start from the inner one the second one so what is this one doing so it's going to this AWS instance type to architecture and then depending on the instance type is picking up the value of the architecture so let's go to this mapping table so I'm gonna ctrl F so this is thus mapping so if you say you want to spin up like a t2 Micro it's gonna return architecture which is HV m64 let's go back now at this point we have h vm 64 and then what it is doing is it's passing the region in this table and the second parameter is h vm 64 so in this table depending on the region I'm gonna pick up the ami for h vm 64 so it will become more clear so let's see let's copy this okay alright so in this table the region is the pseudo parameter AWS corn corn region so if you are running it in us os/2 let's say for example we already have hvm 64 from the other mapping and then it's gonna pick up this mi and then this is gonna get assigned to the image ID so image ID will have that ami fellow and then it will spin up the I see - all right so now let's let's try to run this and see what happens creates dark yeah create template in designer click template pest I want to refresh this to see the picture okay this little funky ec2 instance referring route instance instance group route role and then this separate - honest topic okay I'm gonna upload this click Next okay environment type test our products about it select prod instance type t2 micro key name this click Next okay click Next click Next okay because I remember we are creating a I am role is asking for our acknowledgement I acknowledge okay I want to pause the video and come back okay we are back so actually our confirmation completed successfully honestly I was actually coding with you guys and girls this is good news it's not like I ran beforehand then checked on stuff alright so let's take a look at our resources okay so it created this route roll route instance profile I sent as topic instance security group an ec2 instance so let's take a look at ec2 instance first okay so I am roll is the one that got created in confirmation that's good so now let's take a look at the SMS topics code any CFT this is our topic and remember we put production the Pradas environment so the eighth point is big boss at best company calm all right cousin growls so this is how you code any confirmation and then some stuff as you do more like the name of the intrinsic functions hard to use will come to you naturally however there's always Google like I showed you I showed you my process of how I create unique conformation our cousin girls that is the video if you like this video please like and subscribe also if you are interested learning CloudFormation cdk with some DevOps and some interview guides feel free to check out my course in udemy this is currently highest rated for confirmation I'll give the link in the description there is a sale going on currently orgasm girls I'll see you in the next video bye
Info
Channel: Cloud With Raj
Views: 22,881
Rating: undefined out of 5
Keywords: aws cloudformation, Agent of Change, rajdeep saha aws, Code Any CloudFormation
Id: WlPokWf4VoM
Channel Id: undefined
Length: 20min 4sec (1204 seconds)
Published: Fri Jun 12 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.