dimanche 6 septembre 2015

Refactor AWS query to minimize write requests

I need to be able to write information to an AWS dynamoDB. However not every write includes the same information, but I would like to use the same code. I can make it work by making multiple requests, but I was wondering if there a way I can refactor this so it can be done with one request?

// This code makes the initial write using what is always posted.
$newRecord = $client->putItem(array(
  'TableName' => 'ximoRepV3',
  'Item' => array(
    'rep_num' => array('S' => $rep_num),
    'fc_key' => array('BOOL' => false),
    ...
  )
));

// Then I have a series of if's for writes that are not always present.
if (!empty($salt)){
    $saltUpdate = $client->updateItem ( array (
    'TableName' => 'ximoRepV3',
    'Key' => array (
      'rep_num' => array (
        'S' => $rep_num
      ) 
    ),
    'ExpressionAttributeValues' =>  array (
      ':salt' => array('S' => $salt)
    ),
    'UpdateExpression' => 'SET salt = :salt'
    ));
}




Aucun commentaire:

Enregistrer un commentaire