0

POST to DynamoDB for user login getting.

Fatal error: Uncaught exception 'Aws\DynamoDb\Exception\DynamoDbException' with message 'Error executing "GetItem" on "https://dynamodb.us-east-1.amazonaws.com"; AWS HTTP error: Client error: POST https://dynamodb.us-east-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"}' GuzzleHttp\Exception\ClientException: Client error: POST https://dynamodb.us-east-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...) in /var/www/html/sdks/vendor/guzzlehttp/guzzle/src/Exception/RequestException.php:113 Stack trace: #0 /var/www/html/sdks/vendor/guzz in /var/www/html/sdks/vendor/aws/aws-sdk-php/src/WrappedHttpHandler.php on line 192

MY PHP Code -----

    require 'config.php';
    use Aws\DynamoDb\DynamoDbClient;

    $client = new DynamoDbClient([
        //'profile' => 'default', // access ID + secret are in the       .aws/credentials file
        'region' => 'us-east-1', // also tried with "eu-west-1"
        'version' => 'latest',
        'debug'  => true
    ]);
    // echo "after client instanciation"; // this is not displayed

    $username = null;
    $password = null;

    if ($_SERVER['REQUEST_METHOD'] == 'POST') {

    if(!empty($_POST["userid"]) && !empty($_POST["password"])) {
         $username = $_POST["userid"];
         $password = $_POST["password"];

         $response = $client->getItem(array(
             'TableName' => 'user',
             'Key' => array(
             'userid' => array( 'S' => $username),
             'password' => array( 'S' => $password),
         )
         ));

         if($username == 'userid' && $password == 'password') {
              session_start();
              $_SESSION["authenticated"] = 'true';
              header('Location: index.php');
         }
         //else {
              //header('Location: login.php');
         //}

    //} else {
         //header('Location: login.php');
    }

    print_r ($response['Item']);
  }
?>

1 Answer 1

0

I suspect your primary key (hash / partition key) is actually "userid", rather than "userid" + "password". As such, DynamoDB is telling you exactly that - whatever names you are using to pass to DynamoDB don't match up with what DynamoDB considers your primary key. I imagine once you take out the below line it will get closer to working for you:

'password' => array( 'S' => $password),

Just as an aside, you may want to securely store your passwords with some kind of algorithm - maybe bcrypt or similar. Otherwise your passwords are stored plain-text, which isn't considered a good practice these days.

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

1 Comment

Hello Steven -- Correct you are spot on the money .... i removed password and all is good.

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.