0
0
DynamoDBquery~10 mins

Write sharding 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 create a DynamoDB table with a partition key.

DynamoDB
aws dynamodb create-table --table-name UserData --attribute-definitions AttributeName=UserId,AttributeType=[1] AttributeName=ShardId,AttributeType=S --key-schema AttributeName=UserId,KeyType=HASH AttributeName=ShardId,KeyType=RANGE --provisioned-throughput ReadCapacityUnits=5,WriteCapacityUnits=5
Drag options to blanks, or click blank then click option'
AS
BBOOL
CB
DN
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'N' (number) instead of 'S' for string keys.
2fill in blank
medium

Complete the code to add a shard ID attribute to distribute writes.

DynamoDB
aws dynamodb put-item --table-name UserData --item '{"UserId": {"S": "user123"}, "ShardId": {"[1]": "shard1"}}'
Drag options to blanks, or click blank then click option'
ABOOL
BS
CN
DB
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'N' for shard ID which is a string.
3fill in blank
hard

Fix the error in the update expression to increment a shard counter.

DynamoDB
aws dynamodb update-item --table-name UserData --key '{"UserId": {"S": "user123"}, "ShardId": {"S": "shard1"}}' --update-expression "SET WriteCount = WriteCount [1] :inc" --expression-attribute-values '{":inc": {"N": "1"}}'
Drag options to blanks, or click blank then click option'
A/
B-
C*
D+
Attempts:
3 left
💡 Hint
Common Mistakes
Using '-' or '*' which do not increment the value.
4fill in blank
hard

Fill both blanks to create a batch write request for multiple shards.

DynamoDB
aws dynamodb batch-write-item --request-items '{"UserData": [[1], [2]]}'
Drag options to blanks, or click blank then click option'
A{"PutRequest": {"Item": {"UserId": {"S": "user123"}, "ShardId": {"S": "shard1"}}}}
B{"DeleteRequest": {"Key": {"UserId": {"S": "user123"}, "ShardId": {"S": "shard2"}}}}
C{"PutRequest": {"Item": {"UserId": {"S": "user456"}, "ShardId": {"S": "shard2"}}}}
D{"DeleteRequest": {"Key": {"UserId": {"S": "user456"}, "ShardId": {"S": "shard1"}}}}
Attempts:
3 left
💡 Hint
Common Mistakes
Using DeleteRequest instead of PutRequest for writes.
5fill in blank
hard

Fill all three blanks to create a conditional write that only updates if the shard count is below a limit.

DynamoDB
aws dynamodb update-item --table-name UserData --key '{"UserId": {"S": "user123"}, "ShardId": {"S": "shard1"}}' --update-expression "SET WriteCount = WriteCount + :inc" --condition-expression "WriteCount [1] :max" --expression-attribute-values '{":inc": {"N": "1"}, ":max": {"N": "[2]"}}' --return-values [3]
Drag options to blanks, or click blank then click option'
A<
B<=
C5
DALL_NEW
Attempts:
3 left
💡 Hint
Common Mistakes
Using '>=' or wrong return values causing errors.