Skip to content

Instantly share code, notes, and snippets.

@ankona
Created May 23, 2016 18:25
Show Gist options
  • Select an option

  • Save ankona/b2d827e68f8c60b5def75e97f0421124 to your computer and use it in GitHub Desktop.

Select an option

Save ankona/b2d827e68f8c60b5def75e97f0421124 to your computer and use it in GitHub Desktop.
settings table example
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import boto3
from boto.dynamodb2.table import Table
def saveSetting(applicationName, settingName, value):
client = boto3.client('dynamodb')
response = client.update_item(TableName="chrisSettings",
Key={ "applicationName": { "S": applicationName } },
AttributeUpdates={ settingName: { "Value": {"S": value} } })
def getSetting(applicationName, settingName, settingType="S"):
client = boto3.client('dynamodb')
#todo: cache the entire item, then pull settings from there instead of going to the db each time and using ProjectionExpression.
#NOTE: use of AttributesToGet is deprecated, but ProjectionExpression breaks if you have settings with spaces in the names...
response = client.get_item(TableName="chrisSettings",
Key={ "applicationName": { "S": applicationName } },
ProjectionExpression=settingName)
#AttributesToGet=[settingName])
#print response
return response["Item"][settingName][settingType]
if __name__ == '__main__':
saveSetting("portal", "PortalSetting1", "value 1")
saveSetting("portal", "PortalSetting2", "value 2")
saveSetting("portal", "PortalSetting3", "value 3")
saveSetting("career network", "CN2.0Setting1", "value 4")
saveSetting("career network", "CN2.0Setting2", "value 5")
saveSetting("whowhat", "WhoOrWhatSetting1", "value 6")
setting = getSetting("whowhat", "WhoOrWhatSetting1")
print setting
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment