0
0
DynamoDBquery~10 mins

Local Secondary Index (LSI) 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 Local Secondary Index (LSI) with a sort key.

DynamoDB
LocalSecondaryIndexes: [{
  IndexName: 'LSI1',
  KeySchema: [
    { AttributeName: 'UserId', KeyType: 'HASH' },
    { AttributeName: [1], KeyType: 'RANGE' }
  ],
  Projection: { ProjectionType: 'ALL' }
}]
Drag options to blanks, or click blank then click option'
AEmail
BUserId
CTimestamp
DStatus
Attempts:
3 left
💡 Hint
Common Mistakes
Using the same attribute 'UserId' for both partition and sort key.
Choosing an attribute not defined in the table schema.
2fill in blank
medium

Complete the query to use the LSI by specifying the index name.

DynamoDB
const params = {
  TableName: 'Orders',
  IndexName: [1],
  KeyConditionExpression: 'UserId = :uid and Timestamp > :ts',
  ExpressionAttributeValues: {
    ':uid': 'user123',
    ':ts': 1609459200
  }
};
Drag options to blanks, or click blank then click option'
ADefaultIndex
BLSI1
CGSI1
DPrimaryIndex
Attempts:
3 left
💡 Hint
Common Mistakes
Using the primary index name or a Global Secondary Index name instead of the LSI name.
Omitting the 'IndexName' parameter.
3fill in blank
hard

Fix the error in the LSI definition by choosing the correct attribute type for the sort key.

DynamoDB
AttributeDefinitions: [
  { AttributeName: 'UserId', AttributeType: 'S' },
  { AttributeName: 'Timestamp', AttributeType: [1] }
],
Drag options to blanks, or click blank then click option'
AN
BB
CS
DBOOL
Attempts:
3 left
💡 Hint
Common Mistakes
Setting 'Timestamp' as a string when it is stored as a number.
Using unsupported attribute types like 'BOOL' for keys.
4fill in blank
hard

Fill both blanks to complete the LSI query with correct KeyConditionExpression and attribute values.

DynamoDB
const params = {
  TableName: 'Orders',
  IndexName: 'LSI1',
  KeyConditionExpression: 'UserId = :uid and [1] > :ts',
  ExpressionAttributeValues: {
    ':uid': 'user123',
    [2]: 1609459200
  }
};
Drag options to blanks, or click blank then click option'
ATimestamp
B:ts
C:timestamp
D:time
Attempts:
3 left
💡 Hint
Common Mistakes
Using different placeholder names in the expression and values.
Using attribute names instead of placeholders in ExpressionAttributeValues.
5fill in blank
hard

Fill all three blanks to define an LSI with correct attribute definitions, key schema, and projection type.

DynamoDB
AttributeDefinitions: [
  { AttributeName: 'UserId', AttributeType: 'S' },
  { AttributeName: [1], AttributeType: 'N' }
],
LocalSecondaryIndexes: [{
  IndexName: 'LSI1',
  KeySchema: [
    { AttributeName: 'UserId', KeyType: 'HASH' },
    { AttributeName: [2], KeyType: 'RANGE' }
  ],
  Projection: { ProjectionType: [3] }
}]
Drag options to blanks, or click blank then click option'
ATimestamp
CALL
DUserId
Attempts:
3 left
💡 Hint
Common Mistakes
Mismatch between attribute definitions and key schema attribute names.
Using incorrect projection types.