Skip to content

Instantly share code, notes, and snippets.

@ShakataGaNai
Last active December 17, 2015 06:29
Show Gist options
  • Save ShakataGaNai/5566077 to your computer and use it in GitHub Desktop.
Save ShakataGaNai/5566077 to your computer and use it in GitHub Desktop.
function ddbLogSMS() - Sample for DynamoDB/Twilio. For http://snowulf.com/2013/05/13/wrapping-my-brain-around-dynamodb/
function ddbLogSMS($act,$data){
date_default_timezone_set("UTC");
$now = time();
$upd = array();
$upd['ACTION'] = array("Action" => \Aws\DynamoDb\Enum\AttributeAction::PUT,
"Value" => array(
Type::STRING => $act
)
);
$upd['DATE_RFC822'] = array("Action" => \Aws\DynamoDb\Enum\AttributeAction::PUT,
"Value" => array(
Type::STRING => date(DATE_RFC822,$now)
)
);
foreach($data as $key => $val){
if($key != 'SmsSid' && $key != "sid" && strlen($val)>0){
$upd[$key] = array("Action" => \Aws\DynamoDb\Enum\AttributeAction::PUT,
"Value" => array(
Type::STRING => $val
)
);
}
}
if($act == "RECIEVED"){
$sid = $data['SmsSid'];
}
if($act == "SENT"){
$sid = $data->sid;
}
$ddb = $GLOBALS["aws"]->get('dynamodb');
$res = $ddb->updateItem(array(
"TableName" => DDBLOG,
"Key" => array(
"SmsSid" => array(
Type::STRING => $sid
),
"TIMESTAMP" => array(
Type::NUMBER => $now
)
),
"AttributeUpdates" => $upd
));
} //end ddbLogSMS();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment