boto3.session

Module Contents

class Session(aws_access_key_id=None, aws_secret_access_key=None, aws_session_token=None, region_name=None, botocore_session=None, profile_name=None)

Bases:object

A session stores configuration state and allows you to create service clients and resources.

Parameters:
  • aws_access_key_id (string) – AWS access key ID
  • aws_secret_access_key (string) – AWS secret access key
  • aws_session_token (string) – AWS temporary session token
  • region_name (string) – Default region when creating new connections
  • botocore_session (botocore.session.Session) – Use this Botocore session instead of creating a new default one.
  • profile_name (string) – The name of a profile to use. If not given, then the default profile is used.
profile_name

The read-only profile name.

region_name

The read-only region name.

events

The event emitter for a session

available_profiles

The profiles available to the session credentials

__repr__(self)
_setup_loader(self)

Setup loader paths so that we can load resources.

get_available_services(self)

Get a list of available services that can be loaded as low-level clients via Session.client().

Return type:list
Returns:List of service names
get_available_resources(self)

Get a list of available services that can be loaded as resource clients via Session.resource().

Return type:list
Returns:List of service names
get_available_partitions(self)

Lists the available partitions

Return type:list
Returns:Returns a list of partition names (e.g., [“aws”, “aws-cn”])
get_available_regions(self, service_name, partition_name='aws', allow_non_regional=False)

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).
  • 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_credentials(self)

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.

client(self, 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)

Create a low-level service client by name.

Parameters:
  • service_name (string) – The name of a service, e.g. ‘s3’ or ‘ec2’. You can get a list of available services via get_available_services().
  • 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 region_name is specified in the client config, its value will take precedence over environment variables and configuration values, but not over a region_name value passed explicitly to the method. See botocore config documentation for more details.
Returns:

Service client instance

resource(self, 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)

Create a resource service client by name.

Parameters:
  • service_name (string) – The name of a service, e.g. ‘s3’ or ‘ec2’. You can get a list of available services via get_available_resources().
  • 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 region_name is specified in the client config, its value will take precedence over environment variables and configuration values, but not over a region_name value passed explicitly to the method. If user_agent_extra is specified in the client config, it overrides the default user_agent_extra provided by the resource API. See botocore config documentation for more details.

Returns:

Subclass of ServiceResource

_register_default_handlers(self)