1
00:00:02,220 --> 00:00:04,000
So to add MongoDB,

2
00:00:04,000 --> 00:00:06,260
we simply add another container

3
00:00:06,260 --> 00:00:09,330
to this task definition on which we are working here

4
00:00:09,330 --> 00:00:12,633
and give this a name of our choice, for example, MongoDB.

5
00:00:13,890 --> 00:00:16,440
The image name is just Mongo here

6
00:00:16,440 --> 00:00:19,560
because that is an official image on Docker Hub.

7
00:00:19,560 --> 00:00:21,230
And as I explained before,

8
00:00:21,230 --> 00:00:24,250
AWS ECS will automatically look

9
00:00:24,250 --> 00:00:28,050
for image names you specify here on Docker Hub.

10
00:00:28,050 --> 00:00:29,703
So we just use it like this.

11
00:00:30,760 --> 00:00:32,229
Now, if we're to port mappings,

12
00:00:32,229 --> 00:00:37,230
we wanna map port 27017 which is the default port

13
00:00:38,193 --> 00:00:40,210
the MongoDB image exposes.

14
00:00:40,210 --> 00:00:43,580
It is the port on which we also connect here

15
00:00:43,580 --> 00:00:45,200
in our connection string.

16
00:00:45,200 --> 00:00:47,513
So that's the port we wanna map here.

17
00:00:49,000 --> 00:00:50,360
And then if we scroll down,

18
00:00:50,360 --> 00:00:52,830
we can leave everything the way it is.

19
00:00:52,830 --> 00:00:55,200
But under environment variables,

20
00:00:55,200 --> 00:00:58,540
I of course wanna pass in the environment variables

21
00:00:58,540 --> 00:01:01,043
which are defined in mongo.env.

22
00:01:02,110 --> 00:01:05,390
So here I will grab the first environment variable

23
00:01:05,390 --> 00:01:10,030
for the default username and set this to max,

24
00:01:10,030 --> 00:01:12,790
and grab the password environment variable

25
00:01:12,790 --> 00:01:17,000
and set that to secret here to ensure that we set

26
00:01:17,000 --> 00:01:21,423
these two environment variables inside of our container.

27
00:01:23,490 --> 00:01:25,180
Now, if we scroll down further,

28
00:01:25,180 --> 00:01:27,260
we can ignore the network settings,

29
00:01:27,260 --> 00:01:29,320
but for storage and logging,

30
00:01:29,320 --> 00:01:31,890
we of course, do we have a volume here

31
00:01:31,890 --> 00:01:34,270
in our docker-compose-yami file

32
00:01:34,270 --> 00:01:37,573
which ensures that data persists.

33
00:01:38,610 --> 00:01:41,890
Now at the moment, I will leave it like that.

34
00:01:41,890 --> 00:01:46,180
I will not add anything here in this setup,

35
00:01:46,180 --> 00:01:49,170
but it will come back to this later.

36
00:01:49,170 --> 00:01:50,980
For the moment, let's keep that storage

37
00:01:50,980 --> 00:01:54,863
and logging part empty and add to this container like this.

38
00:01:56,300 --> 00:01:57,550
Now with that, we can leave

39
00:01:57,550 --> 00:02:02,080
all the other settings the way they are and click create.

40
00:02:02,080 --> 00:02:05,400
And now this creates this new task definition

41
00:02:05,400 --> 00:02:07,833
with our two containers inside of them.

42
00:02:09,340 --> 00:02:10,740
With that created,

43
00:02:10,740 --> 00:02:13,860
we can now launch a service based on this task,

44
00:02:13,860 --> 00:02:16,280
which then actually launches these containers

45
00:02:16,280 --> 00:02:18,513
with the defined configuration.

46
00:02:19,560 --> 00:02:21,880
So for that, we go back to clusters,

47
00:02:21,880 --> 00:02:25,410
our goals-app cluster and under services,

48
00:02:25,410 --> 00:02:27,340
we click create.

49
00:02:27,340 --> 00:02:30,340
Here, choose Fargate as a launch type

50
00:02:30,340 --> 00:02:32,270
and under task definition,

51
00:02:32,270 --> 00:02:35,883
choose that goals task definition we just worked on.

52
00:02:36,830 --> 00:02:38,570
You can give this serve as a name,

53
00:02:38,570 --> 00:02:40,770
for example, goals_service,

54
00:02:42,840 --> 00:02:45,483
under a number of tasks we choose one here.

55
00:02:46,490 --> 00:02:51,490
We can keep the deployment type and then click next step.

56
00:02:52,200 --> 00:02:55,890
Now here on this page,

57
00:02:55,890 --> 00:02:59,440
at the top you should have a VPC which you can select.

58
00:02:59,440 --> 00:03:02,960
So select this VPC, and under subnets,

59
00:03:02,960 --> 00:03:04,880
simply add both subnets

60
00:03:04,880 --> 00:03:07,130
which you should be able to choose from here.

