runway.aws_sso_botocore.session module

Botocore with support for AWS SSO session assets.

class runway.aws_sso_botocore.session.Session(session_vars=None, event_hooks=None, include_builtin_handlers=True, profile=None)[source]

Bases: botocore.session.Session

Extends the botocore session to support AWS SSO.

Create a new Session object.

Parameters
  • session_vars (dict) – A dictionary that is used to override some or all of the environment variables associated with this session. The key/value pairs defined in this dictionary will override the corresponding variables defined in SESSION_VARIABLES.

  • event_hooks (BaseEventHooks) – The event hooks object to use. If one is not provided, an event hooks object will be automatically created for you.

  • include_builtin_handlers (bool) – Indicates whether or not to automatically register builtin handlers.

  • profile (str) – The name of the profile to use for this session. Note that the profile can only be set when the session is created.

create_client(service_name, region_name=None, api_version=None, use_ssl=True, verify=None, endpoint_url=None, aws_access_key_id=None, aws_secret_access_key=None, aws_session_token=None, config=None)[source]

Create a botocore client.

Parameters
  • service_name (string) – The name of the service for which a client will be created. You can use the Sesssion.get_available_services() method to get a list of all available service names.

  • region_name (string) – The name of the region associated with the client. A client is associated with a single region.

  • api_version (string) – The API version to use. By default, botocore will use the latest API version when creating a client. You only need to specify this parameter if you want to use a previous API version of the client.

  • use_ssl (boolean) – Whether or not to use SSL. By default, SSL is used. Note that not all services support non-ssl connections.

  • verify (boolean/string) –

    Whether or not to verify SSL certificates. By default SSL certificates are verified. You can provide the following values:

    • False - do not validate SSL certificates. SSL will still be used (unless use_ssl is False), but SSL certificates will not be verified.

    • path/to/cert/bundle.pem - A filename of the CA cert bundle to uses. You can specify this argument if you want to use a different CA cert bundle than the one used by botocore.

  • endpoint_url (string) – The complete URL to use for the constructed client. Normally, botocore will automatically construct the appropriate URL to use when communicating with a service. You can specify a complete URL (including the “http/https” scheme) to override this behavior. If this value is provided, then use_ssl is ignored.

  • aws_access_key_id (string) – The access key to use when creating the client. This is entirely optional, and if not provided, the credentials configured for the session will automatically be used. You only need to provide this argument if you want to override the credentials used for this specific client.

  • aws_secret_access_key (string) – The secret key to use when creating the client. Same semantics as aws_access_key_id above.

  • aws_session_token (string) – The session token to use when creating the client. Same semantics as aws_access_key_id above.

  • config (botocore.client.Config) – Advanced client configuration options. If a value is specified in the client config, its value will take precedence over environment variables and configuration values, but not over a value passed explicitly to the method. If a default config object is set on the session, the config object used when creating the client will be the result of calling merge() on the default config with the config provided to this call.

Return type

botocore.client.BaseClient

Returns

A botocore client instance

property full_config

Return the parsed config file.

The get_config method returns the config associated with the specified profile. This property returns the contents of the entire config file.

Return type

dict

get_available_partitions()[source]

Lists the available partitions found on disk

Return type

list

Returns

Returns a list of partition names (e.g., [“aws”, “aws-cn”])

get_available_regions(service_name, partition_name='aws', allow_non_regional=False)[source]

Lists the region and endpoint names of a particular partition.

