1
00:00:02,010 --> 00:00:08,000
In the last lecture, I gave you a hint that there is this language, this templating language we can use

2
00:00:08,000 --> 00:00:14,720
here to extract data from the request we have and define which data we want to forward.

3
00:00:14,810 --> 00:00:21,500
Now actually, you can learn more about this language if you Google for AWS API Gateway body mapping

4
00:00:21,500 --> 00:00:22,770
templates.

5
00:00:22,790 --> 00:00:28,590
The first article you find here below the ads gives you an overview over this language,

6
00:00:28,720 --> 00:00:35,120
the special variables you can use in this body mapping template text box there and how you can retrieve

7
00:00:35,120 --> 00:00:38,470
data. This is a good place to dive deeper

8
00:00:38,480 --> 00:00:41,950
but you'll also see quite some examples throughout this course.

9
00:00:41,960 --> 00:00:47,220
A quick example can be found if you go to the drop-down and choose method request pass through.

10
00:00:47,240 --> 00:00:52,640
What this does is it gives you a quite elaborate template, you might not understand all of that I can

11
00:00:52,640 --> 00:00:58,910
tell you it uses Apache's Velocity language and it basically extracts a lot of data from the request,

12
00:00:59,660 --> 00:01:01,630
data from the request body

13
00:01:01,670 --> 00:01:03,790
but also a lot of metadata.

14
00:01:04,220 --> 00:01:13,250
If we save this and I will come back to explaining this later and we go back to testing this, you will

15
00:01:13,250 --> 00:01:19,500
still see null because our lambda code still tries to access an age property which doesn't exist on event

16
00:01:19,940 --> 00:01:28,540
but if we go to our cloud watch logs here and we wait for the latest log to arrive, you will see that

17
00:01:28,550 --> 00:01:34,890
now we log a big object which has a body JSON property which holds our actual request body,

18
00:01:34,910 --> 00:01:38,930
now not as a JSON string but already as a Javascript object,

19
00:01:38,990 --> 00:01:47,060
all of this is a Javascript object and a lot of other information about this request. So kind of similar

20
00:01:47,240 --> 00:01:53,510
to the time we use this checkbox, use this proxy integration and forward everything

21
00:01:53,540 --> 00:02:03,110
but now not forwarding the request but forwarding a mapped template or a mapped event data object with

22
00:02:03,110 --> 00:02:08,780
data from that request which is also the reason why we wouldn't have to parse JSON data here because

23
00:02:08,780 --> 00:02:11,950
it already is a mapped Javascript object instead

24
00:02:12,140 --> 00:02:13,440
and that's the power.

25
00:02:13,760 --> 00:02:17,990
Also, this doesn't override our integration response,

26
00:02:17,990 --> 00:02:23,600
we're still in the world of API Gateway doing the request and response handling,

27
00:02:23,720 --> 00:02:29,200
we just happen to extract a lot of data from the request and pass it to the action

28
00:02:29,390 --> 00:02:31,390
but we can narrow this down.

29
00:02:31,460 --> 00:02:36,540
We can go to our template and get rid of all the stuff at the bottom here,

30
00:02:36,860 --> 00:02:45,200
a lot of information we don't need about authorization and so on, we'll need this later though and only extract

31
00:02:45,200 --> 00:02:48,250
data from the request body

32
00:02:48,440 --> 00:02:54,090
and this is done with this special command, input JSON and then dollar sign.

33
00:02:54,110 --> 00:03:00,650
This is dollar sign, a special variable which refers to your request body and JSON simply parses

34
00:03:00,680 --> 00:03:10,070
it and with that, you can also of course rename this to age and not parse your full request body but there,

35
00:03:10,300 --> 00:03:17,750
person data, you know that is a property on the request body you're parsing and then age. And now if

36
00:03:17,750 --> 00:03:21,510
we remove this comma, important that you don't have a syntax error,

37
00:03:21,530 --> 00:03:31,070
now if we save this and go back to testing this, if we hit test here, you'll see 56 again

38
00:03:31,070 --> 00:03:38,510
and important too if you check your cloud watch logs, wait for the latest one to arrive

39
00:03:38,510 --> 00:03:44,460
again, you'll see that we only received this object.

40
00:03:44,530 --> 00:03:46,560
So all the other data was dropped,

41
00:03:46,560 --> 00:03:53,300
we have no other metadata about the requests because in our mapping template under integration request

42
00:03:53,300 --> 00:03:55,840
here, we only extract that

43
00:03:55,960 --> 00:04:01,730
and the difficult part here to grasp probably is the language we use with this $input.json('$')

44
00:04:01,750 --> 00:04:03,700
thing.

45
00:04:03,880 --> 00:04:06,450
So let's dive deeper into this in the next lecture.
