1 00:00:00,307 --> 00:00:01,432 ‫So the exam may ask you 2 00:00:01,432 --> 00:00:03,044 ‫about Intrinsic Functions, 3 00:00:03,044 --> 00:00:05,437 ‫and we've seen them, but here is a list of 4 00:00:05,437 --> 00:00:08,123 ‫the ones you should absolutely know for the exam. 5 00:00:08,123 --> 00:00:10,197 ‫The Ref function, the GetAttributes 6 00:00:10,197 --> 00:00:12,496 ‫FindInMap, ImportValue, Join, 7 00:00:12,496 --> 00:00:14,982 ‫Sub, and the Condition Functions. 8 00:00:14,982 --> 00:00:16,948 ‫So, let's go ahead and have a quick 9 00:00:16,948 --> 00:00:19,485 ‫memory refresher on what they are. 10 00:00:19,485 --> 00:00:21,671 ‫The Ref function is to me the most important. 11 00:00:21,671 --> 00:00:24,754 ‫It used to be referencing parameters, 12 00:00:24,754 --> 00:00:26,712 ‫and in case you reference a parameter, 13 00:00:26,712 --> 00:00:29,370 ‫it will return the value of that parameter. 14 00:00:29,370 --> 00:00:30,889 ‫So, we've seen this in practice 15 00:00:30,889 --> 00:00:32,693 ‫when you had the security group description. 16 00:00:32,693 --> 00:00:36,101 ‫And Resources. So if you reference another resource 17 00:00:36,101 --> 00:00:37,876 ‫in your CloudFormation template, 18 00:00:37,876 --> 00:00:39,660 ‫it will return the physical ID 19 00:00:39,660 --> 00:00:41,368 ‫of the underlying resource. 20 00:00:41,368 --> 00:00:43,068 ‫So, for example, if we reference 21 00:00:43,068 --> 00:00:47,068 ‫a EC2 Instance, we will get the EC2 Instance ID. 22 00:00:49,186 --> 00:00:51,875 ‫Now the shorthand for this is going to be 23 00:00:51,875 --> 00:00:54,268 ‫!Ref, and this is what it looks like. 24 00:00:54,268 --> 00:00:57,248 ‫So here is a quick example, we create a Subnet 25 00:00:57,248 --> 00:01:01,402 ‫and for the Properties VpcId, we reference the VPC 26 00:01:01,402 --> 00:01:02,819 ‫that was created from before, 27 00:01:02,819 --> 00:01:05,064 ‫and so what we get out of it is the VpcId. 28 00:01:05,064 --> 00:01:06,872 ‫As I said, when you reference a resource, 29 00:01:06,872 --> 00:01:09,063 ‫it returns the physical ID. 30 00:01:09,063 --> 00:01:11,146 ‫So super important to know. 31 00:01:11,146 --> 00:01:14,346 ‫Now, how do we get other information out of resources? 32 00:01:14,346 --> 00:01:17,782 ‫Right? Because, if we only can get the ID information 33 00:01:17,782 --> 00:01:20,018 ‫out of the resources using a Ref, 34 00:01:20,018 --> 00:01:21,976 ‫then we're pretty much stuck for some things. 35 00:01:21,976 --> 00:01:24,742 ‫So, we can use GetAtt, and attributes can be attached 36 00:01:24,742 --> 00:01:26,642 ‫to any resources you create, 37 00:01:26,642 --> 00:01:28,542 ‫and so to basically get a list 38 00:01:28,542 --> 00:01:30,733 ‫of all the resources and all the attributes 39 00:01:30,733 --> 00:01:33,729 ‫that get exposed from these resources, 40 00:01:33,729 --> 00:01:36,002 ‫you will have to look in the documentation. 41 00:01:36,002 --> 00:01:38,676 ‫So let's do a quick look at it, just to get an idea. 42 00:01:38,676 --> 00:01:41,509 ‫So if we look at our EC2 Instance, 43 00:01:42,618 --> 00:01:45,301 ‫and we go to Return Values, 44 00:01:45,301 --> 00:01:46,543 ‫we can see that there's a Ref. 45 00:01:46,543 --> 00:01:50,917 ‫So the Ref will return the ID of that instance, okay, 46 00:01:50,917 --> 00:01:53,297 ‫and then using the GetAttributes function 47 00:01:53,297 --> 00:01:55,617 ‫we're able to get the AvailabilityZone 48 00:01:55,617 --> 00:01:58,547 ‫the DNS name, the private IP, and so on. 49 00:01:58,547 --> 00:02:00,089 ‫So all these things are exposed. 50 00:02:00,089 --> 00:02:03,497 ‫So to know what attributes are exposed in each resource, 51 00:02:03,497 --> 00:02:04,713 ‫you have to go to the resource, 52 00:02:04,713 --> 00:02:07,722 ‫and look at the documentation. 53 00:02:07,722 --> 00:02:10,232 ‫Now, for example if you want to get the AZ 54 00:02:10,232 --> 00:02:12,217 ‫of an EC2 machine, we saw we could do it. 55 00:02:12,217 --> 00:02:15,026 ‫Here is our resource blogs, so we have our EC2 Instance 56 00:02:15,026 --> 00:02:17,468 ‫with an ImageId, and an InstanceType 57 00:02:17,468 --> 00:02:19,384 ‫and we want to get the AZ out of it, 58 00:02:19,384 --> 00:02:21,838 ‫for example, when we create an EBS Volume. 59 00:02:21,838 --> 00:02:24,452 ‫For this we're going create a new volume under resources, 60 00:02:24,452 --> 00:02:27,493 ‫and we'll say the type is a EC2 volume. 61 00:02:27,493 --> 00:02:30,210 ‫Condition, if we had a condition from before, 62 00:02:30,210 --> 00:02:31,760 ‫but the important thing here and there 63 00:02:31,760 --> 00:02:33,292 ‫is that if you look at the properties, 64 00:02:33,292 --> 00:02:35,900 ‫the size is 100, and the AZ 65 00:02:35,900 --> 00:02:38,833 ‫is using the GetAttribute function, 66 00:02:38,833 --> 00:02:40,583 ‫EC2.AvailabilityZone, 67 00:02:41,730 --> 00:02:45,063 ‫so the EC2 Instance is coming straight out of this name 68 00:02:45,063 --> 00:02:47,872 ‫on the left hand side, and then the dot says, 69 00:02:47,872 --> 00:02:50,923 ‫it tells GetAttribute what we wanna get out of it, 70 00:02:50,923 --> 00:02:53,291 ‫so we wanna get the AvailbilityZone. 71 00:02:53,291 --> 00:02:56,314 ‫So this is quite a popular exam question as well, 72 00:02:56,314 --> 00:02:58,353 ‫you know, how do we get this attribute 73 00:02:58,353 --> 00:03:02,412 ‫of this resource, and the answer is use the GetAtt function. 74 00:03:02,412 --> 00:03:04,240 ‫You have FindInMap, and we've seen this before. 75 00:03:04,240 --> 00:03:06,105 ‫We use this FindInMap function, 76 00:03:06,105 --> 00:03:07,964 ‫and the shorthand syntax is this, 77 00:03:07,964 --> 00:03:09,805 ‫we have to specify the MapName, 78 00:03:09,805 --> 00:03:12,682 ‫the TopLevelKey, and the SecondLevelKey. 79 00:03:12,682 --> 00:03:14,498 ‫And so here is this quick summary. 80 00:03:14,498 --> 00:03:18,231 ‫In this example, we were using the FindInMap function 81 00:03:18,231 --> 00:03:20,189 ‫to find the Image ID, 82 00:03:20,189 --> 00:03:21,863 ‫based on the region we were in, 83 00:03:21,863 --> 00:03:25,670 ‫and the type of architecture, 32 or 64 bits. 84 00:03:25,670 --> 00:03:28,194 ‫ImportValue is to import values 85 00:03:28,194 --> 00:03:31,134 ‫that have been exported as outputs in other templates, 86 00:03:31,134 --> 00:03:33,747 ‫and for this we use the ImportValue function 87 00:03:33,747 --> 00:03:36,706 ‫so again remember, when we import a value, 88 00:03:36,706 --> 00:03:39,035 ‫we just give the ImportValue name 89 00:03:39,035 --> 00:03:42,875 ‫that was exported and it should work just easy. 90 00:03:42,875 --> 00:03:45,035 ‫Now for Join. Join we haven't seen it yet, 91 00:03:45,035 --> 00:03:47,275 ‫but we can join value with a delimiter, 92 00:03:47,275 --> 00:03:48,780 ‫so this is the shorthand syntax, 93 00:03:48,780 --> 00:03:51,575 ‫we define Join, we get the delimeter name 94 00:03:51,575 --> 00:03:55,221 ‫and then we provide a comma-delimited list of values. 95 00:03:55,221 --> 00:03:56,946 ‫To make it slightly more concrete, 96 00:03:56,946 --> 00:03:59,196 ‫to create the a:b:c string, 97 00:04:00,515 --> 00:04:03,601 ‫we can use the Join function with the colon, 98 00:04:03,601 --> 00:04:07,121 ‫and then we specify a, b, c on the right hand side. 99 00:04:07,121 --> 00:04:08,441 ‫So this is, if you do programming, 100 00:04:08,441 --> 00:04:11,095 ‫this is quite a common function in programming. 101 00:04:11,095 --> 00:04:12,031 ‫So, just know about it. 102 00:04:12,031 --> 00:04:13,781 ‫Sometimes, maybe you'll be asked, 103 00:04:13,781 --> 00:04:16,881 ‫hey, what is the output of this Intrinsic Function, 104 00:04:16,881 --> 00:04:18,171 ‫and if you use Join, well you know 105 00:04:18,171 --> 00:04:19,445 ‫that you have to just put the colons 106 00:04:19,445 --> 00:04:22,031 ‫in between the a and the b, and the b and the c. 107 00:04:22,031 --> 00:04:25,731 ‫Okay, finally we have the Sub function. 108 00:04:25,731 --> 00:04:28,991 ‫The sub function is a shorthand for substitutes. 109 00:04:28,991 --> 00:04:30,091 ‫It's super handy, it allows you 110 00:04:30,091 --> 00:04:32,740 ‫to substitute values within strings, 111 00:04:32,740 --> 00:04:36,590 ‫and so you can use it with references or pseudo variables, 112 00:04:36,590 --> 00:04:39,275 ‫and the string must contain this dollar sign, 113 00:04:39,275 --> 00:04:43,280 ‫and open with the VariableName to do a substitution. 114 00:04:43,280 --> 00:04:44,816 ‫So this is a bit obscure, 115 00:04:44,816 --> 00:04:47,158 ‫but just remember Sub the substitution, 116 00:04:47,158 --> 00:04:49,679 ‫and it will totally make sense when you see it, 117 00:04:49,679 --> 00:04:51,284 ‫if you see it in the exam, okay? 118 00:04:51,284 --> 00:04:53,518 ‫Sub is to substitute values. 119 00:04:53,518 --> 00:04:56,750 ‫Finally, Conditions. Conditions is when we define, 120 00:04:56,750 --> 00:05:00,104 ‫for example, a condition to only create the ProdResources, 121 00:05:00,104 --> 00:05:03,130 ‫and we can use a bunch of functions in there. 122 00:05:03,130 --> 00:05:05,184 ‫And so the intrinsic function we can use is 123 00:05:05,184 --> 00:05:08,943 ‫And, Equals, If, Not, and Or and maybe others 124 00:05:08,943 --> 00:05:11,899 ‫that will get to added to CloudFormation over time. 125 00:05:11,899 --> 00:05:15,020 ‫But that's all for the intrinsic functions you should use. 126 00:05:15,020 --> 00:05:16,593 ‫You recognize a function is called Intrinsic 127 00:05:16,593 --> 00:05:19,625 ‫when there is this FN colon colon, 128 00:05:19,625 --> 00:05:22,434 ‫or when you have that little exclamation point 129 00:05:22,434 --> 00:05:24,908 ‫before a name that represents a function. 130 00:05:24,908 --> 00:05:27,409 ‫This is all you need to know for CloudFormation functions. 131 00:05:27,409 --> 00:05:28,525 ‫I hope that was helpful, 132 00:05:28,525 --> 00:05:30,585 ‫and I will see you in the next lecture.