Skip to content

Instantly share code, notes, and snippets.

@reisjr
Created June 26, 2017 13:49
Show Gist options
  • Save reisjr/98bda1705266033c2600fc1b59a22de3 to your computer and use it in GitHub Desktop.
Save reisjr/98bda1705266033c2600fc1b59a22de3 to your computer and use it in GitHub Desktop.
DynamoDB - Optimistic Lock using timestamp
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