61
00:03:08,160 --> 00:03:11,010
Make sure auto-assign public IP is enabled

62
00:03:11,010 --> 00:03:13,660
so that we'll be able to reach this

63
00:03:13,660 --> 00:03:15,430
with help of a public ID.

64
00:03:15,430 --> 00:03:17,770
And now actually under load balancing,

65
00:03:17,770 --> 00:03:20,510
choose application load balancer.

66
00:03:20,510 --> 00:03:23,150
This will ensure that incoming traffic is handled

67
00:03:23,150 --> 00:03:26,250
in an efficient way, but it will also help us

68
00:03:26,250 --> 00:03:29,800
with assigning a custom domain later if we want to.

69
00:03:29,800 --> 00:03:33,660
Hence, I'll choose application load balancer here.

70
00:03:33,660 --> 00:03:37,150
Now it won't find a load balancer by default.

71
00:03:37,150 --> 00:03:41,120
So go to the EC2 Console as it prompts you here.

72
00:03:41,120 --> 00:03:44,500
As a side note, if you use the wizard, the first run wizard

73
00:03:44,500 --> 00:03:47,870
which you saw earlier, it would create one automatically,

74
00:03:47,870 --> 00:03:49,120
but here on this side,

75
00:03:49,120 --> 00:03:52,793
simply create an application load balancer,

76
00:03:54,060 --> 00:03:55,680
give it any name of your choice,

77
00:03:55,680 --> 00:04:00,210
I'll name it ecs-lb for load balancer.

78
00:04:00,210 --> 00:04:02,030
It should be a internet-facing one

79
00:04:02,030 --> 00:04:05,260
so that it can be reached from the internet.

80
00:04:05,260 --> 00:04:07,820
It should definitely expose port 80

81
00:04:07,820 --> 00:04:10,360
so make sure you have that listener here,

82
00:04:10,360 --> 00:04:13,300
and it should be connected to the same VPC

83
00:04:13,300 --> 00:04:17,740
you chose as a VPC here on your service.

84
00:04:17,740 --> 00:04:19,519
This ensures that the load balancer

85
00:04:19,519 --> 00:04:21,753
is working on the same network.

86
00:04:23,170 --> 00:04:25,630
We can also check these two boxes here

87
00:04:26,610 --> 00:04:30,090
and click next, configure security settings.

88
00:04:30,090 --> 00:04:32,160
Now for the moment, we can leave this empty.

89
00:04:32,160 --> 00:04:35,690
You could look into the docs you're pointed at here

90
00:04:35,690 --> 00:04:39,210
to ensure that you actually use HTTPS.

91
00:04:39,210 --> 00:04:42,230
But our Node application is not using HTTPS,

92
00:04:42,230 --> 00:04:44,350
so I will leave it the way it is here.

93
00:04:44,350 --> 00:04:46,480
Click on configure security groups

94
00:04:47,720 --> 00:04:50,260
and there, selected existing security group,

95
00:04:50,260 --> 00:04:53,690
and choose the security group which you should find here.

96
00:04:53,690 --> 00:04:58,170
Click on configure routing, and there under target group,

97
00:04:58,170 --> 00:05:00,460
give it any name of your choice

98
00:05:00,460 --> 00:05:03,400
and choose IP as a targets type.

99
00:05:03,400 --> 00:05:06,010
This is required since we're using Fargate

100
00:05:06,010 --> 00:05:10,233
for our container, for running our containers,

101
00:05:11,270 --> 00:05:13,170
and click register targets.

102
00:05:13,170 --> 00:05:14,990
Now here under registered targets,

103
00:05:14,990 --> 00:05:16,740
you don't need to do anything.

104
00:05:16,740 --> 00:05:20,580
AWS ECS will automatically register running containers

105
00:05:20,580 --> 00:05:23,930
as targets here, and therefore we click next review,

106
00:05:23,930 --> 00:05:26,650
and create this load balancer.

107
00:05:26,650 --> 00:05:28,490
Now, once this was created,

108
00:05:28,490 --> 00:05:30,490
and by the way, I will say that, of course,

109
00:05:30,490 --> 00:05:33,770
these are all features which might incur costs.

110
00:05:33,770 --> 00:05:36,810
So you might wanna check out the AWS pricing pages

111
00:05:36,810 --> 00:05:39,980
before you continue with all of that.

112
00:05:39,980 --> 00:05:44,813
Now with that created, we can go back to ECS,

113
00:05:44,813 --> 00:05:48,620
and then here, refresh the list of load balancers

114
00:05:50,490 --> 00:05:53,143
and choose the load balancer you just created.

115
00:05:54,060 --> 00:05:57,160
Choose that goals-backend 80:80 port mapping here

116
00:05:57,160 --> 00:05:59,373
which should be added to the load balancer,

117
00:06:01,543 --> 00:06:03,510
and add it to that target group

118
00:06:03,510 --> 00:06:05,553
we already created in advance.

