0
0
DynamoDBquery~10 mins

Idempotency tokens 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 add an idempotency token attribute named 'IdempotencyKey' to the DynamoDB item.

DynamoDB
item = { 'OrderId': '123', 'Amount': 100, 'IdempotencyKey': [1] }
Drag options to blanks, or click blank then click option'
ATrue
B12345
CNone
D'unique-token-123'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a number instead of a string for the token.
Using None or boolean values as tokens.
2fill in blank
medium

Complete the code to include the idempotency token in the DynamoDB PutItem request condition expression to prevent duplicate writes.

DynamoDB
response = table.put_item(Item=item, ConditionExpression='attribute_not_exists([1])')
Drag options to blanks, or click blank then click option'
AOrderId
BIdempotencyKey
CAmount
DTimestamp
Attempts:
3 left
💡 Hint
Common Mistakes
Checking attribute_not_exists on the wrong attribute.
Using attribute names that are not part of the item.
3fill in blank
hard

Fix the error in the code by completing the parameter to generate a unique idempotency token using Python's uuid module.

DynamoDB
import uuid
idempotency_token = [1]
Drag options to blanks, or click blank then click option'
Auuid.uuid4()
Buuid.generate()
Cuuid4()
Duuid.random()
Attempts:
3 left
💡 Hint
Common Mistakes
Calling uuid4() without the uuid prefix.
Using non-existent methods like generate() or random().
4fill in blank
hard

Fill both blanks to complete the DynamoDB update expression that sets the idempotency token only if it does not already exist.

DynamoDB
response = table.update_item(
  Key={'OrderId': '123'},
  UpdateExpression='SET [1] = :token',
  ConditionExpression='attribute_not_exists([2])',
  ExpressionAttributeValues={':token': idempotency_token}
)
Drag options to blanks, or click blank then click option'
AIdempotencyKey
BOrderId
CAmount
DTimestamp
Attempts:
3 left
💡 Hint
Common Mistakes
Using different attribute names in UpdateExpression and ConditionExpression.
Using attributes unrelated to the idempotency token.
5fill in blank
hard

Fill all three blanks to complete the Python dictionary comprehension that creates a map of order IDs to their idempotency tokens, filtering only orders with tokens present.

DynamoDB
idempotency_map = {order['[1]']: order['[2]'] for order in orders if '[3]' in order}
Drag options to blanks, or click blank then click option'
AOrderId
BIdempotencyKey
DAmount
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong attribute names for keys or values.
Filtering on an attribute not related to the token.