Search code examples
phpcodeigniteramazon-dynamodbjquery-filter

Query with codeigniter 3 and dynamodb


How do I make a query in Codeigniter 3 with dynamodb and in addition include an index?

In my example I get the following error:

1 validation error detected: Value null at 'hashKeyValue' failed to satisfy constraint: Member must not be null

This is my example :

function obtener($fecha_registro) {

   $client = new AmazonDynamoDB(); 
   $response = $client->query( array(

     'TableName' => 'nom_table',
    'KeyConditionExpression' => 'id_registro = :v_hash and fecha_registro = :v_range',
    'ExpressionAttributeValues' =>  array (
        ':v_hash'  => array('S' => '148537355319'),
        ':v_range' => array('S' => $fecha_registro)
    )
));


     print_r($response);
        if ($response->status == '200'){
            return $response->body->Items;
        } else {     
            print_r($response);
        }
}

Solution

  • The Only Reason you are getting this Error is :

    Amazon DynamoDB is not handling empty or null attributes.

    As per DynamoDB Documentation :

    Attribute values cannot be null.

    The Same issue is Raised at AWS Developer Forum also.

    Solution :

    Before passing your variable $fecha_registro to function obtener(), You need to check whether the passed variable is Non Empty or Not Null

    For your scenario just add a check before calling your function as below :

    if(isset($fecha_registro) && ($fecha_registro != '' || $fecha_registro != NULL)){
         obtener($fecha_registro);
    }