1
00:00:00,021 --> 00:00:02,040
<v Instructor>Okay, just a little bit of practice</v>

2
00:00:02,040 --> 00:00:03,840
with the DynamoDB CLI 'cause there is

3
00:00:03,840 --> 00:00:05,840
some good-to-know parameters that we can use,

4
00:00:05,840 --> 00:00:08,190
and that the exam may ask you questions about.

5
00:00:08,190 --> 00:00:10,830
The first one is a projection-expression,

6
00:00:10,830 --> 00:00:13,460
and this is to specify a list of attributes

7
00:00:13,460 --> 00:00:15,590
that you may want to retrieve from the table.

8
00:00:15,590 --> 00:00:17,690
Maybe you don't want all the attributes from the table.

9
00:00:17,690 --> 00:00:18,880
Maybe you just want a subset,

10
00:00:18,880 --> 00:00:21,720
and so projection-expression is the way to say that.

11
00:00:21,720 --> 00:00:23,600
Also if you want to filter the results,

12
00:00:23,600 --> 00:00:25,430
you can use a filter-expression,

13
00:00:25,430 --> 00:00:28,500
and we'll see how to do both these things into the hands-on.

14
00:00:28,500 --> 00:00:32,040
Now, there are some general CLI pagination option

15
00:00:32,040 --> 00:00:35,400
that includes the DynamoDB and the S3 CLI

16
00:00:35,400 --> 00:00:37,030
but could also include other CLI.

17
00:00:37,030 --> 00:00:40,810
And so, these commands are not just applied to

18
00:00:40,810 --> 00:00:43,160
these two services but to CLI overall

19
00:00:43,160 --> 00:00:44,460
when it returns results,

20
00:00:44,460 --> 00:00:45,890
and they're really good to know overall.

21
00:00:45,890 --> 00:00:50,030
The first one is an optimization which is page-size.

22
00:00:50,030 --> 00:00:52,900
This option is saying that you still wanna retrieve

23
00:00:52,900 --> 00:00:56,030
the full dataset, for example if you're doin' S3 ListBucket

24
00:00:56,030 --> 00:01:00,890
or DynamoDB Scan, but you want each API call made to AWS

25
00:01:00,890 --> 00:01:03,940
to request less data, and maybe a reason

26
00:01:03,940 --> 00:01:07,540
why you would want to do this is to help avoid timeouts.

27
00:01:07,540 --> 00:01:10,360
So by specifying a smaller page size, you will have

28
00:01:10,360 --> 00:01:13,360
more API calls being done, but each API call will return

29
00:01:13,360 --> 00:01:16,720
less data, so it probably will help you avoid timeouts.

30
00:01:16,720 --> 00:01:18,020
We'll see this in a second.

31
00:01:18,020 --> 00:01:19,808
There's also pagination.

32
00:01:19,808 --> 00:01:22,393
Pagination, as the name indicates, is to use pages.

33
00:01:23,272 --> 00:01:25,670
With this, you specify the max number of items

34
00:01:25,670 --> 00:01:28,240
you want to be returned by the CLI,

35
00:01:28,240 --> 00:01:31,330
and you will get a token at the end of this command

36
00:01:31,330 --> 00:01:34,530
called NextToken, and you would pass on that token

37
00:01:34,530 --> 00:01:35,840
to the starting token parameters

38
00:01:35,840 --> 00:01:37,800
for the next command you run

39
00:01:37,800 --> 00:01:41,450
to keep on reading the next page hence the name pagination.

40
00:01:41,450 --> 00:01:43,620
So the first two, projection-expression

41
00:01:43,620 --> 00:01:45,400
and filter-expression, they're only applicable

42
00:01:45,400 --> 00:01:48,720
to the DynamoDB CLI, but all these optimization

43
00:01:48,720 --> 00:01:51,380
and pagination, so page-size, max-item and starting-token,

44
00:01:51,380 --> 00:01:54,350
are applicable to way more CLI in the AWS world,

45
00:01:54,350 --> 00:01:56,310
and you need to know those going into the exam.

46
00:01:56,310 --> 00:01:58,660
So, let's go and have a little bit of practice.

47
00:01:59,550 --> 00:02:01,530
I'm going to use the UsersPost table,

48
00:02:01,530 --> 00:02:03,340
and there's three items in there,

49
00:02:03,340 --> 00:02:04,850
and I'm going to run the queries against those.

50
00:02:04,850 --> 00:02:06,280
So, we have three items.

51
00:02:06,280 --> 00:02:07,840
Two belong to the same user ID,

52
00:02:07,840 --> 00:02:09,580
and we have three different columns,

53
00:02:09,580 --> 00:02:11,970
user_id, post_ts and content.

54
00:02:11,970 --> 00:02:14,220
So, let's go how we can query this table.

55
00:02:14,220 --> 00:02:17,357
Here is my terminal, and I've created a file called

56
00:02:17,357 --> 00:02:20,100
cli-examples that you can just use to run these commands.

57
00:02:20,100 --> 00:02:22,290
The first command I want to show you

58
00:02:22,290 --> 00:02:24,410
is the projection-expression.

59
00:02:24,410 --> 00:02:27,330
If the copy and paste works, here we go, it works.

60
00:02:27,330 --> 00:02:29,940
This projection-expression is saying okay, we'll run

61
00:02:29,940 --> 00:02:33,970
a DynamoDB Scan command on the table name UserPosts,

62
00:02:33,970 --> 00:02:35,890
and I'm running in the region US East one,

63
00:02:35,890 --> 00:02:38,860
so change this if you don't run in US East one.

64
00:02:38,860 --> 00:02:41,210
The projection-expression is saying I only want

65
00:02:41,210 --> 00:02:44,740
to retrieve the user ID and the content column.

66
00:02:44,740 --> 00:02:47,250
No other attributes should be retrieved.

67
00:02:47,250 --> 00:02:49,920
So if I press enter, I'm gonna get my results

68
00:02:49,920 --> 00:02:53,970
of all my items, but all these items, the three of them,

69
00:02:53,970 --> 00:02:57,080
they only returned the content and the user ID.

70
00:02:57,080 --> 00:03:01,060
I did not retrieve from this, the post time stamp.

71
00:03:01,060 --> 00:03:02,450
So, this is a demo into

72
00:03:02,450 --> 00:03:04,550
how the projection-expression can be used.

73
00:03:06,000 --> 00:03:09,690
Next command we want to look at is this filter-expression.

74
00:03:09,690 --> 00:03:11,280
Now, they're really not easy to figure out,

75
00:03:11,280 --> 00:03:12,640
so I'm glad I did.

76
00:03:12,640 --> 00:03:15,690
Again, we run a scan on the same table.

77
00:03:15,690 --> 00:03:17,680
This time we say we want the user ID

78
00:03:17,680 --> 00:03:20,050
to be equal to this value u.

79
00:03:20,050 --> 00:03:20,883
What is u?

80
00:03:20,883 --> 00:03:23,790
Well, you need to specify an expression-attributes value

81
00:03:23,790 --> 00:03:27,740
to say that this u-value is S, which means string,

82
00:03:27,740 --> 00:03:30,170
equals to this value.

83
00:03:30,170 --> 00:03:31,420
What does this value represent?

84
00:03:31,420 --> 00:03:34,250
Well, it represents this user ID right here.

85
00:03:34,250 --> 00:03:37,780
So, it's a little bit tricky to put together this command,

86
00:03:37,780 --> 00:03:41,510
but what it should do is filter our table for the scan

87
00:03:41,510 --> 00:03:44,030
just based on the results for this user ID.

88
00:03:44,030 --> 00:03:47,820
So if I press enter, this time it scanned three rows,

89
00:03:47,820 --> 00:03:51,077
but it returned to me two rows, and the response

90
00:03:51,077 --> 00:03:54,290
of the two rows were the user ID has a value of

91
00:03:54,290 --> 00:03:57,980
string one, two, three usersoi3 so excellent.

92
00:03:57,980 --> 00:04:01,680
So, this filter-expression works as well.

93
00:04:01,680 --> 00:04:05,960
Now, let's get into the page-size demo.

94
00:04:05,960 --> 00:04:09,243
Here, I'm just going to run a straight forward scan.

95
00:04:10,280 --> 00:04:15,270
If I do a scan, this does one API call to DynamoDB, just one

96
00:04:15,270 --> 00:04:18,900
because it tries to return as much data as possible.

97
00:04:18,900 --> 00:04:22,120
But if you wanna do three API calls, we are going to run

98
00:04:22,120 --> 00:04:25,470
this command where we specify the page size to be one,

99
00:04:25,470 --> 00:04:27,730
and by having the page size being one,

100
00:04:27,730 --> 00:04:30,380
we're saying the max number of results I want

101
00:04:30,380 --> 00:04:32,670
from each API call is going to be one,

102
00:04:32,670 --> 00:04:35,140
but because we will still get the full data set,

103
00:04:35,140 --> 00:04:38,420
in the background, it will run three API calls.

104
00:04:38,420 --> 00:04:41,360
If I press enter, as we can see, we still get three

105
00:04:41,360 --> 00:04:45,690
as a final result, but we were issuing three API calls

106
00:04:45,690 --> 00:04:48,810
to DynamoDB because of this page-size argument.

107
00:04:48,810 --> 00:04:53,810
How do we limit the number of results per call to the CLI?

108
00:04:54,030 --> 00:04:56,510
Well, we use the max-items.

109
00:04:56,510 --> 00:05:00,060
If I use this max-item here, I do a scan on the same table,

110
00:05:00,060 --> 00:05:02,370
same region but now say number of items

111
00:05:02,370 --> 00:05:04,960
that I want to be returned at the maximum is one.

112
00:05:04,960 --> 00:05:09,673
I press enter, and here I only get one item back.

113
00:05:10,739 --> 00:05:12,820
And I'm given a NextToken,

114
00:05:12,820 --> 00:05:15,380
and this token is what I should be using

115
00:05:15,380 --> 00:05:20,000
as part of the starting token argument,

116
00:05:20,000 --> 00:05:22,930
and so I'm going to paste the starting token here,

117
00:05:22,930 --> 00:05:25,200
and so here I got the hello world first post.

118
00:05:25,200 --> 00:05:28,170
But if I press enter, now I'm getting my second post

119
00:05:28,170 --> 00:05:30,480
which is awesome new post, second ever,

120
00:05:30,480 --> 00:05:32,410
and I'm getting a new NextToken again,

121
00:05:32,410 --> 00:05:36,460
so we're going to reuse that new NextToken and replace it.

122
00:05:36,460 --> 00:05:41,460
So, let's use this NextToken and paste it here, press enter.

123
00:05:42,843 --> 00:05:45,430
Now, I'm getting new user new post,

124
00:05:45,430 --> 00:05:47,940
and we don't get any new NextToken.

125
00:05:47,940 --> 00:05:50,600
We don't have any new NextToken, so what does that mean?

126
00:05:50,600 --> 00:05:53,020
That means that we are done reading this table,

127
00:05:53,020 --> 00:05:54,750
and there is no more pages to read

128
00:05:54,750 --> 00:05:56,337
hence the name pagination.

129
00:05:56,337 --> 00:05:58,930
That's it, just what I wanted to show you.

130
00:05:58,930 --> 00:06:01,620
It's pretty simple, but hopefully you need to see it once

131
00:06:01,620 --> 00:06:03,730
before you understand how these things work,

132
00:06:03,730 --> 00:06:06,220
so once you remember the structure, look at the code,

133
00:06:06,220 --> 00:06:07,360
try to remember these options.

134
00:06:07,360 --> 00:06:09,100
I think it's really important to understand the difference

135
00:06:09,100 --> 00:06:13,230
between max-items and the starting-token and page-size.

136
00:06:13,230 --> 00:06:14,300
One is for optimization.

137
00:06:14,300 --> 00:06:16,520
The other one is for pagination.

138
00:06:16,520 --> 00:06:17,870
That's it for the CLI practice.

139
00:06:17,870 --> 00:06:18,703
I hope you liked this,

140
00:06:18,703 --> 00:06:20,590
and I will see you in the next lecture.

