Narrator: So the exam may ask you
about Intrinsic Functions,
and we've seen them, but here is a list of
the ones you should absolutely know for the exam.
The Ref function, the GetAttributes
FindInMap, ImportValue, Join,
Sub, and the Condition Functions.
So, let's go ahead and have a quick
memory refresher on what they are.
The Ref function is to me the most important.
It used to be referencing parameters,
and in case you reference a parameter,
it will return the value of that parameter.
So, we've seen this in practice
when you had the security group description.
And Resources. So if you reference another resource
in your CloudFormation template,
it will return the physical ID
of the underlying resource.
So, for example, if we reference
a EC2 Instance, we will get the EC2 Instance ID.
Now the shorthand for this is going to be
!Ref, and this is what it looks like.
So here is a quick example, we create a Subnet
and for the Properties VpcId, we reference the VPC
that was created from before,
and so what we get out of it is the VpcId.
As I said, when you reference a resource,
it returns the physical ID.
So super important to know.
Now, how do we get other information out of resources?
Right? Because, if we only can get the ID information
out of the resources using a Ref,
then we're pretty much stuck for some things.
So, we can use GetAtt, and attributes can be attached
to any resources you create,
and so to basically get a list
of all the resources and all the attributes
that get exposed from these resources,
you will have to look in the documentation.
So let's do a quick look at it, just to get an idea.
So if we look at our EC2 Instance,
and we go to Return Values,
we can see that there's a Ref.
So the Ref will return the ID of that instance, okay,
and then using the GetAttributes function
we're able to get the AvailabilityZone
the DNS name, the private IP, and so on.
So all these things are exposed.
So to know what attributes are exposed in each resource,
you have to go to the resource,
and look at the documentation.
Now, for example if you want to get the AZ
of an EC2 machine, we saw we could do it.
Here is our resource blogs, so we have our EC2 Instance
with an ImageId, and an InstanceType
and we want to get the AZ out of it,
for example, when we create an EBS Volume.
For this we're going create a new volume under resources,
and we'll say the type is a EC2 volume.
Condition, if we had a condition from before,
but the important thing here and there
is that if you look at the properties,
the size is 100, and the AZ
is using the GetAttribute function,
EC2.AvailabilityZone,
so the EC2 Instance is coming straight out of this name
on the left hand side, and then the dot says,
it tells GetAttribute what we wanna get out of it,
so we wanna get the AvailbilityZone.
So this is quite a popular exam question as well,
you know, how do we get this attribute
of this resource, and the answer is use the GetAtt function.
You have FindInMap, and we've seen this before.
We use this FindInMap function,
and the shorthand syntax is this,
we have to specify the MapName,
the TopLevelKey, and the SecondLevelKey.
And so here is this quick summary.
In this example, we were using the FindInMap function
to find the Image ID,
based on the region we were in,
and the type of architecture, 32 or 64 bits.
ImportValue is to import values
that have been exported as outputs in other templates,
and for this we use the ImportValue function
so again remember, when we import a value,
we just give the ImportValue name
that was exported and it should work just easy.
Now for Join. Join we haven't seen it yet,
but we can join value with a delimiter,
so this is the shorthand syntax,
we define Join, we get the delimeter name
and then we provide a comma-delimited list of values.
To make it slightly more concrete,
to create the a:b:c string,
we can use the Join function with the colon,
and then we specify a, b, c on the right hand side.
So this is, if you do programming,
this is quite a common function in programming.
So, just know about it.
Sometimes, maybe you'll be asked,
hey, what is the output of this Intrinsic Function,
and if you use Join, well you know
that you have to just put the colons
in between the a and the b, and the b and the c.
Okay, finally we have the Sub function.
The sub function is a shorthand for substitutes.
It's super handy, it allows you
to substitute values within strings,
and so you can use it with references or pseudo variables,
and the string must contain this dollar sign,
and open with the VariableName to do a substitution.
So this is a bit obscure,
but just remember Sub the substitution,
and it will totally make sense when you see it,
if you see it in the exam, okay?
Sub is to substitute values.
Finally, Conditions. Conditions is when we define,
for example, a condition to only create the ProdResources,
and we can use a bunch of functions in there.
And so the intrinsic function we can use is
And, Equals, If, Not, and Or and maybe others
that will get to added to CloudFormation over time.
But that's all for the intrinsic functions you should use.
You recognize a function is called Intrinsic
when there is this FN colon colon,
or when you have that little exclamation point
before a name that represents a function.
This is all you need to know for CloudFormation functions.
I hope that was helpful,
and I will see you in the next lecture.