0
0
DynamoDBquery~10 mins

Global Secondary Index (GSI) concept 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 a partition key.

DynamoDB
GlobalSecondaryIndexes: [{
  IndexName: 'UserEmailIndex',
  KeySchema: [{ AttributeName: [1], KeyType: 'HASH' }],
  Projection: { ProjectionType: 'ALL' }
}]
Drag options to blanks, or click blank then click option'
A'email'
B'username'
C'userId'
D'createdAt'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the primary key attribute instead of the GSI partition key.
2fill in blank
medium

Complete the code to specify the projection type for a GSI that only includes specific attributes.

DynamoDB
Projection: {
  ProjectionType: [1],
  NonKeyAttributes: ['name', 'age']
}
Drag options to blanks, or click blank then click option'
A'INCLUDE'
B'ALL'
C'KEYS_ONLY'
D'NONE'
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing 'ALL' projection when only specific attributes are needed.
3fill in blank
hard

Fix the error in the GSI KeySchema definition by choosing the correct key type for the sort key.

DynamoDB
KeySchema: [
  { AttributeName: 'email', KeyType: 'HASH' },
  { AttributeName: 'signupDate', KeyType: [1] }
]
Drag options to blanks, or click blank then click option'
A'HASH'
B'SORT'
C'RANGE'
D'PRIMARY'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'SORT' instead of 'RANGE' for the sort key.
4fill in blank
hard

Fill both blanks to define a GSI with a partition key and a sort key.

DynamoDB
GlobalSecondaryIndexes: [{
  IndexName: 'OrderIndex',
  KeySchema: [
    { AttributeName: [1], KeyType: 'HASH' },
    { AttributeName: [2], KeyType: 'RANGE' }
  ],
  Projection: { ProjectionType: 'ALL' }
}]
Drag options to blanks, or click blank then click option'
A'customerId'
B'orderDate'
C'productId'
D'status'
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping partition and sort keys.
5fill in blank
hard

Fill all three blanks to create a GSI with a partition key, sort key, and projection type.

DynamoDB
GlobalSecondaryIndexes: [{
  IndexName: 'ProductIndex',
  KeySchema: [
    { AttributeName: [1], KeyType: 'HASH' },
    { AttributeName: [2], KeyType: 'RANGE' }
  ],
  Projection: { ProjectionType: [3] }
}]
Drag options to blanks, or click blank then click option'
A'category'
B'price'
C'ALL'
D'KEYS_ONLY'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'KEYS_ONLY' when all attributes are needed.