Parameters
  • service_name (string) – Name of a service to list endpoint for (e.g., s3). This parameter accepts a service name (e.g., “elb”) or endpoint prefix (e.g., “elasticloadbalancing”).

  • partition_name (string) – Name of the partition to limit endpoints to. (e.g., aws for the public AWS endpoints, aws-cn for AWS China endpoints, aws-us-gov for AWS GovCloud (US) Endpoints, etc.

  • allow_non_regional (bool) – Set to True to include endpoints that are not regional endpoints (e.g., s3-external-1, fips-us-gov-west-1, etc).

Returns

Returns a list of endpoint names (e.g., [“us-east-1”]).

get_available_services()[source]

Return a list of names of available services.

get_credentials()[source]

Return the botocore.credential.Credential object associated with this session. If the credentials have not yet been loaded, this will attempt to load them. If they have already been loaded, this will return the cached credentials.

get_data(data_path)[source]

Retrieve the data associated with data_path.

Parameters

data_path (str) – The path to the data you wish to retrieve.

get_default_client_config()[source]

Retrieves the default config for creating clients

Return type

botocore.client.Config

Returns

The default client config object when creating clients. If the value is None then there is no default config object attached to the session.

get_scoped_config()[source]

Returns the config values from the config file scoped to the current profile.

The configuration data is loaded only from the config file. It does not resolve variables based on different locations (e.g. first from the session instance, then from environment variables, then from the config file). If you want this lookup behavior, use the get_config_variable method instead.

Note that this configuration is specific to a single profile (the profile session variable).

If the profile session variable is set and the profile does not exist in the config file, a ProfileNotFound exception will be raised.

Raises

ConfigNotFound, ConfigParseError, ProfileNotFound

Return type

dict

get_service_data(service_name, api_version=None)[source]

Retrieve the fully merged data associated with a service.

get_service_model(service_name, api_version=None)[source]

Get the service model object.

Parameters
  • service_name (string) – The service name

  • api_version (string) – The API version of the service. If none is provided, then the latest API version will be used.

Return type

L{botocore.model.ServiceModel}

Returns

The botocore service model for the service.

register(event_name, handler, unique_id=None, unique_id_uses_count=False)[source]

Register a handler with an event.

Parameters
  • event_name (str) – The name of the event.

  • handler (callable) – The callback to invoke when the event is emitted. This object must be callable, and must accept **kwargs. If either of these preconditions are not met, a ValueError will be raised.

  • unique_id (str) – An optional identifier to associate with the registration. A unique_id can only be used once for the entire session registration (unless it is unregistered). This can be used to prevent an event handler from being registered twice.

  • unique_id_uses_count – boolean

  • unique_id_uses_count – Specifies if the event should maintain a count when a unique_id is registered and unregisted. The event can only be completely unregistered once every register call using the unique id has been matched by an unregister call. If unique_id is specified, subsequent register calls must use the same value for unique_id_uses_count as the register call that first registered the event.

Raises

ValueError – If the call to register uses unique_id but the value for unique_id_uses_count differs from the unique_id_uses_count value declared by the very first register call for that unique_id.

set_config_variable(logical_name, value)[source]

Set a configuration variable to a specific value.

By using this method, you can override the normal lookup process used in get_config_variable by explicitly setting a value. Subsequent calls to get_config_variable will use the value. This gives you per-session specific configuration values.

::
>>> # Assume logical name 'foo' maps to env var 'FOO'
>>> os.environ['FOO'] = 'myvalue'
>>> s.get_config_variable('foo')
'myvalue'
>>> s.set_config_variable('foo', 'othervalue')
>>> s.get_config_variable('foo')
'othervalue'
Parameters
  • logical_name (str) – The logical name of the session variable you want to set. These are the keys in SESSION_VARIABLES.

  • value – The value to associate with the config variable.

set_credentials(access_key, secret_key, token=None)[source]

Manually create credentials for this session. If you would prefer to use botocore without a config file, environment variables, or IAM roles, you can pass explicit credentials into this method to establish credentials for this session.

Parameters
  • access_key (str) – The access key part of the credentials.

  • secret_key (str) – The secret key part of the credentials.

  • token (str) – An option session token used by STS session credentials.

set_debug_logger(logger_name='botocore')[source]

Convenience function to quickly configure full debug output to go to the console.

set_default_client_config(client_config)[source]

Sets the default config for creating clients

Parameters

client_config (botocore.client.Config) – The default client config object when creating clients. If the value is None then there is no default config object attached to the session.

set_file_logger(log_level, path, logger_name='botocore')[source]

Convenience function to quickly configure any level of logging to a file.

Parameters
  • log_level (int) – A log level as specified in the logging module

  • path (string) – Path to the log file. The file will be created if it doesn’t already exist.

set_stream_logger(logger_name, log_level, stream=None, format_string=None)[source]

Convenience method to configure a stream logger.

Parameters
  • logger_name (str) – The name of the logger to configure

  • log_level (str) – The log level to set for the logger. This is any param supported by the .setLevel() method of a Log object.

  • stream (file) – A file like object to log to. If none is provided then sys.stderr will be used.

  • format_string (str) – The format string to use for the log formatter. If none is provided this will default to self.LOG_FORMAT.

unregister(event_name, handler=None, unique_id=None, unique_id_uses_count=False)[source]

Unregister a handler with an event.

Parameters
  • event_name (str) – The name of the event.

  • handler (callable) – The callback to unregister.

  • unique_id (str) – A unique identifier identifying the callback to unregister. You can provide either the handler or the unique_id, you do not have to provide both.

  • unique_id_uses_count – boolean

  • unique_id_uses_count – Specifies if the event should maintain a count when a unique_id is registered and unregisted. The event can only be completely unregistered once every register call using the unique_id has been matched by an unregister call. If the unique_id is specified, subsequent unregister calls must use the same value for unique_id_uses_count as the register call that first registered the event.

Raises

ValueError – If the call to unregister uses unique_id but the value for unique_id_uses_count differs from the unique_id_uses_count value declared by the very first register call for that unique_id.

user_agent()[source]

Return a string suitable for use as a User-Agent header. The string will be of the form:

<agent_name>/<agent_version> Python/<py_ver> <plat_name>/<plat_ver> <exec_env>

Where:

  • agent_name is the value of the user_agent_name attribute of the session object (Botocore by default).

  • agent_version is the value of the user_agent_version attribute of the session object (the botocore version by default). by default.

  • py_ver is the version of the Python interpreter beng used.

  • plat_name is the name of the platform (e.g. Darwin)

  • plat_ver is the version of the platform

  • exec_env is exec-env/$AWS_EXECUTION_ENV

If user_agent_extra is not empty, then this value will be appended to the end of the user agent string.