Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does boto3 have a credential cache comparable to awscli?

With awscli there's a credential cache in ~/.aws/cli/cache which allows me to cache credentials for a while. This is very helpful when using MFA. Does boto3 have a similar capability or do I have to explicitly cache my credentials returned from session = boto3.session.Session(profile_name='CTO:Admin')?

like image 581
n2ygk Avatar asked Mar 08 '16 17:03

n2ygk


People also ask

Do you need AWS CLI for Boto3?

No, you don't need the awscli.

What is Aws_session_token?

AWS_SESSION_TOKEN - environment variableSpecifies an AWS session token used as part of the credentials to authenticate the user. A session token is required only if you manually specify temporary security credentials.


2 Answers

Originally, the credential caching and automatic renewing of temporary credentials was part of the AWSCLI but this commit (and some subsequent ones) moved that functionality to botocore which means it is now available in boto3, as well.

like image 144
garnaat Avatar answered Oct 12 '22 19:10

garnaat


I created a Python library that provides this for you - see https://github.com/mixja/boto3-session-cache

Example:

import boto3_session_cache

# This returns a regular boto3 client object with the underlying session configured with local credential cache 
client = boto3_session_cache.client('ecs')
ecs_clusters = client.list_clusters()
like image 27
mixja Avatar answered Oct 12 '22 20:10

mixja