问题描述
当我尝试获取缓存中保存的凭据以供 mfa 登录到 aws 时,我总是收到提示 mfa 代码。但是当我登录时它正确保存在缓存中。只是没用过。
cli_cache = os.path.join(os.path.expanduser('~'),'.aws/cli/cache')
params = {'profile': 'profile-name'}
provider = botocore.session.Session(**params)
provider.get_component('credential_provider').get_provider('assume-role').cache = credentials.JSONFileCache(cli_cache)
session = Session(botocore_session=provider)
解决方法
好的,它修复了,代码是正确的。问题在于 duration_seconds
中的 .aws/credentials
与 aws 上的角色设置不同