Created
December 15, 2019 00:56
-
-
Save hashbrowncipher/60b21356e580008dad1012c2c76bb5f5 to your computer and use it in GitHub Desktop.
subclass of botocore.session.Session that assumes roles and refreshes credentials
This file contains hidden or 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 botocore.session import Session | |
credentials_cache = dict() | |
class Session(Session): | |
def __init__(self, role_arn, *args, **kwargs): | |
super().__init__(*args, **kwargs) | |
self._config = dict( | |
profiles=dict( | |
default=dict( | |
credential_source="Ec2InstanceMetadata", | |
role_arn=role_arn, | |
) | |
) | |
) | |
self.get_component("credential_provider").get_provider( | |
"assume-role" | |
).cache = credentials_cache | |
@classmethod | |
def from_role(cls, *args, **kwargs): | |
arn = _role_arn(*args, **kwargs) | |
return cls(arn) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment