Error: name key is not defined dynamodb

Answered by Rafal Wilinski
What's Causing This Error
This error occurs in Python when referring to the Key module in a query operation without importing it.
Solution: Here's How To Resolve It
To resolve the error, import the Key module, as shown below.
import boto3 // import Key from boto3.dynamodb.conditions import Key
Afterwards, you can execute a DynamoDB query, as shown below.
dynamodb = boto3.resource('dynamodb')
table = dynamodb.Table('Employees')
response = table.query(KeyConditionExpression=Key('pk').eq('USER#1'))
Other Common DynamoDB Errors (with Solutions)
- DynamoDB Failed To Compute Node presentation
- dynamodb cannot assign requested address
- DynamoDB Is Not Null
- dynamodb cannot read property 'push' of undefined
- DynamoDB Scan Not Working
- DynamoDB Not Supported Requires @DynamoDBTyped Or @DynamoDBTypeConverted
- DynamoDB Update Not Working
- dynamodb throughput error
- DynamoDB type is not supported
- DynamoDB could not invoke null on class
- DynamoDB missing items
- DynamoDB BatchWriteItem error
- DynamoDB table not updating
- DynamoDB query is slow
- Dynamodb error 500
Dynobase is a Professional GUI Client for DynamoDB
Try 7-day free trial. No credit card needed.
Product Features
DynamoDB Tools
DynamoDB Info
© 2026 Dynobase