boto3_refresh_session.session#
Helper method for generating an automatically refreshing boto3.session.Session
object.
Warning
AutoRefreshableSession
was not tested for manually passing hard-coded
account credentials to the boto3.client
object! There is an optional
client_kwargs
parameter available for doing so, which should work;
however, that cannot be guaranteed as that functionality was not tested.
Pass hard-coded credentials with the client_kwargs
parameter at your
own discretion.
Classes
Returns a |
- class boto3_refresh_session.session.AutoRefreshableSession[source]#
Returns a
boto3.session.Session
object which refreshes automatically, no extra steps required.This object is useful for long-running processes where temporary credentials may expire.
- Parameters:
- regionstr
AWS region name.
- role_arnstr
AWS role ARN.
- session_namestr
Name for session.
- defer_refreshbool, optional
If
True
then temporary credentials are not automatically refreshed until they are explicitly needed. IfFalse
then temporary credentials refresh immediately upon expiration. Default isTrue
.- ttlint, optional
Number of seconds until temporary credentials expire. Must be greater than or equal to 900 seconds. Default is 900.
- session_kwargsdict, optional
Optional keyword arguments for
boto3.session.Session
.- client_kwargsdict, optional
Optional keyword arguments for
boto3.client
.
Attributes
session
Returns a
boto3.session.Session
object with credentials which refresh automatically.Notes
Check the authorization documentation for additional information concerning how to authorize access to AWS.
The default
defer_refresh
parameter value results in temporary credentials not being refreshed until they are explicitly requested; that is more efficient than refreshing expired temporary credentials automatically after they expire.Examples
Here’s how to initialize this object:
>>> sess = brs.AutoRefreshableSession( >>> region="us-east-1", >>> role_arn="<your-arn>", >>> session_name="test", >>> ) >>> s3_client = sess.session.client(service_name="s3")