‫So let's have a look
‫at how we can create indexes.
‫So back into my tables, I'm going to create a new table,
‫and I'll call this one demo_indexes.
‫And we need to choose a Partition key,
‫so let's choose user_id.
‫And a sort key, game_timestamp.
‫So this is allowing us to query
‫on user_id and game_timestamp.
‫And for this I'm going to customize settings.
‫I'm going to say I want Provisioned capacity
‫of one RCU and one WCU grades.
‫And here we can define our secondary indexes.
‫So you can see,
‫we can create either a local index or a global index.
‫Now local indexes can only be created
‫at table creation time,
‫whereas global indexes can be created afterwards.
‫So we can create a local index.
‫And here we need to specify a different Sort key.
‫So as you can see,
‫we do not have the option
‫to specify a different Partition key,
‫so user_id will remain the Partition key for this index,
‫but we can specify a different Sort key.
‫So for example,
‫let's say I want to create a local index
‫and the Sort key's going to be called game_id.
‫So now the Index name is game_id_index.
‫And then what attributes
‫do we want to project onto this index?
‫Do we want All, Only the keys,
‫or only Include specific attribute names that we specify.
‫So we'll keep it simple and have it as All.
‫So we just created this index and we could go ahead
‫and create a global secondary index
‫in which we have the option
‫to specify a different Partition key
‫and optionally a different Sort key,
‫as well as project some attributes.
‫So let's just for now not create
‫this global secondary index.
‫We're just going to create a local index, okay?
‫And then click on Create table.
‫Okay, so my table is now created
‫and let's have a look at how we can query it right now.
‫So if I go into Query, as we can see,
‫I can query either a table or an index and have two options.
‫I can query my demo_indexes, which is my table.
‫So I can specify a user_id and a game_timestamp,
‫or I could query my index and specify a user_id
‫and a game_id.
‫So as we can see this local index allows me
‫to query by a different Partition key,
‫a different Sort key, excuse me,
‫with the same Partition key.
‫So let's go back into the table details
‫and let's go into the Indexes tab.
‫So as you can see,
‫there is one local secondary index that has been defined.
‫So this one, and we cannot create another one.
‫So LSIs have to be defined at the table creation time
‫and not afterwards,
‫or as GSIs, so global secondary indexes,
‫can be created afterwards.
‫So we could create an index
‫and we could enter a completely different Partition key,
‫for example, game_id, and a Sort key could be,
‫for example, game_timestamp, okay?
‫And this gives me a GSI.
‫Now we need to also create some capacity for my GSS.
‫So the local secondary indexes tap in the RCU and WSU
‫of the main table, whereas for a global secretary index,
‫you need to create your own read and write capacity.
‫So either we copy from base table or we customize settings
‫and we can, again, specify Auto scaling On and Off.
‫So we'll just copy from base table
‫and have a one and one for RCU and WCUs,
‫and then what attributes we want to project.
‫And then this global secondary index is going to be created.
‫Now, remember, if you query a lot
‫that GSI and writes get throttled,
‫then the writes will be throttled as well on the main table.
‫Whereas the LSI just taps into the RCU and WCU
‫of the main table.
‫Okay, so my global secondary index is now created.
‫And what I can do now is that if I go back into view items,
‫I can look at my table and now I can query
‫by game_id-game_timestamp-index.
‫And so, as you can see now,
‫the Partition key can query by is by game_id.
‫And my Sort key is my game-timestamp.
‫So this really shows you all the powers of indexes.
‫I hope this makes sense,
‫and I will see you in the next lecture.