1
00:00:00,570 --> 00:00:03,000
So let's talk about Lambda@Edge which is another

2
00:00:03,000 --> 00:00:05,530
type of synchronous invocation of Lambda.

3
00:00:05,530 --> 00:00:08,100
So say you have deployed a CDN using CloudFront.

4
00:00:08,100 --> 00:00:10,440
What if you wanted to run a global Lambda function,

5
00:00:10,440 --> 00:00:12,440
alongside each edge locations,

6
00:00:12,440 --> 00:00:14,410
or how would you implement request filtering

7
00:00:14,410 --> 00:00:16,620
before reaching your application.

8
00:00:16,620 --> 00:00:18,743
Well for this, you can use Lambda@Edge,

9
00:00:18,743 --> 00:00:21,900
and Lambda@Edge is that you deploy Lambda functions,

10
00:00:21,900 --> 00:00:23,865
not in a specific region, but alongside

11
00:00:23,865 --> 00:00:25,880
each region around the world

12
00:00:25,880 --> 00:00:27,266
with your CloudFront CDN.

13
00:00:27,266 --> 00:00:29,100
So, why would you do this?

14
00:00:29,100 --> 00:00:30,604
Well to build more responsive applications,

15
00:00:30,604 --> 00:00:32,220
you don't manage servers so

16
00:00:32,220 --> 00:00:33,610
Lambda will be deployed globally.

17
00:00:33,610 --> 00:00:35,140
You can customize whatever it goes through

18
00:00:35,140 --> 00:00:37,230
your CDN, and you're only going to pay for

19
00:00:37,230 --> 00:00:38,063
what you use.

20
00:00:38,063 --> 00:00:39,889
So that's the whole premise of Lambda@Edge.

21
00:00:39,889 --> 00:00:42,750
So you can use Lambda to do what?

22
00:00:42,750 --> 00:00:44,920
To change CloudFront request and response

23
00:00:44,920 --> 00:00:46,590
and there's four types of Lambda functions

24
00:00:46,590 --> 00:00:47,560
at the edge.

25
00:00:47,560 --> 00:00:50,077
So if we look at our integration we have our user,

26
00:00:50,077 --> 00:00:52,209
talking to your CloudFront edge locations

27
00:00:52,209 --> 00:00:55,290
that are going to be talking to your origin.

28
00:00:55,290 --> 00:00:56,670
So the first thing we can change

29
00:00:56,670 --> 00:00:57,850
within that bench is called

30
00:00:57,850 --> 00:00:59,240
the viewer requests

31
00:00:59,240 --> 00:01:01,690
So the viewer request is when CloudFront

32
00:01:01,690 --> 00:01:03,790
receives a request from a viewer, so from a user,

33
00:01:03,790 --> 00:01:05,890
we can modify that request.

34
00:01:05,890 --> 00:01:07,628
The second type of request we can modify

35
00:01:07,628 --> 00:01:09,900
is called the origin request,

36
00:01:09,900 --> 00:01:13,115
and this request is before CloudFront forwards the request

37
00:01:13,115 --> 00:01:14,366
to the origin.

38
00:01:14,366 --> 00:01:16,940
Then we can modify the third request,

39
00:01:16,940 --> 00:01:18,093
which is the origin response,

40
00:01:18,093 --> 00:01:20,740
which is done when CloudFront received the

41
00:01:20,740 --> 00:01:22,830
response from the origin, we can modify that.

42
00:01:22,830 --> 00:01:25,592
And then finally, we can modify the viewer response,

43
00:01:25,592 --> 00:01:27,610
which is before CloudFront forwards

44
00:01:27,610 --> 00:01:29,064
the response to the viewer.

45
00:01:29,064 --> 00:01:31,740
So what that means is that we can also generate

46
00:01:31,740 --> 00:01:32,800
responses to viewers,

47
00:01:32,800 --> 00:01:35,157
without ever sending any request to the origin,

48
00:01:35,157 --> 00:01:37,217
by just using the viewer request,

49
00:01:37,217 --> 00:01:39,207
and the viewer response Lambda functions.

50
00:01:39,207 --> 00:01:41,584
So, Lambda@Edge does allow you to change

51
00:01:41,584 --> 00:01:42,968
these four types of requests.

52
00:01:42,968 --> 00:01:44,320
So why would you do this?

53
00:01:44,320 --> 00:01:46,210
Well we can create a global application,

54
00:01:46,210 --> 00:01:47,043
for as an example.

55
00:01:47,043 --> 00:01:50,762
So, our website will be statically hosted onto Amazon S3

56
00:01:50,762 --> 00:01:52,553
in the HTML form,

57
00:01:52,553 --> 00:01:55,130
then the user will visit it and will be asked,

58
00:01:55,130 --> 00:01:57,530
with some client side JavaScript to do

59
00:01:57,530 --> 00:01:59,267
some API requests to CloudFront and

60
00:01:59,267 --> 00:02:02,750
CloudFront will be triggering our Lambda@Edge function

61
00:02:02,750 --> 00:02:05,340
which is globally and running globally alongside

62
00:02:05,340 --> 00:02:06,400
your edge locations,

63
00:02:06,400 --> 00:02:08,600
and then your Lambda function may be querying

64
00:02:08,600 --> 00:02:10,850
data in Amazon, DynamoDB,

65
00:02:10,850 --> 00:02:13,210
and we'll see what DynamoDB is very soon

66
00:02:13,210 --> 00:02:15,149
but it is a global database

67
00:02:15,149 --> 00:02:18,090
for your serverless applications.

68
00:02:18,090 --> 00:02:20,404
So, why would we use Lambda@Edge?

69
00:02:20,404 --> 00:02:22,200
What are the use cases?

70
00:02:22,200 --> 00:02:23,696
Where website security and privacy.

71
00:02:23,696 --> 00:02:25,674
Dynamic web application at the edge.

72
00:02:25,674 --> 00:02:28,600
Search Engine Optimization so SEO.

73
00:02:28,600 --> 00:02:30,530
You can intelligently route across origins

74
00:02:30,530 --> 00:02:31,450
and data centers.

75
00:02:31,450 --> 00:02:33,090
You can mitigate bots at the edge.

76
00:02:33,090 --> 00:02:35,580
You can do real time image transformation.

77
00:02:35,580 --> 00:02:37,750
AB testing, user authentication

78
00:02:37,750 --> 00:02:40,075
and authorization prior to reaching your origin.

79
00:02:40,075 --> 00:02:41,601
User pressurization

80
00:02:41,601 --> 00:02:44,400
and user tracking and analytics,

81
00:02:44,400 --> 00:02:46,470
so then Lambda@Edge is just something you should know,

82
00:02:46,470 --> 00:02:47,910
at a high level, going to the exam.

83
00:02:47,910 --> 00:02:50,090
Okay, so it is whenever you need to integrate

84
00:02:50,090 --> 00:02:52,259
a Lambda function with your CloudFront

85
00:02:52,259 --> 00:02:55,490
distribution to modify these four kinds

86
00:02:55,490 --> 00:02:56,470
of requests we've seen.

87
00:02:56,470 --> 00:02:58,530
And so that's why I will just not include

88
00:02:58,530 --> 00:02:59,660
a hands on for this.

89
00:02:59,660 --> 00:03:00,640
Just a high level overview.

90
00:03:00,640 --> 00:03:01,730
So that's it.

91
00:03:01,730 --> 00:03:03,480
I will see you in the next lecture.

