重构AWS查询以最小化写入请求

时间:2015-09-07 03:34:44

标签: php amazon-web-services

我需要能够将信息写入AWS dynamoDB。但是并非每次写入都包含相同的信息,但我想使用相同的代码。我可以通过提出多个请求来使其工作,但我想知道是否有一种方法可以重构这个以便可以通过一个请求来完成它?

// 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'
    ));
}

0 个答案:

没有答案