Created
November 23, 2018 03:59
-
-
Save bskim45/9af5d81ac315738035b7f4104679e19b to your computer and use it in GitHub Desktop.
Pynamodb AWS_PROFILE https://github.com/pynamodb/PynamoDB/issues/204#issuecomment-360568930
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
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