Skip to content

Instantly share code, notes, and snippets.

@bskim45
Created November 23, 2018 03:59
Show Gist options
  • Save bskim45/9af5d81ac315738035b7f4104679e19b to your computer and use it in GitHub Desktop.
Save bskim45/9af5d81ac315738035b7f4104679e19b to your computer and use it in GitHub Desktop.
from pynamodb.models import Model
from pynamodb.attributes import UnicodeAttribute, NumberAttribute
class MyModel(Model):
class Meta:
table_name = 'mytable'
group = UnicodeAttribute(hash_key=True)
id = NumberAttribute(range_key=True)
name = UnicodeAttribute()
def monkeypatch_connection(profile=None):
from botocore.session import Session
from pynamodb.connection.base import Connection
@property
def session(self):
if getattr(self._local, 'session', None) is None:
self._local.session = Session(profile=profile)
return self._local.session
Connection.session = session
monkeypatch_connection(profile='my-aws-profile')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment