Pyjo.AWS.Credentials.InstanceMetadata - Credentials of the instance metadata of EC2¶
from Pyjo.AWS.Credentials.InstanceMetadata import InstanceMetadata
credentials = InstanceMetadata().credentials()
# Or import the module, as in Google Python Style Guide
import Pyjo.AWS.Credentials.InstanceMetadata
provider = Pyjo.AWS.Credentials.InstanceMetadata.new(timeout=2, attempts=3)
provider.credentials_p().then(lambda credentials: print(credentials.expiration)).wait()
Pyjo.AWS.Credentials.InstanceMetadata is the provider of the
credentials of the role of the instance profile of an instance of EC2, of
its instance metadata service, with a token of IMDSv2, or without one of
IMDSv1, where the service has no tokens, unless
AWS_EC2_METADATA_V1_DISABLED or ec2_metadata_v1_disabled of the
profile is true.
The service is the one of AWS_EC2_METADATA_SERVICE_ENDPOINT or
ec2_metadata_service_endpoint, or http://169.254.169.254, or
http://[fd00:ec2::254] of AWS_EC2_METADATA_SERVICE_ENDPOINT_MODE or
ec2_metadata_service_endpoint_mode IPv6, with the timeout of
AWS_METADATA_SERVICE_TIMEOUT or metadata_service_timeout, 1 second by
default, and the attempts of AWS_METADATA_SERVICE_NUM_ATTEMPTS or
metadata_service_num_attempts, 1 by default, as a machine that is not an
instance of EC2 has no service, which the provider waits for that long. The
AWS_EC2_METADATA_DISABLED environment variable true turns it off.
A service that does not answer, or answers without a role, has no
credentials, as the SDKs of AWS have it, so that
Pyjo.AWS.Credentials.Chain ends without them; the credentials of a
role that the service does not give are an error.
See also¶
Pyjo.AWS.Credentials.Provider, Pyjo.AWS.Credentials.Chain,
https://docs.aws.amazon.com/sdkref/latest/guide/feature-imds-credentials.html.
Classes¶
- Pyjo.AWS.Credentials.InstanceMetadata.ENDPOINT = 'http://169.254.169.254'¶
The service of IPv4.
- Pyjo.AWS.Credentials.InstanceMetadata.ENDPOINT_IPV6 = 'http://[fd00:ec2::254]'¶
The service of IPv6.
- class Pyjo.AWS.Credentials.InstanceMetadata.Pyjo_AWS_Credentials_InstanceMetadata(*, endpoint: str | None = None, timeout: float | None = None, attempts: int | None = None, config: Pyjo_AWS_Config | None = None, ua: Pyjo_UserAgent | None = None, **kwargs: Any)[source]¶
Pyjo.AWS.Credentials.InstanceMetadatainherits all attributes and methods fromPyjo.AWS.Credentials.Providerand implements the following new ones.- __init__(*, endpoint: str | None = None, timeout: float | None = None, attempts: int | None = None, config: Pyjo_AWS_Config | None = None, ua: Pyjo_UserAgent | None = None, **kwargs: Any) None[source]¶
provider = Pyjo.AWS.Credentials.InstanceMetadata.new() provider = Pyjo.AWS.Credentials.InstanceMetadata.new(endpoint='http://[fd00:ec2::254]', timeout=2)
Construct a new
Pyjo.AWS.Credentials.InstanceMetadataobject, with the options ofPyjo.AWS.Credentials.Provider, and those of the environment and of the profile ofconfigby default.
- attempts¶
attempts = provider.attempts
The number of the attempts of a request that fails, of the
AWS_METADATA_SERVICE_NUM_ATTEMPTSenvironment variable ormetadata_service_num_attemptsof the profile, or 1.
- config¶
config = provider.config
The shared files of the settings, a new
Pyjo.AWS.Configobject by default.
- disabled¶
boolean = provider.disabled
Whether the provider is turned off, of the
AWS_EC2_METADATA_DISABLEDenvironment variabletrue.
- endpoint¶
url = provider.endpoint
The URL of the service, of the
AWS_EC2_METADATA_SERVICE_ENDPOINTenvironment variable orec2_metadata_service_endpointof the profile, or of IPv4 or of IPv6 of the mode.
- async fetch() Pyjo_AWS_Credentials | None[source]¶
credentials = await provider.fetch()
The credentials of the role of the instance, or
Nonewithout the service or a role.
- timeout¶
seconds = provider.timeout
The timeout of the service, of the
AWS_METADATA_SERVICE_TIMEOUTenvironment variable ormetadata_service_timeoutof the profile, or 1 second, of a newuaof the provider, which keeps no connections, as the credentials come once an hour.
- v1_disabled¶
boolean = provider.v1_disabled
Whether IMDSv1 without a token is turned off, of the
AWS_EC2_METADATA_V1_DISABLEDenvironment variable orec2_metadata_v1_disabledof the profiletrue.
- Pyjo.AWS.Credentials.InstanceMetadata.TTL = 21600¶
The seconds of a token of IMDSv2, 6 hours, as the SDKs of AWS ask for.