dynobase-icon
Dynobase

Error: name key is not defined dynamodb

Rafal Wilinski

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'))

Better DynamoDB experience.

Try 7-day free trial. No credit card needed.

Product Features

Download
/
Changelog
/
Pricing
/
Member Portal
/
Privacy
/
EULA
/
Twitter
/
Affiliates & Influencers
© 2024 Dynobase
+
Tired of AWS Console?
Try Dynobase to accelerate your DynamoDB workflow. Start your 7-day free trial today.