Created
June 26, 2017 13:49
-
-
Save reisjr/98bda1705266033c2600fc1b59a22de3 to your computer and use it in GitHub Desktop.
DynamoDB - Optimistic Lock using timestamp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
dynamodb = boto3.resource('dynamodb') | |
table = dynamodb.Table(ddb_table) | |
table.put_item( | |
Item={ | |
'device_id': event['clientId'], | |
'timestamp': str(event['timestamp']), | |
'status': event['eventType'] | |
}, | |
ConditionExpression=':ts >= #ts_old OR attribute_not_exists(#ts_old)', | |
ExpressionAttributeValues={':ts': str(event['timestamp']) }, | |
ExpressionAttributeNames={'#ts_old': 'timestamp'} | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment