Skip to content

Instantly share code, notes, and snippets.

@ghaering
Created July 30, 2014 17:09
Show Gist options
  • Save ghaering/3dffa08717c147f256d6 to your computer and use it in GitHub Desktop.
Save ghaering/3dffa08717c147f256d6 to your computer and use it in GitHub Desktop.
DynamoDB atomic increment
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