0
0
DynamoDBquery~10 mins

GSI overloading technique in DynamoDB - 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) with the partition key.

DynamoDB
CreateTableRequest {
  TableName: "Orders",
  KeySchema: [
    { AttributeName: "OrderId", KeyType: "HASH" }
  ],
  AttributeDefinitions: [
    { AttributeName: "OrderId", AttributeType: "S" },
    { AttributeName: "[1]", AttributeType: "S" }
  ],
  GlobalSecondaryIndexes: [
    {
      IndexName: "StatusIndex",
      KeySchema: [
        { AttributeName: "[1]", KeyType: "HASH" }
      ],
      Projection: { ProjectionType: "ALL" }
    }
  ]
}
Drag options to blanks, or click blank then click option'
AStatus
BPrice
CCustomerId
DOrderDate
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing the main table's partition key instead of the GSI's partition key.
Using an attribute not defined in AttributeDefinitions.
2fill in blank
medium

Complete the code to add a sort key to the GSI for sorting orders by date.

DynamoDB
GlobalSecondaryIndexes: [
  {
    IndexName: "StatusDateIndex",
    KeySchema: [
      { AttributeName: "Status", KeyType: "HASH" },
      { AttributeName: "[1]", KeyType: "RANGE" }
    ],
    Projection: { ProjectionType: "ALL" }
  }
]
Drag options to blanks, or click blank then click option'
AOrderId
BPrice
CCustomerId
DOrderDate
Attempts:
3 left
💡 Hint
Common Mistakes
Using the partition key as the sort key.
Choosing an attribute unrelated to sorting by date.
3fill in blank
hard

Fix the error in the GSI projection type to include only specific attributes.

DynamoDB
GlobalSecondaryIndexes: [
  {
    IndexName: "CustomerIndex",
    KeySchema: [
      { AttributeName: "CustomerId", KeyType: "HASH" }
    ],
    Projection: { ProjectionType: "[1]", NonKeyAttributes: ["OrderDate", "Status"] }
  }
]
Drag options to blanks, or click blank then click option'
AALL
BKEYS_ONLY
CINCLUDE
DNONE
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'ALL' projection type when only specific attributes are needed.
Using 'KEYS_ONLY' which excludes non-key attributes.
4fill in blank
hard

Fill both blanks to create a GSI that overloads the 'Status' attribute to store different types of data.

DynamoDB
GlobalSecondaryIndexes: [
  {
    IndexName: "OverloadIndex",
    KeySchema: [
      { AttributeName: "[1]", KeyType: "HASH" },
      { AttributeName: "[2]", KeyType: "RANGE" }
    ],
    Projection: { ProjectionType: "ALL" }
  }
]
Drag options to blanks, or click blank then click option'
AStatus
BOrderDate
CCategory
DCustomerId
Attempts:
3 left
💡 Hint
Common Mistakes
Using unrelated attributes that don't support overloading.
Mixing up partition and sort keys.
5fill in blank
hard

Fill all three blanks to write a DynamoDB query using the overloaded GSI to get items with a specific status and category.

DynamoDB
const params = {
  TableName: "Orders",
  IndexName: "OverloadIndex",
  KeyConditionExpression: "#S = :statusVal AND #C = :categoryVal",
  ExpressionAttributeNames: {
    "#S": "[1]",
    "#C": "[2]"
  },
  ExpressionAttributeValues: {
    ":statusVal": { S: "shipped" },
    ":categoryVal": { S: "electronics" }
  }
};
Drag options to blanks, or click blank then click option'
AStatus
BCategory
COrderDate
DCustomerId
Attempts:
3 left
💡 Hint
Common Mistakes
Using attribute names not defined in the GSI.
Mixing up placeholders and attribute names.