-: So outputs, let's talk about outputs.
And that's actually a very popular exam question,
so pay attention.
The outputs section is optional
but we can declare optional outputs
and if we export these outputs,
we will be able to import their values into other stacks
and by stack I mean, CloudFormation templates.
So you can start linking your CloudFormation templates.
We can also view the outputs in the AWS Console
or using the AWS CLI so it allows us
to quickly retrieve the value of an outputs,
straight from using the UI.
In terms of example, for example
you can have a network CloudFormation template
and then you would export outputs
that would be for example, the VPC ID and the Subnet IDs.
And you would reuse those in to
other CloudFormation templates.
So it enables to do a cross stack collaboration
where you let the experts handle
their own parts of the VPC and the Subnet
and you as a app developer,
you just reference these values out of the box.
Something you should know though,
is that if you start using the CloudFormation outputs
and they start being referenced
from another CloudFormation stack,
you cannot delete a stack
that still has outputs being referenced somewhere else.
So that's just something to know.
Now if we look at an example of the outputs.
In this one we are creating a SSH Security Group
as part of the template.
And so we export that value as an output
and basically other templates will be able
to get the value of that Security Group ID.
So the syntax is pretty easy,
we have the outputs section right here,
and we have the name of the Security Group
and we have the description,
so the SSH Security Group for our Company.
Here's the value,
so we provide a reference of the Security Group
where that was created within the resources.
And then we have to specify this Export block right here,
this is an optional block, if you don't specify it,
then the value does not get exported
and it will not be able to be imported.
So when we specify the Export value,
we can say okay, this value, this SSH Security Group ID,
is going to be exported as the name SSH Security Group.
So now how do we import the value?
Well using a cross stack reference.
And so we'll create a second template
that leverages that security group.
And for this we'll use the Fn Import Value function,
interesting function.
And we can't delete again,
the previous stack until all this stack will be deleted.
So if we look at this little snippet of code right here,
we can see that for the security groups at the very bottom,
there's a short hand syntax for import value
and then we reference the exact same name as before,
called SSH Security Group.
So, just a reminder,
before, we exported the value as SSH Security Group
and here we import the value SSH Security Group.
So, you know, outputs and exports are
a very, very popular question at the exam.
Especially, if they start asking you,
how do you link CloudFormation templates?
Or retrieve the value from one to another?
So you should know about it.
You should know about the syntax,
and you should know about the import value function.
So I hope that was helpful
and I will see you in the next lecture.