1

Not sure, what is the issue while get item from DynamoDB.

Json View of Data :

{
 "section_id": "6177d23bb5f04ca363fe3d91",
 "chapter_id": "6177ccd4b5f04ca363fe3d63",
 "data": {
 }
}

PHP Code :

    $sdk = $this->sdk();
    $dynamodb = $sdk->createDynamoDb();

    $result = $dynamodb->getItem(
        array(
            'TableName' => 'sections',
            'Key'   => array(
                'section_id'   => array(
                    'S' => '6177d23bb5f04ca363fe3d91'
                )
            )
        )
    );
    print_r($result);
    exit;

Error I'm getting

Type: Aws\DynamoDb\Exception\DynamoDbException
Message: Error executing "GetItem" on "https://dynamodb.ap-south-1.amazonaws.com"; AWS HTTP error: Client error: `POST https://dynamodb.ap-south-1.amazonaws.com` resulted in a `400 Bad Request` response: {"__type":"com.amazon.coral.validate#ValidationException","message":"The provided key element does not match the schema" (truncated...) ValidationException (client): The provided key element does not match the schema - {"__type":"com.amazon.coral.validate#ValidationException","message":"The provided key element does not match the schema"}

2 Answers 2

2

Considering the error, There could be two possible problems here:

  1. You are only providing half of your primary key. For the primary key, you must provide all of the attributes. For example, with a simple primary key, you only need to provide a value for the partition key. For a composite primary key, you must provide values for both the partition key and the sort key.
  2. Field's value should have a proper data type as per the table. It is always better to double-check the data type of the value being passed. Maybe, you have defined the primary key as a Number and you are passing a string value in the getItem call.
Sign up to request clarification or add additional context in comments.

Comments

0

The error message tells the problem: "The provided key element does not match the schema"

Is section_id your primary key? If so, you can try it like this:

$result = $dynamodb->getItem(
    [
        'TableName' => 'sections',
        'Key' => [
            'section_id' => ['S' => '6177d23bb5f04ca363fe3d91'],
        ],
    ]
);

You are providing an array to a GetItem call but you need to provide a primary key.

See: https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_GetItem.html

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.