1
00:00:02,200 --> 00:00:03,300
Now let's talk

2
00:00:03,300 --> 00:00:06,610
about a problem we might be facing here.

3
00:00:06,610 --> 00:00:10,030
This public IP address changes every time

4
00:00:10,030 --> 00:00:13,090
we deploy an updated container.

5
00:00:13,090 --> 00:00:16,830
And that's, of course, not really ideal.

6
00:00:16,830 --> 00:00:19,900
Now, that's why I did create that load balancer.

7
00:00:19,900 --> 00:00:22,080
If you go to Services and you search

8
00:00:22,080 --> 00:00:24,913
for application load here,

9
00:00:26,000 --> 00:00:28,600
you should find EC2 as a suggestion

10
00:00:28,600 --> 00:00:32,350
because that's where load balancers are managed.

11
00:00:32,350 --> 00:00:34,730
We don't use EC2 instances here

12
00:00:34,730 --> 00:00:37,590
but the load balancer feature belongs to that

13
00:00:37,590 --> 00:00:40,350
and Fargate also utilizes it.

14
00:00:40,350 --> 00:00:42,330
So here under Load Balancers,

15
00:00:42,330 --> 00:00:45,394
you should find the load balancer we created.

16
00:00:45,394 --> 00:00:48,510
And here, we find the DNS name,

17
00:00:48,510 --> 00:00:51,010
which looks very much like a domain.

18
00:00:51,010 --> 00:00:52,530
We can copy that,

19
00:00:52,530 --> 00:00:53,970
enter it in the browser

20
00:00:53,970 --> 00:00:57,210
and send a request to /goals.

21
00:00:57,210 --> 00:01:00,770
However, you will notice that this won't work here

22
00:01:00,770 --> 00:01:03,160
for a couple of reasons.

23
00:01:03,160 --> 00:01:05,190
For one, I made a tiny mistake

24
00:01:05,190 --> 00:01:08,680
in the target groups of that load balancer.

25
00:01:08,680 --> 00:01:10,580
If we go back to ECS,

26
00:01:10,580 --> 00:01:13,970
you will notice that on your services,

27
00:01:13,970 --> 00:01:17,010
the tasks connected to the service

28
00:01:17,010 --> 00:01:20,880
are stopped and restarted all the time.

29
00:01:20,880 --> 00:01:22,906
And that stopping and restarting

30
00:01:22,906 --> 00:01:26,010
is done by our load balancer

31
00:01:26,010 --> 00:01:28,880
because that load balancer is checking the health

32
00:01:28,880 --> 00:01:32,800
of the services it's redirecting requests to

33
00:01:32,800 --> 00:01:34,470
and it shuts down a service

34
00:01:34,470 --> 00:01:39,020
and restarts it if finds that this service is unhealthy.

35
00:01:39,020 --> 00:01:41,840
For example, if it's not responding anymore.

36
00:01:41,840 --> 00:01:44,410
That generally is a good behavior

37
00:01:44,410 --> 00:01:48,100
because it ensures that if our application should crash

38
00:01:48,100 --> 00:01:50,980
for whatever reason, it's restarted.

39
00:01:50,980 --> 00:01:53,720
However, unfortunately, I made a tiny mistake

40
00:01:53,720 --> 00:01:56,580
when we set up this load balancer.

41
00:01:56,580 --> 00:02:01,080
On the target groups area of that EC2 service page,

42
00:02:01,080 --> 00:02:04,830
you should find the target group we created earlier.

43
00:02:04,830 --> 00:02:07,890
There under Health check settings, click on Edit.

44
00:02:07,890 --> 00:02:10,729
And here, by default, the load balancer

45
00:02:10,729 --> 00:02:15,730
is sending a request to our deployed service slash nothing.

46
00:02:17,590 --> 00:02:22,590
Now, in our case, we are handling requests to /goals

47
00:02:22,610 --> 00:02:25,320
but not to slash nothing.

48
00:02:25,320 --> 00:02:29,010
Therefore, requests sent to slash nothing

49
00:02:29,010 --> 00:02:32,430
will respond with a 404 error,

50
00:02:32,430 --> 00:02:34,573
which is treated as unhealthy.

51
00:02:35,610 --> 00:02:40,000
Therefore, we should change this health check path to /goals

52
00:02:40,000 --> 00:02:43,220
so that the request is sent to an endpoint

53
00:02:43,220 --> 00:02:45,740
of our service, which will respond

