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.InstanceMetadata inherits all attributes and methods from Pyjo.AWS.Credentials.Provider and 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.InstanceMetadata object, with the options of Pyjo.AWS.Credentials.Provider, and those of the environment and of the profile of config by default.

attempts
attempts = provider.attempts

The number of the attempts of a request that fails, of the AWS_METADATA_SERVICE_NUM_ATTEMPTS environment variable or metadata_service_num_attempts of the profile, or 1.

config
config = provider.config

The shared files of the settings, a new Pyjo.AWS.Config object by default.

disabled
boolean = provider.disabled

Whether the provider is turned off, of the AWS_EC2_METADATA_DISABLED environment variable true.

endpoint
url = provider.endpoint

The URL of the service, of the AWS_EC2_METADATA_SERVICE_ENDPOINT environment variable or ec2_metadata_service_endpoint of 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 None without the service or a role.

timeout
seconds = provider.timeout

The timeout of the service, of the AWS_METADATA_SERVICE_TIMEOUT environment variable or metadata_service_timeout of the profile, or 1 second, of a new ua of 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_DISABLED environment variable or ec2_metadata_v1_disabled of the profile true.

Pyjo.AWS.Credentials.InstanceMetadata.TTL = 21600

The seconds of a token of IMDSv2, 6 hours, as the SDKs of AWS ask for.