0

i got the error "The provided key element does not match the schema", while getting data from AWS dynamoDB using stepfunction.

stepfunction Defination

{
  "Comment": "This is your state machine",
  "StartAt": "Choice",
  "States": {
    "Choice": {
      "Type": "Choice",
      "Choices": [
        {
          "Variable": "$.data.Type",
          "StringEquals": "GET",
          "Next": "DynamoDB GetItem"
        },
        {
          "Variable": "$.data.Type",
          "StringEquals": "PUT",
          "Next": "DynamoDB PutItem"
        }
      ]
    },
    "DynamoDB GetItem": {
      "Type": "Task",
      "Resource": "arn:aws:states:::dynamodb:getItem",
      "Parameters": {
        "TableName": "KeshavDev",
        "Key": {
          "Email": {
            "S": "$.Email"
          }
        }
      },
      "End": true
    },
    "DynamoDB PutItem": {
      "Type": "Task",
      "Resource": "arn:aws:states:::dynamodb:putItem",
      "Parameters": {
        "TableName": "KeshavDev",
        "Item": {
          "City": {
            "S.$": "$.City"
          },
          "Email": {
            "S.$": "$.Email"
          },
          "Address": {
            "S.$": "$.Address"
          }
        }
      },
      "InputPath": "$.data",
      "End": true
    }
  }
}

Input

{
  "data": {
    "Type": "GET",
     "Email": "[email protected]"
  }
}

Error

{ "resourceType": "dynamodb", "resource": "getItem", "error": "DynamoDB.AmazonDynamoDBException", "cause": "The provided key element does not match the schema (Service: AmazonDynamoDBv2; Status Code: 400; Error Code: ValidationException; Request ID: a78c3d7a-ca3f-4483-b986-1735201d4ef2; Proxy: null)" }

2 Answers 2

1

I see some potential issues with the getItem task when compared to AWS documentation.

  • I think the Key field needs to be S.$ similar to what you have in your putItem task.
  • There is no ResultPath attribute to tell the state machine where to put the results.
  • Your path may not be correct, try $.data.Email
    "DynamoDB GetItem": {
      "Type": "Task",
      "Resource": "arn:aws:states:::dynamodb:getItem",
      "Parameters": {
        "TableName": "KeshavDev",
        "Key": {
          "Email": {
            "S.$": "$.data.Email"
          }
        }
      },
      "ResultPath": "$.DynamoDB",
      "End": true
    },

To be honest, I'm not sure if one of all of these are contributing to the validation error those are some things to experiment with.

On another note, there are some open source validators for Amazon State Language but for this case, they were not very helpful and said that your code was valid.

Sign up to request clarification or add additional context in comments.

2 Comments

Error is still comming, $.data.Email is right
Hi its working now, by adding both key in step function definition. dynamodb have two key. 1) primary partition key 2) primary sort key. and your mentioned steps is also right.
0

its working, above JD D mentoned steps and also by adding both key in step function definition. DynamoDb have two key.

  1. primary partition key
  2. primary sort key

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.