1
00:00:00,178 --> 00:00:01,901
<v ->So outputs, let's talk about outputs.</v>

2
00:00:01,901 --> 00:00:04,341
And that's actually a very popular exam question,

3
00:00:04,341 --> 00:00:05,493
so pay attention.

4
00:00:05,493 --> 00:00:07,481
The outputs section is optional

5
00:00:07,481 --> 00:00:09,700
but we can declare optional outputs

6
00:00:09,700 --> 00:00:11,693
and if we export these outputs,

7
00:00:11,693 --> 00:00:15,438
we will be able to import their values into other stacks

8
00:00:15,438 --> 00:00:17,415
and by stack I mean, CloudFormation templates.

9
00:00:17,415 --> 00:00:20,533
So you can start linking your CloudFormation templates.

10
00:00:20,533 --> 00:00:23,123
We can also view the outputs in the AWS Console

11
00:00:23,123 --> 00:00:25,110
or using the AWS CLI so it allows us

12
00:00:25,110 --> 00:00:28,685
to quickly retrieve the value of an outputs,

13
00:00:28,685 --> 00:00:31,041
straight from using the UI.

14
00:00:31,041 --> 00:00:33,706
In terms of example, for example

15
00:00:33,706 --> 00:00:36,484
you can have a network CloudFormation template

16
00:00:36,484 --> 00:00:39,070
and then you would export outputs

17
00:00:39,070 --> 00:00:42,818
that would be for example, the VPC ID and the Subnet IDs.

18
00:00:42,818 --> 00:00:44,511
And you would reuse those in to

19
00:00:44,511 --> 00:00:47,036
other CloudFormation templates.

20
00:00:47,036 --> 00:00:50,534
So it enables to do a cross stack collaboration

21
00:00:50,534 --> 00:00:52,349
where you let the experts handle

22
00:00:52,349 --> 00:00:54,789
their own parts of the VPC and the Subnet

23
00:00:54,789 --> 00:00:56,290
and you as a app developer,

24
00:00:56,290 --> 00:01:00,173
you just reference these values out of the box.

25
00:01:00,173 --> 00:01:01,133
Something you should know though,

26
00:01:01,133 --> 00:01:04,374
is that if you start using the CloudFormation outputs

27
00:01:04,374 --> 00:01:05,711
and they start being referenced

28
00:01:05,711 --> 00:01:07,985
from another CloudFormation stack,

29
00:01:07,985 --> 00:01:09,266
you cannot delete a stack

30
00:01:09,266 --> 00:01:12,012
that still has outputs being referenced somewhere else.

31
00:01:12,012 --> 00:01:13,904
So that's just something to know.

32
00:01:13,904 --> 00:01:16,306
Now if we look at an example of the outputs.

33
00:01:16,306 --> 00:01:19,408
In this one we are creating a SSH Security Group

34
00:01:19,408 --> 00:01:20,644
as part of the template.

35
00:01:20,644 --> 00:01:23,977
And so we export that value as an output

36
00:01:25,096 --> 00:01:28,196
and basically other templates will be able

37
00:01:28,196 --> 00:01:31,727
to get the value of that Security Group ID.

38
00:01:31,727 --> 00:01:33,339
So the syntax is pretty easy,

39
00:01:33,339 --> 00:01:35,400
we have the outputs section right here,

40
00:01:35,400 --> 00:01:38,147
and we have the name of the Security Group

41
00:01:38,147 --> 00:01:39,148
and we have the description,

42
00:01:39,148 --> 00:01:41,743
so the SSH Security Group for our Company.

43
00:01:41,743 --> 00:01:42,662
Here's the value,

44
00:01:42,662 --> 00:01:44,643
so we provide a reference of the Security Group

45
00:01:44,643 --> 00:01:47,672
where that was created within the resources.

46
00:01:47,672 --> 00:01:51,375
And then we have to specify this Export block right here,

47
00:01:51,375 --> 00:01:53,839
this is an optional block, if you don't specify it,

48
00:01:53,839 --> 00:01:55,480
then the value does not get exported

49
00:01:55,480 --> 00:01:57,375
and it will not be able to be imported.

50
00:01:57,375 --> 00:01:59,516
So when we specify the Export value,

51
00:01:59,516 --> 00:02:03,617
we can say okay, this value, this SSH Security Group ID,

52
00:02:03,617 --> 00:02:08,022
is going to be exported as the name SSH Security Group.

53
00:02:08,022 --> 00:02:09,731
So now how do we import the value?

54
00:02:09,731 --> 00:02:11,637
Well using a cross stack reference.

55
00:02:11,637 --> 00:02:12,980
And so we'll create a second template

56
00:02:12,980 --> 00:02:14,554
that leverages that security group.

57
00:02:14,554 --> 00:02:18,187
And for this we'll use the Fn Import Value function,

58
00:02:18,187 --> 00:02:19,401
interesting function.

59
00:02:19,401 --> 00:02:20,772
And we can't delete again,

60
00:02:20,772 --> 00:02:24,572
the previous stack until all this stack will be deleted.

61
00:02:24,572 --> 00:02:27,667
So if we look at this little snippet of code right here,

62
00:02:27,667 --> 00:02:30,492
we can see that for the security groups at the very bottom,

63
00:02:30,492 --> 00:02:33,705
there's a short hand syntax for import value

64
00:02:33,705 --> 00:02:36,928
and then we reference the exact same name as before,

65
00:02:36,928 --> 00:02:39,850
called SSH Security Group.

66
00:02:39,850 --> 00:02:41,440
So, just a reminder,

67
00:02:41,440 --> 00:02:45,219
before, we exported the value as SSH Security Group

68
00:02:45,219 --> 00:02:50,007
and here we import the value SSH Security Group.

69
00:02:50,007 --> 00:02:52,699
So, you know, outputs and exports are

70
00:02:52,699 --> 00:02:55,369
a very, very popular question at the exam.

71
00:02:55,369 --> 00:02:56,814
Especially, if they start asking you,

72
00:02:56,814 --> 00:02:58,319
how do you link CloudFormation templates?

73
00:02:58,319 --> 00:03:00,341
Or retrieve the value from one to another?

74
00:03:00,341 --> 00:03:01,504
So you should know about it.

75
00:03:01,504 --> 00:03:02,587
You should know about the syntax,

76
00:03:02,587 --> 00:03:05,002
and you should know about the import value function.

77
00:03:05,002 --> 00:03:06,153
So I hope that was helpful

78
00:03:06,153 --> 00:03:08,249
and I will see you in the next lecture.