119
00:06:06,550 --> 00:06:09,420
Alternatively, of course, you can create a new one.

120
00:06:09,420 --> 00:06:11,223
Choose any name of your choice then.

121
00:06:12,820 --> 00:06:17,020
And with all of that, we can click next step here,

122
00:06:17,020 --> 00:06:21,290
ignore auto scaling here and click next step.

123
00:06:21,290 --> 00:06:23,510
Auto scaling, just as a side note,

124
00:06:23,510 --> 00:06:25,430
could of course be configured to ensure

125
00:06:25,430 --> 00:06:27,440
that for incoming traffic spikes,

126
00:06:27,440 --> 00:06:31,680
more and more simultaneous instances off your container

127
00:06:31,680 --> 00:06:34,020
are being executed to be able to handle

128
00:06:34,020 --> 00:06:36,240
all these spikes without delay.

129
00:06:36,240 --> 00:06:38,120
It's an advanced feature and therefore,

130
00:06:38,120 --> 00:06:40,260
I'll not dive into it here.

131
00:06:40,260 --> 00:06:42,460
If you are planning to deploy bigger

132
00:06:42,460 --> 00:06:45,420
and realistic applications on AWS,

133
00:06:45,420 --> 00:06:47,260
you will need to dive deeply

134
00:06:47,260 --> 00:06:49,790
into their documentation anyways.

135
00:06:49,790 --> 00:06:52,520
So therefore, we got a basic setup here which we can use,

136
00:06:52,520 --> 00:06:54,910
and now we can click create service

137
00:06:54,910 --> 00:06:57,340
and this should now set up everything we need

138
00:06:57,340 --> 00:06:59,803
in order to be able to run these containers.

139
00:07:01,120 --> 00:07:06,120
So on our cluster here, the goals-app,

140
00:07:06,130 --> 00:07:08,220
we now have a service.

141
00:07:08,220 --> 00:07:12,540
We got tasks here, and if you click on this service,

142
00:07:12,540 --> 00:07:15,270
we see the tasks associated with that service.

143
00:07:15,270 --> 00:07:17,420
And if we click on that task,

144
00:07:17,420 --> 00:07:20,160
we of course see that public ID again.

145
00:07:20,160 --> 00:07:23,260
We also see the containers that belong to that task,

146
00:07:23,260 --> 00:07:24,900
and you see that at the moment,

147
00:07:24,900 --> 00:07:27,380
they're still starting up here.

148
00:07:27,380 --> 00:07:31,000
So let's wait for that to finish and let's ensure

149
00:07:31,000 --> 00:07:33,510
that both containers are up and running

150
00:07:33,510 --> 00:07:35,603
before we then try working with them.

151
00:07:36,540 --> 00:07:38,860
Now they are both up and running

152
00:07:38,860 --> 00:07:41,050
and now we can use the public IP address

153
00:07:41,050 --> 00:07:43,970
to visit this address slash goals,

154
00:07:43,970 --> 00:07:47,700
to fetch all the goals stored in our database.

155
00:07:47,700 --> 00:07:50,610
And we get back an empty goals array here initially,

156
00:07:50,610 --> 00:07:54,280
of course, but that proof standard works

157
00:07:54,280 --> 00:07:56,680
because otherwise, we would be getting an error.

158
00:07:57,640 --> 00:08:00,610
Now of course we can now use Postman,

159
00:08:00,610 --> 00:08:04,490
this tool which allowed us to send requests to APIs,

160
00:08:04,490 --> 00:08:07,860
to test the other API endpoints as well.

161
00:08:07,860 --> 00:08:12,610
And I wanna send a post request to my IP slash goals

162
00:08:12,610 --> 00:08:16,400
and add a body which should be in raw format

163
00:08:16,400 --> 00:08:19,940
and then JSON format, which has a text field

164
00:08:21,300 --> 00:08:25,590
where I add a first test as content.

165
00:08:25,590 --> 00:08:27,850
And if I click send, this is being sent

166
00:08:27,850 --> 00:08:29,830
and I get back my goal here.

167
00:08:29,830 --> 00:08:31,413
So that's looking very good.

168
00:08:32,250 --> 00:08:37,250
If I now send a Get request to my IP slash goals,

169
00:08:38,880 --> 00:08:40,573
I see that goal here.

170
00:08:42,073 --> 00:08:45,350
And if I try deleting it by sending a Delete request

171
00:08:45,350 --> 00:08:48,680
to slash goals slash the ID of that goal

172
00:08:48,680 --> 00:08:52,090
which we can find here in the response from before,

173
00:08:52,090 --> 00:08:55,130
I hopefully also can delete that goal.

174
00:08:55,130 --> 00:08:58,653
It says it did so, and indeed it's missing.

175
00:08:59,790 --> 00:09:02,710
So that now proves that all our containers

176
00:09:02,710 --> 00:09:06,730
were successfully deployed with AWS ECS,

177
00:09:06,730 --> 00:09:09,723
now working on a multi-container app.

