-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Move JSONFileCache to botocore #1338
Conversation
Codecov Report
@@ Coverage Diff @@
## develop #1338 +/- ##
===========================================
+ Coverage 98.13% 98.13% +<.01%
===========================================
Files 46 46
Lines 7701 7732 +31
===========================================
+ Hits 7557 7588 +31
Misses 144 144
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks fine. I just had a question about the default location of the cache.
botocore/credentials.py
Outdated
values can be retrieved at a later time. | ||
""" | ||
|
||
CACHE_DIR = os.path.expanduser(os.path.join('~', '.aws', 'cli', 'cache')) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should consider using a different directory than what the CLI uses. I have not thought through whether there will be edge cases to this, but it may be surprising if you are running a script to learn that your temp credentials were being cached under a cli
directory. I wonder if it makes sense to call it boto
or python
instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sounds reasonable
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me. Don't forget to add an enhancement changelog. 🚢
Will do. Also gonna put up a PR for the cli to switch to using this. |
cf0e41b
to
b915ca3
Compare
Can we get a quick explanation of how to use this? Is it possible to cache the MFA globally yet? |
@et304383 - here is an example of leveraging the AWS CLI cache. Note you could create your own custom cache location if you wanted.
|
…and thread: boto/botocore#1338 Special thanks to @mixja.
If you need to specify a profile you have to specify it in botocore.Session. It's too late to specify it in boto3.Session as AssumeRoleProvider instantiates with wrong 'default' profile.
|
@bgabrhelik - it's generally better practice to rely on the external environment to configure your credentials, rather than specify an AWS profile name in code. This approach has benefit of allowing the code to work in EC2/ECS environments where you may be using EC2 instance profile or ECS task role. My code snippet works in a local desktop environment assuming you have set profile name as environment variable - e.g. |
See boto/botocore#1157 and also boto/botocore#1338 which actually merged. There's no global way to say that we want Boto3 to cache credentials; we need to do a dance for every session. TODO: Should we use the same credentials cache as awscli? Right now this uses the default boto3 cache location which is different. TODO: Should we remove the custom caching at the boto2 monkey patch level?
Does anyone know if there's a feature request to implement this as a configuration option, like @JordonPhillips mentioned in initial description?
|
This moves the file cache to botocore and allows users to set their
own cache via
create_credential_resolver
.Future work: allow setting this via the config file and/or some other
easy method of configuration.
Closes #1157