AWS Lambda – name ‘Key’ is not defined

When going through the example from I ran into the following error message:

  "errorMessage": "name 'Key' is not defined",
  "errorType": "NameError",
  "stackTrace": [
    "  File \"/var/task/\", line 20, in lambda_handler\n    KeyConditionExpression=Key('year').eq(1985)\n"

The error come from this line

response = table.query(

The issue was that I was only importing boto3, this is not enough. Guess I have to read the whole tutorial. You’ll have to add the following import.

from boto3.dynamodb.conditions import Key