1 00:00:00,222 --> 00:00:01,574 ‫Now that we've seen resources, 2 00:00:01,574 --> 00:00:02,887 ‫the second most important one 3 00:00:02,887 --> 00:00:04,208 ‫is going to be parameters. 4 00:00:04,208 --> 00:00:06,406 ‫And parameters are a way to provide inputs 5 00:00:06,406 --> 00:00:08,635 ‫to your AWS CloudFormation template. 6 00:00:08,635 --> 00:00:09,877 ‫They're super important to know about 7 00:00:09,877 --> 00:00:11,438 ‫if you want to reuse your templates across 8 00:00:11,438 --> 00:00:15,187 ‫the company or other accounts or regions. 9 00:00:15,187 --> 00:00:18,659 ‫And some inputs cannot be determined ahead of time. 10 00:00:18,659 --> 00:00:20,336 ‫For example, the keep area you're going 11 00:00:20,336 --> 00:00:22,501 ‫to link to instances. 12 00:00:22,501 --> 00:00:25,021 ‫Parameters are very powerful, they can be controlled, 13 00:00:25,021 --> 00:00:26,782 ‫and they can prevent errors down the line 14 00:00:26,782 --> 00:00:30,027 ‫happening in your templates, thanks to types. 15 00:00:30,027 --> 00:00:32,654 ‫So, we've used parameters before 16 00:00:32,654 --> 00:00:35,149 ‫in the first hands on, in which we basically 17 00:00:35,149 --> 00:00:39,095 ‫had to specify the security group description. 18 00:00:39,095 --> 00:00:41,121 ‫So, it was a string and we were asked 19 00:00:41,121 --> 00:00:42,754 ‫for the security group description, 20 00:00:42,754 --> 00:00:45,454 ‫and that was used in the security group itself. 21 00:00:45,454 --> 00:00:47,923 ‫So, you should use the parameter when basically 22 00:00:47,923 --> 00:00:49,164 ‫you ask yourself the question, 23 00:00:49,164 --> 00:00:51,458 ‫"Is this CloudFormation resource configuration 24 00:00:51,458 --> 00:00:53,123 ‫"likely to change in the future?" 25 00:00:53,123 --> 00:00:54,904 ‫If so, you can make it a parameter. 26 00:00:54,904 --> 00:00:56,496 ‫And by doing it as a parameter, 27 00:00:56,496 --> 00:00:59,118 ‫you don't have to re-upload a template to change content. 28 00:00:59,118 --> 00:01:01,663 ‫It's a bit more stable and a bit modualized. 29 00:01:01,663 --> 00:01:03,272 ‫If you do programming, and I hope you do, 30 00:01:03,272 --> 00:01:06,439 ‫you know the advantages of parameters. 31 00:01:07,744 --> 00:01:09,727 ‫Now, parameters can have different settings, 32 00:01:09,727 --> 00:01:11,644 ‫and they can be controlled in many different ways. 33 00:01:11,644 --> 00:01:13,577 ‫I don't think the exam requires you to know 34 00:01:13,577 --> 00:01:16,043 ‫all of these but, for me, for your interest, 35 00:01:16,043 --> 00:01:17,560 ‫I'm just going to name them. 36 00:01:17,560 --> 00:01:19,465 ‫You can have a typing string, number, 37 00:01:19,465 --> 00:01:21,986 ‫CommaDelimitedList, list of a type, 38 00:01:21,986 --> 00:01:23,845 ‫and an AWS Parameter. 39 00:01:23,845 --> 00:01:26,205 ‫As far as description, you can have constraints, 40 00:01:26,205 --> 00:01:27,830 ‫you can have a ConstraintDescription, 41 00:01:27,830 --> 00:01:29,960 ‫a minimum and a max length for string, 42 00:01:29,960 --> 00:01:32,055 ‫a minimum and a max value for numbers, 43 00:01:32,055 --> 00:01:33,997 ‫you can have defaults, AllowedValues 44 00:01:33,997 --> 00:01:36,194 ‫when you want to restrict the number of values 45 00:01:36,194 --> 00:01:38,275 ‫a user can pick, AllowedPattern when you want 46 00:01:38,275 --> 00:01:43,275 ‫to verify the inputs of a user using irregular expression, 47 00:01:43,307 --> 00:01:47,535 ‫and NoEcho if you want to pass in the secrets basically. 48 00:01:47,535 --> 00:01:49,725 ‫So, this is a lot of different optimizations 49 00:01:49,725 --> 00:01:51,164 ‫and parameters you can do. 50 00:01:51,164 --> 00:01:52,725 ‫For now, the only thing we've done is 51 00:01:52,725 --> 00:01:55,438 ‫use a simple string parameter in our thing, 52 00:01:55,438 --> 00:01:57,667 ‫and that's all you should know I think for the exam. 53 00:01:57,667 --> 00:01:59,800 ‫So, how do you reference a parameter? 54 00:01:59,800 --> 00:02:03,087 ‫Well, like this you have to use the function called Ref. 55 00:02:03,087 --> 00:02:05,863 ‫And so, this is the first time we encounter Ref 56 00:02:05,863 --> 00:02:08,496 ‫and functions, but basically interesting functions 57 00:02:08,496 --> 00:02:11,647 ‫in your templates allow you to supercharge it 58 00:02:11,647 --> 00:02:13,317 ‫and to link things up. 59 00:02:13,317 --> 00:02:15,879 ‫And so the Ref function is one of the most used, 60 00:02:15,879 --> 00:02:18,215 ‫and so you use it to reference parameters, 61 00:02:18,215 --> 00:02:19,751 ‫and this way you can use your parameters 62 00:02:19,751 --> 00:02:22,430 ‫anywhere in your templates, so in your resources, 63 00:02:22,430 --> 00:02:27,320 ‫for any type of inputs, and parameters, and configs. 64 00:02:27,320 --> 00:02:32,259 ‫So, the shorthand for a reference function in the YAML 65 00:02:32,259 --> 00:02:35,317 ‫is a little exclamation point Ref. 66 00:02:35,317 --> 00:02:38,433 ‫And this is why, it's just a way for us to have 67 00:02:38,433 --> 00:02:40,973 ‫a much nicer syntax, easier to recognize. 68 00:02:40,973 --> 00:02:43,695 ‫You can use the FN column call in Ref as well, 69 00:02:43,695 --> 00:02:45,743 ‫it's whatever you want, but most likely, 70 00:02:45,743 --> 00:02:50,150 ‫it's going to be this exclamation point Ref for shorthand. 71 00:02:50,150 --> 00:02:52,465 ‫And the function can also be used to reference 72 00:02:52,465 --> 00:02:54,163 ‫other elements within a template. 73 00:02:54,163 --> 00:02:56,184 ‫So, in the template we've been using, 74 00:02:56,184 --> 00:02:58,353 ‫in the parameter section, we had to find 75 00:02:58,353 --> 00:03:01,429 ‫a parameter name security group description. 76 00:03:01,429 --> 00:03:04,839 ‫Turns out that if we look all the way down, 77 00:03:04,839 --> 00:03:07,107 ‫the security group description was used 78 00:03:07,107 --> 00:03:10,139 ‫in this security group description key, 79 00:03:10,139 --> 00:03:13,694 ‫and so we used the Ref function to reference it. 80 00:03:13,694 --> 00:03:15,626 ‫So, this Ref function basically says, 81 00:03:15,626 --> 00:03:18,977 ‫"Whatever the user will put as a parameter value, 82 00:03:18,977 --> 00:03:22,670 ‫"for this parameter key, you want to use this, 83 00:03:22,670 --> 00:03:25,076 ‫"reference it into the group description." 84 00:03:25,076 --> 00:03:26,888 ‫So, it's very simple to think about. 85 00:03:26,888 --> 00:03:28,190 ‫It's just a reference. 86 00:03:28,190 --> 00:03:31,377 ‫But this reference function can also be used somewhere else. 87 00:03:31,377 --> 00:03:33,377 ‫It was used right here, for example, 88 00:03:33,377 --> 00:03:36,557 ‫for security groups, so you can see this reference function 89 00:03:36,557 --> 00:03:39,107 ‫also referenced the SSH security group 90 00:03:39,107 --> 00:03:41,447 ‫that was created under Resources. 91 00:03:41,447 --> 00:03:45,046 ‫So the Ref function can be used both to reference 92 00:03:45,046 --> 00:03:47,157 ‫parameters like the one before, 93 00:03:47,157 --> 00:03:50,827 ‫or it can also be used to reference resources. 94 00:03:50,827 --> 00:03:53,016 ‫So, here we've referenced the two security groups 95 00:03:53,016 --> 00:03:57,274 ‫and within the EIP, we reference MyInstance. 96 00:03:57,274 --> 00:03:59,283 ‫So, as you can see, the name of the reference 97 00:03:59,283 --> 00:04:04,004 ‫is the exact same name as the logical value under Resources. 98 00:04:04,004 --> 00:04:06,682 ‫Finally, you have a concept of Pseudo Parameters, 99 00:04:06,682 --> 00:04:10,468 ‫and these are AWS offer parameters that we can use, 100 00:04:10,468 --> 00:04:12,740 ‫and anytime they're enable by default, 101 00:04:12,740 --> 00:04:14,376 ‫and we get just a bunch of values 102 00:04:14,376 --> 00:04:15,636 ‫you may want to retrieve. 103 00:04:15,636 --> 00:04:18,671 ‫So, we can get an account ID, and you can just 104 00:04:18,671 --> 00:04:20,223 ‫give us the value of the account ID, 105 00:04:20,223 --> 00:04:22,864 ‫notification ARNs, no value if we don't want 106 00:04:22,864 --> 00:04:24,008 ‫to return the value. 107 00:04:24,008 --> 00:04:26,202 ‫We can also ask for the region in which 108 00:04:26,202 --> 00:04:29,767 ‫our address CloudFormation template is being run at, 109 00:04:29,767 --> 00:04:31,366 ‫so for example, US-east-2. 110 00:04:31,366 --> 00:04:33,808 ‫We can also get a pseudo parameter for the Stack ID 111 00:04:33,808 --> 00:04:35,084 ‫or the Stack name. 112 00:04:35,084 --> 00:04:37,487 ‫Basically, you don't need to know about these too much, 113 00:04:37,487 --> 00:04:38,402 ‫maybe the first one. 114 00:04:38,402 --> 00:04:40,342 ‫Account idea's very important to get the value 115 00:04:40,342 --> 00:04:42,070 ‫of the account ID if you were to try to construct 116 00:04:42,070 --> 00:04:46,348 ‫some complicated ARN value in your CloudFormation template. 117 00:04:46,348 --> 00:04:48,230 ‫But overall, you should just know that there is 118 00:04:48,230 --> 00:04:49,992 ‫this concept of pseudo parameters, 119 00:04:49,992 --> 00:04:51,722 ‫and again, you can use them at any time, 120 00:04:51,722 --> 00:04:54,877 ‫just use a Ref, and you're all set. 121 00:04:54,877 --> 00:04:55,898 ‫I hope that was helpful, 122 00:04:55,898 --> 00:04:57,106 ‫I hope you know how they work now 123 00:04:57,106 --> 00:04:58,630 ‫in your CloudFormation templates, 124 00:04:58,630 --> 00:04:59,673 ‫and I will see you in the next lecture.