Skills covered: 1.2.1, 1.2.2, 1.2.5, 1.3.4, 1.3.6
OrdersorderId (String), Sort key: createdAt (String)com.amazonaws.{region}.dynamodbimport boto3
dynamodb = boto3.resource('dynamodb')
table = dynamodb.Table('Orders')
def handler(event, context):
# PutItem
table.put_item(Item={'orderId': '001', 'createdAt': '2025-01-01', 'status': 'new'})
# GetItem
response = table.get_item(Key={'orderId': '001', 'createdAt': '2025-01-01'})
# Query
response = table.query(KeyConditionExpression=Key('orderId').eq('001'))
return {'statusCode': 200, 'body': 'OK'}