Pyjo.AWS.Client - Client of an API of AWS

from Pyjo.AWS.Client import Client
from Pyjo.AWS.Protocol.Query import Query
from Pyjo.AWS.Protocol.RestJSON import RestJSON

sts = Client(service='sts')
print(sts.call(Query('GetCallerIdentity', version='2011-06-15')).at('Arn').text)

# Or import the module, as in Google Python Style Guide

import Pyjo.AWS.Client
import Pyjo.AWS.Config
import Pyjo.AWS.Protocol.RestJSON

lambda_ = Pyjo.AWS.Client.new(service='lambda', config=Pyjo.AWS.Config.new(profile='dev'))
call = Pyjo.AWS.Protocol.RestJSON.new('GET', '/2018-10-31/layers')
lambda_.call_p(call).then(lambda layers: print(layers['Layers'])).wait()

Pyjo.AWS.Client calls an API of AWS, of a service in a region, with the calls of Pyjo.AWS.Protocol: it signs the request of a call with the credentials of Pyjo.AWS.Credentials, which Pyjo.AWS.Credentials.Chain finds by default, as the SDKs of AWS do, starts it with Pyjo.UserAgent, blocking or non-blocking, and gives the result of its response, or raises the Pyjo.AWS.Error that AWS responds with.

The endpoint of the service is the one that the environment or the profile of Pyjo.AWS.Config configures, as endpoint_url() resolves it, or the regional one of AWS, as https://sts.eu-central-1.amazonaws.com, of amazonaws.com.cn in the regions of China. A service with a global endpoint, as IAM, takes it as endpoint.

iam = Pyjo.AWS.Client.new(service='iam', endpoint='https://iam.amazonaws.com', region='us-east-1')

A provider of credentials calls an API of AWS with steps(), which Pyjo.Steps runs with its own steps, as a role of STS with the credentials of its source:

async def fetch(self):
    source = await self.source.steps()
    dom = await sts.steps(Query('AssumeRole', {...}, version='2011-06-15'), source)

See also

Pyjo.AWS.Protocol, Pyjo.AWS.Error, Pyjo.AWS.SigV4, Pyjo.AWS.Credentials, https://docs.aws.amazon.com/sdkref/latest/guide/feature-ss-endpoints.html.

Classes

class Pyjo.AWS.Client.Pyjo_AWS_Client(*, service: str, region: str | None = None, endpoint: str | None = None, endpoint_prefix: str | None = None, service_id: str | None = None, config: Pyjo_AWS_Config | None = None, credentials: Pyjo_AWS_Credentials_Provider | None = None, unsigned: bool = False, ua: Pyjo_UserAgent | None = None)[source]

Pyjo.AWS.Client inherits all attributes and methods from Pyjo.Base and implements the following new ones.

__init__(*, service: str, region: str | None = None, endpoint: str | None = None, endpoint_prefix: str | None = None, service_id: str | None = None, config: Pyjo_AWS_Config | None = None, credentials: Pyjo_AWS_Credentials_Provider | None = None, unsigned: bool = False, ua: Pyjo_UserAgent | None = None) → None[source]
client = Pyjo.AWS.Client.new(service='sts')
client = Pyjo.AWS.Client.new(service='lambda', region='eu-central-1',
                             config=Pyjo.AWS.Config.new(profile='dev'))
client = Pyjo.AWS.Client.new(service='awsssoportal', endpoint_prefix='portal.sso', service_id='SSO',
                             unsigned=True)

Construct a new Pyjo.AWS.Client object.

__weakref__

list of weak references to the object

call(call: Pyjo_AWS_Protocol) → T[source]
result = client.call(Pyjo.AWS.Protocol.Query.new('GetCallerIdentity', version='2011-06-15'))

Call an operation, blocking, and give its result, or raise its Pyjo.AWS.Error.

call_p(call: Pyjo_AWS_Protocol[Any]) → Pyjo_Promise[source]
promise = client.call_p(Pyjo.AWS.Protocol.Query.new('GetCallerIdentity', version='2011-06-15'))

Same as call(), but non-blocking, and returns a Pyjo.Promise object. The credentials come of credentials_p(), so that the calls while the provider gets them wait for them once.

config
config = client.config

The shared files of the region, the endpoint and the default credentials, a new Pyjo.AWS.Config object by default.

credentials: Pyjo_AWS_Credentials_Provider
provider = client.credentials

The provider of the credentials, a new Pyjo.AWS.Credentials.Chain object of config by default.

endpoint
url = client.endpoint
client.endpoint = 'http://127.0.0.1:4566'

The URL of the endpoint, which comes over the configured and the regional one, or None.

endpoint_prefix
prefix = client.endpoint_prefix

The prefix of the regional endpoint, as portal.sso of SSO, service by default.

endpoint_url() → str[source]
url = client.endpoint_url()

The URL of the endpoint, endpoint, the configured one, or the regional one, which needs a region.

region
region = client.region
client.region = 'eu-central-1'

The region of the service, of region() of config by default, or None, which a call raises an error of.

service
service = client.service

The name of the service in the signature, as sts or lambda, which is the prefix of its endpoint and its ID by default.

service_id
service_id = client.service_id

The ID of the service, whose endpoint the environment and the profile configure, as SSO OIDC, service by default.

signer(credentials: Pyjo_AWS_Credentials) → Pyjo_AWS_SigV4[source]
signer = client.signer(credentials)

A new Pyjo.AWS.SigV4 object of the service and the region with credentials, which signs the path of S3 as it is, with the hash of its body.

steps(call: Pyjo_AWS_Protocol, credentials: Pyjo_AWS_Credentials | None = None) → Pyjo_Steps[source]
result = await client.steps(call)
result = await client.steps(call, credentials)

The Pyjo.Steps of a call, of a provider of credentials, with credentials, or those of credentials by default.

ua
ua = client.ua

The user agent of the requests, a new Pyjo.UserAgent object by default, whose event start signs each request.

unsigned
boolean = client.unsigned

Send the requests without a signature, false by default, as those of SSO and SSO OIDC, which have a token of their own.