Search code examples
amazon-dynamodbaws-step-functionsdynamodb-queries

StepFunction, DynamoDB: Query condition missed key schema element


I'm trying to query a DynamoDB table in a Step Function but it's throwing the following error.

Query condition missed key schema element: Scope (Service: DynamoDb, Status Code: 400, Request ID: FN4G...)

The Step Function Task definition is;

    "Obtain Users info": {
      "Type": "Task",
      "Parameters": {
        "TableName": "Users",
        "KeyConditionExpression": "#Scope = :Global",
        "ExpressionAttributeNames": {
          "#Scope": {
            "S": "Scope"
          }
        },
        "ExpressionAttributeValues": {
          ":Global": {
            "S": "Global"
          }
        }
      },
      "Resource": "arn:aws:states:::aws-sdk:dynamodb:query",
      "Next": "Pass"
    },

The DyanmoDB definition is; enter image description here

And here's a sample item from the table

{
  "Scope": {
    "S": "Global"
  },
  "ServiceName": {
    "S": "driver"
  },
  "lastVisitDateTime": {
    "N": "1680022106"
  },
  "Status": {
    "S": "ONLINE"
  }
}

Any pointers on what I'm missing?? Thanks!


Solution

  • Your parameters should be as follows:

        "Obtain Users info": {
          "Type": "Task",
          "Parameters": {
            "TableName": "Users",
            "KeyConditionExpression": "#Scope = :Global",
            "ExpressionAttributeNames": {
              "#Scope": "Scope"
            },
            "ExpressionAttributeValues": {
              ":Global": {
                "S": "Global"
              }
            }
          },
          "Resource": "arn:aws:states:::aws-sdk:dynamodb:query",
          "Next": "Pass"
        },
    

    ExpressionAttributeNames does not take a data type as they are always defined as strings.