Introduction
Expression attribute names help you use reserved words or special characters in your DynamoDB queries safely.
Jump into concepts and practice - no test required
ExpressionAttributeNames = {"#key": "ActualAttributeName"}
Use #key in your expressions instead of ActualAttributeName.ExpressionAttributeNames = {"#N": "AND"}
UpdateExpression = "SET #N = :val"ExpressionAttributeNames = {"#A": "Address City"}
ProjectionExpression = "#A"ExpressionAttributeNames = {"#D": "FOR"}
FilterExpression = "#D = :dateVal"import boto3 dynamodb = boto3.resource('dynamodb') table = dynamodb.Table('Users') response = table.update_item( Key={'UserId': '123'}, UpdateExpression='SET #N = :name', ExpressionAttributeNames={'#N': 'AND'}, ExpressionAttributeValues={':name': 'Alice'} ) print(response['ResponseMetadata']['HTTPStatusCode'])
Expression Attribute Names in DynamoDB queries?status in a DynamoDB UpdateExpression?FilterExpression: "#yr = :yearVal"
ExpressionAttributeNames: {"#yr": "year"}
ExpressionAttributeValues: {":yearVal": 2023}UpdateExpression: "SET #nm = :nameVal"
ExpressionAttributeNames: {"#name": "name"}
ExpressionAttributeValues: {":nameVal": "Alice"}order (a reserved word) and the attribute order#count (which contains a special character) in a DynamoDB item. Which is the correct way to write the UpdateExpression and ExpressionAttributeNames?