Pyjo.AWS.Credentials.Chain - Chain of the providers of credentials¶
from Pyjo.AWS.Credentials.Chain import Chain
credentials = Chain().credentials()
# Or import the module, as in Google Python Style Guide
import Pyjo.AWS.Config
import Pyjo.AWS.Credentials.Chain
import Pyjo.AWS.Credentials.Environment
import Pyjo.AWS.Credentials.Profile
chain = Pyjo.AWS.Credentials.Chain.new(config=Pyjo.AWS.Config.new(profile='dev'))
chain.credentials_p().then(lambda credentials: print(credentials.provider)).wait()
chain = Pyjo.AWS.Credentials.Chain.new(
providers=[Pyjo.AWS.Credentials.Environment.new(), Pyjo.AWS.Credentials.Profile.new()]
)
Pyjo.AWS.Credentials.Chain is the provider of the credentials of the
first of its providers that has them, in the order of the SDKs of AWS by
default:
the environment, of
Pyjo.AWS.Credentials.Environment,the role of a web identity of the environment, of
Pyjo.AWS.Credentials.WebIdentity,the profile of the shared files, of
Pyjo.AWS.Credentials.Profile, with its role, its SSO, its keys, its session ofaws loginor itscredential_process,the container of ECS or EKS Pod Identity, of
Pyjo.AWS.Credentials.Container,the instance metadata of EC2, of
Pyjo.AWS.Credentials.InstanceMetadata.
A profile of Pyjo.AWS.Config of the argument profile, as of the
option --profile of the AWS CLI, skips the first two, so that the keys of
AWS_ACCESS_KEY_ID and the role of AWS_ROLE_ARN of the environment do
not come over the profile, as botocore has it, whose AWS_PROFILE alone
does not:
# The session of aws login of the profile, with AWS_ACCESS_KEY_ID of the environment too
chain = Pyjo.AWS.Credentials.Chain.new(config=Pyjo.AWS.Config.new(profile='console'))
A provider that is not configured passes on to the next one, and the error of one that is configured ends the chain, as the SDKs of AWS do, so that a broken profile is not hidden by other credentials.
See also¶
Pyjo.AWS.Credentials.Provider, Pyjo.AWS.Credentials,
https://docs.aws.amazon.com/sdkref/latest/guide/standardized-credentials.html.
Classes¶
- class Pyjo.AWS.Credentials.Chain.Pyjo_AWS_Credentials_Chain(*, providers: Sequence[Pyjo_AWS_Credentials_Provider] | None = None, config: Pyjo_AWS_Config | None = None, **kwargs: Any)[source]¶
Pyjo.AWS.Credentials.Chaininherits all attributes and methods fromPyjo.AWS.Credentials.Providerand implements the following new ones.- __init__(*, providers: Sequence[Pyjo_AWS_Credentials_Provider] | None = None, config: Pyjo_AWS_Config | None = None, **kwargs: Any) None[source]¶
chain = Pyjo.AWS.Credentials.Chain.new() chain = Pyjo.AWS.Credentials.Chain.new(config=Pyjo.AWS.Config.new(profile='dev')) chain = Pyjo.AWS.Credentials.Chain.new(providers=[Pyjo.AWS.Credentials.Environment.new()])
Construct a new
Pyjo.AWS.Credentials.Chainobject, with the options ofPyjo.AWS.Credentials.Provider, and the providers of the SDKs of AWS, with the shared files ofconfig, by default.
- config¶
config = chain.config
The shared files of the default providers, a new
Pyjo.AWS.Configobject by default.
- default_providers() list[Pyjo_AWS_Credentials_Provider][source]¶
providers = chain.default_providers()
New providers of the SDKs of AWS, with
configand the user agent of the chain, in their order, but the container and the instance metadata, which have user agents of their own, with short timeouts, and without the environment and the web identity of the environment for anexplicit_profile.
- async fetch() Pyjo_AWS_Credentials | None[source]¶
credentials = await chain.fetch()
The credentials of the first provider that has them, or
None.
- providers: list[Pyjo_AWS_Credentials_Provider]¶
providers = chain.providers chain.providers.append(Pyjo.AWS.Credentials.Process.new(command='/opt/bin/credentials'))
The providers, in their order.