Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Inserting unique value into DynamoDB list.
$marshaler = new Marshaler();
$UpdateExpression = "
SET #subscribers = list_append(if_not_exists(#subscribers, :empty_list), :subscriber)
";
$ConditionExpression = "
NOT contains (#subscribers,:subscriberStr)
";
$ExpressionAttributeNames = [
"#subscribers" => "subscribers"
];
$ExpressionAttributeValues = $marshaler->marshalJson('
{
":subscriber" : ['.$subscriber.'],
":subscriberStr" : '.$subscriber.',
":empty_list" :[]
}
');
$tableName = 'publisherRelationships';
$key = $marshaler->marshalJson('
{
"publisher": '.$publisher.'
}
');
$params = [
'TableName' => $tableName,
'Key' => $key,
'UpdateExpression' => $UpdateExpression,
'ConditionExpression' => $ConditionExpression,
'ExpressionAttributeNames' => $ExpressionAttributeNames,
'ExpressionAttributeValues' => $ExpressionAttributeValues
];
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.