0
0
AWScloud~10 mins

Secondary indexes (GSI, LSI) in AWS - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to define a Global Secondary Index (GSI) in a DynamoDB table.

AWS
GlobalSecondaryIndexes: [{
  IndexName: "UserEmailIndex",
  KeySchema: [{ AttributeName: "email", KeyType: [1] }],
  Projection: { ProjectionType: "ALL" },
  ProvisionedThroughput: { ReadCapacityUnits: 5, WriteCapacityUnits: 5 }
}]
Drag options to blanks, or click blank then click option'
AHASH
BRANGE
CPRIMARY
DSORT
Attempts:
3 left
💡 Hint
Common Mistakes
Using RANGE instead of HASH for the partition key.
Confusing PRIMARY key type with HASH or RANGE.
2fill in blank
medium

Complete the code to add a Local Secondary Index (LSI) with a sort key.

AWS
LocalSecondaryIndexes: [{
  IndexName: "StatusIndex",
  KeySchema: [
    { AttributeName: "userId", KeyType: "HASH" },
    { AttributeName: [1], KeyType: "RANGE" }
  ],
  Projection: { ProjectionType: "KEYS_ONLY" }
}]
Drag options to blanks, or click blank then click option'
AcreatedAt
Bemail
Cstatus
DuserName
Attempts:
3 left
💡 Hint
Common Mistakes
Using an attribute that is not part of the table's key schema.
Confusing partition key with sort key.
3fill in blank
hard

Fix the error in the GSI definition by completing the missing attribute.

AWS
GlobalSecondaryIndexes: [{
  IndexName: "OrderDateIndex",
  KeySchema: [
    { AttributeName: "orderId", KeyType: "HASH" },
    { AttributeName: [1], KeyType: "RANGE" }
  ],
  Projection: { ProjectionType: "INCLUDE", NonKeyAttributes: ["total"] },
  ProvisionedThroughput: { ReadCapacityUnits: 10, WriteCapacityUnits: 5 }
}]
Drag options to blanks, or click blank then click option'
AorderDate
BcustomerId
Ctotal
Dstatus
Attempts:
3 left
💡 Hint
Common Mistakes
Using an attribute not part of the key schema as the sort key.
Choosing an attribute that is only projected but not part of the key.
4fill in blank
hard

Fill both blanks to define a DynamoDB table with a primary key and a GSI.

AWS
TableName: "Products",
AttributeDefinitions: [
  { AttributeName: "productId", AttributeType: "S" },
  { AttributeName: [1], AttributeType: "S" }
],
KeySchema: [
  { AttributeName: "productId", KeyType: "HASH" }
],
GlobalSecondaryIndexes: [{
  IndexName: "CategoryIndex",
  KeySchema: [
    { AttributeName: [2], KeyType: "HASH" }
  ],
  Projection: { ProjectionType: "ALL" },
  ProvisionedThroughput: { ReadCapacityUnits: 5, WriteCapacityUnits: 5 }
}]
Drag options to blanks, or click blank then click option'
Acategory
Bprice
Dstock
Attempts:
3 left
💡 Hint
Common Mistakes
Using different attribute names in AttributeDefinitions and KeySchema.
Using an attribute not defined in AttributeDefinitions.
5fill in blank
hard

Fill all three blanks to create a DynamoDB table with a composite primary key and a Local Secondary Index (LSI).

AWS
TableName: "Orders",
AttributeDefinitions: [
  { AttributeName: [1], AttributeType: "S" },
  { AttributeName: [2], AttributeType: "S" },
  { AttributeName: [3], AttributeType: "S" }
],
KeySchema: [
  { AttributeName: [1], KeyType: "HASH" },
  { AttributeName: [2], KeyType: "RANGE" }
],
LocalSecondaryIndexes: [{
  IndexName: "StatusIndex",
  KeySchema: [
    { AttributeName: [1], KeyType: "HASH" },
    { AttributeName: [3], KeyType: "RANGE" }
  ],
  Projection: { ProjectionType: "ALL" }
}]
Drag options to blanks, or click blank then click option'
AorderId
BcreatedAt
Cstatus
DcustomerId
Attempts:
3 left
💡 Hint
Common Mistakes
Using different partition keys for the table and LSI.
Using the same sort key for both table and LSI.