0
0
DynamoDBquery~10 mins

Composite primary key 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 composite primary key with partition key 'UserId'.

DynamoDB
KeySchema: [{ AttributeName: 'UserId', KeyType: '[1]' }]
Drag options to blanks, or click blank then click option'
APRIMARY
BRANGE
CHASH
DINDEX
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'RANGE' instead of 'HASH' for the partition key.
Using 'PRIMARY' or 'INDEX' which are not valid KeyType values.
2fill in blank
medium

Complete the code to add a sort key named 'OrderId' in the composite primary key.

DynamoDB
KeySchema: [
  { AttributeName: 'UserId', KeyType: 'HASH' },
  { AttributeName: 'OrderId', KeyType: '[1]' }
]
Drag options to blanks, or click blank then click option'
APRIMARY
BINDEX
CHASH
DRANGE
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'HASH' instead of 'RANGE' for the sort key.
Using 'PRIMARY' or 'INDEX' which are not valid KeyType values.
3fill in blank
hard

Fix the error in the attribute definitions for the composite primary key.

DynamoDB
AttributeDefinitions: [
  { AttributeName: 'UserId', AttributeType: '[1]' },
  { AttributeName: 'OrderId', AttributeType: 'S' }
]
Drag options to blanks, or click blank then click option'
AS
BBOOL
CB
DN
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'N' (number) when the attribute is a string.
Using 'BOOL' which is not valid for key attributes.
4fill in blank
hard

Fill both blanks to complete the table creation with composite primary key.

DynamoDB
CreateTable({
  TableName: 'Orders',
  KeySchema: [
    { AttributeName: '[1]', KeyType: 'HASH' },
    { AttributeName: '[2]', KeyType: 'RANGE' }
  ],
  AttributeDefinitions: [
    { AttributeName: 'UserId', AttributeType: 'S' },
    { AttributeName: 'OrderId', AttributeType: 'S' }
  ]
})
Drag options to blanks, or click blank then click option'
AUserId
BOrderDate
COrderId
DCustomerId
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping partition and sort key names.
Using attribute names not defined in AttributeDefinitions.
5fill in blank
hard

Fill all three blanks to define a composite primary key and attribute types correctly.

DynamoDB
CreateTable({
  TableName: 'Purchases',
  KeySchema: [
    { AttributeName: '[1]', KeyType: 'HASH' },
    { AttributeName: '[2]', KeyType: 'RANGE' }
  ],
  AttributeDefinitions: [
    { AttributeName: '[1]', AttributeType: 'S' },
    { AttributeName: '[2]', AttributeType: 'N' }
  ]
})
Drag options to blanks, or click blank then click option'
ACustomerId
BPurchaseDate
COrderId
DUserId
Attempts:
3 left
💡 Hint
Common Mistakes
Mismatching attribute names between KeySchema and AttributeDefinitions.
Using wrong attribute types for keys.