Created
July 30, 2014 17:09
-
-
Save ghaering/3dffa08717c147f256d6 to your computer and use it in GitHub Desktop.
DynamoDB atomic increment
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
import boto.dynamodb2 | |
def get_connection(): | |
con = boto.dynamodb2.connect_to_region("eu-west-1") | |
return con | |
def get_new_version(con, package_name): | |
item = con.update_item( | |
"package-versioncounter", | |
{"package": {"S": package_name}}, | |
{ | |
"version": | |
{"Action": "ADD", "Value": {"N": "1"}} | |
}, return_values="ALL_NEW" | |
) | |
return int(item["Attributes"]["version"]["N"]) | |
def main(): | |
print get_new_version(get_connection(), "myapp3") | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment