Skip to content

Instantly share code, notes, and snippets.

@ShakataGaNai ShakataGaNai/gist:5566077
Last active Dec 17, 2015

Embed
What would you like to do?
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
You can’t perform that action at this time.