54
00:02:45,740 --> 00:02:47,560
with a success code.

55
00:02:47,560 --> 00:02:49,530
Now, that's one thing we've gotta change

56
00:02:49,530 --> 00:02:52,653
to ensure that our load balancer will work correctly.

57
00:02:53,510 --> 00:02:57,030
Another thing which I accidentally messed up a bit

58
00:02:57,030 --> 00:02:59,400
is on the load balancer itself

59
00:02:59,400 --> 00:03:02,430
in the basic configuration here,

60
00:03:02,430 --> 00:03:04,530
the security groups I added,

61
00:03:04,530 --> 00:03:07,490
I added this default security group.

62
00:03:07,490 --> 00:03:11,990
Now, actually I wanna add this goals security groups here,

63
00:03:11,990 --> 00:03:13,690
not the default one.

64
00:03:13,690 --> 00:03:16,710
So here, make sure you add your security group

65
00:03:16,710 --> 00:03:19,290
besides that default security group

66
00:03:19,290 --> 00:03:21,660
so that the security group we're also using

67
00:03:21,660 --> 00:03:25,000
for our ECS services is also attached here

68
00:03:25,000 --> 00:03:26,383
and then click Save.

69
00:03:27,960 --> 00:03:30,510
Now, all these changes will take a couple of seconds

70
00:03:30,510 --> 00:03:32,480
or minutes to have an effect

71
00:03:32,480 --> 00:03:36,300
but thereafter, our services should not be stopped

72
00:03:36,300 --> 00:03:38,300
and restarted all the time anymore

73
00:03:38,300 --> 00:03:40,750
or our tasks here, I should say.

74
00:03:40,750 --> 00:03:42,230
And we should be able

75
00:03:42,230 --> 00:03:45,340
to also use this URL here,

76
00:03:45,340 --> 00:03:47,960
which we find on the load balancer page

77
00:03:47,960 --> 00:03:50,920
to send a request to our deployed services

78
00:03:50,920 --> 00:03:52,850
and to our running tasks.

79
00:03:52,850 --> 00:03:56,070
And that means that we now can send a request

80
00:03:56,070 --> 00:03:59,460
to the same URL, to the same domain

81
00:03:59,460 --> 00:04:03,320
without caring about changing IP addresses.

82
00:04:03,320 --> 00:04:06,380
Of course, you can also map your own custom domain

83
00:04:06,380 --> 00:04:08,100
to this one if you want to

84
00:04:08,100 --> 00:04:11,510
and the AWS documentation is the place to go

85
00:04:11,510 --> 00:04:13,990
if you wanna learn more about that.

86
00:04:13,990 --> 00:04:16,459
So if we now wait for all this deployment

87
00:04:16,459 --> 00:04:17,866
to finish up here,

88
00:04:17,866 --> 00:04:22,866
and we wait for this service to be restarted one more time,

89
00:04:23,247 --> 00:04:25,990
and therefore, after a couple of minutes,

90
00:04:25,990 --> 00:04:27,920
we will be able to send the request

91
00:04:27,920 --> 00:04:30,063
to this domain /goals.

92
00:04:31,042 --> 00:04:34,220
And of course, we can also use this in Postman now

93
00:04:34,220 --> 00:04:36,040
instead of the IP address

94
00:04:36,040 --> 00:04:37,699
and we can add a new goal.

95
00:04:37,699 --> 00:04:41,136
We can, of course, then also get our goals.

96
00:04:41,136 --> 00:04:43,530
Oops, I had a typo there.

97
00:04:43,530 --> 00:04:45,170
We can get our goals

98
00:04:45,170 --> 00:04:47,210
and of course, if we want to,

99
00:04:47,210 --> 00:04:50,010
we can also delete a goal there.

100
00:04:50,010 --> 00:04:53,050
Just make sure you grab the correct goal ID,

101
00:04:53,050 --> 00:04:54,370
plug it into the URL

102
00:04:55,360 --> 00:04:57,490
and here we go.

103
00:04:57,490 --> 00:04:59,460
So this is now all working

104
00:04:59,460 --> 00:05:02,800
and that's how we could deploy multiple containers

105
00:05:02,800 --> 00:05:04,630
with AWS ECS

106
00:05:04,630 --> 00:05:07,740
and how we can also use such a load balancer

107
00:05:07,740 --> 00:05:11,060
to then ensure that we have a unchanging domain,

108
00:05:11,060 --> 00:05:13,793
which points at these deployed containers.

