boto3.resources.factory

Module Contents

logger
class ResourceFactory(emitter)

Bases:object

A factory to create new ServiceResource classes from a ResourceModel. There are two types of lookups that can be done: one on the service itself (e.g. an SQS resource) and another on models contained within the service (e.g. an SQS Queue resource).

load_from_definition(self, resource_name, single_resource_json_definition, service_context)

Loads a resource from a model, creating a new ServiceResource subclass with the correct properties and methods, named based on the service and resource name, e.g. EC2.Instance.

Parameters:
  • resource_name (string) – Name of the resource to look up. For services, this should match the service_name.
  • single_resource_json_definition (dict) – The loaded json of a single service resource or resource definition.
  • service_context (ServiceContext) – Context about the AWS service
Return type:

Subclass of ServiceResource

Returns:

The service or resource class.

_load_identifiers(self, attrs, meta, resource_model, resource_name)

Populate required identifiers. These are arguments without which the resource cannot be used. Identifiers become arguments for operations on the resource.

_load_actions(self, attrs, resource_name, resource_model, service_context)

Actions on the resource become methods, with the load method being a special case which sets internal data for attributes, and reload is an alias for load.

_load_attributes(self, attrs, meta, resource_name, resource_model, service_context)

Load resource attributes based on the resource shape. The shape name is referenced in the resource JSON, but the shape itself is defined in the Botocore service JSON, hence the need for access to the service_model.

_load_collections(self, attrs, resource_model, service_context)

Load resource collections from the model. Each collection becomes a CollectionManager instance on the resource instance, which allows you to iterate and filter through the collection’s items.

_load_has_relations(self, attrs, resource_name, resource_model, service_context)

Load related resources, which are defined via a has relationship but conceptually come in two forms:

  1. A reference, which is a related resource instance and can be None, such as an EC2 instance’s vpc.
  2. A subresource, which is a resource constructor that will always return a resource instance which shares identifiers/data with this resource, such as s3.Bucket('name').Object('key').
_create_available_subresources_command(self, attrs, subresources)
_load_waiters(self, attrs, resource_name, resource_model, service_context)

Load resource waiters from the model. Each waiter allows you to wait until a resource reaches a specific state by polling the state of the resource.

_create_identifier(factory_self, identifier, resource_name)

Creates a read-only property for identifier attributes.

_create_identifier_alias(factory_self, resource_name, identifier, member_model, service_context)

Creates a read-only property that aliases an identifier.

_create_autoload_property(factory_self, resource_name, name, snake_cased, member_model, service_context)

Creates a new property on the resource to lazy-load its value via the resource’s load method (if it exists).

_create_waiter(factory_self, resource_waiter_model, resource_name, service_context)

Creates a new wait method for each resource where both a waiter and resource model is defined.

_create_collection(factory_self, resource_name, collection_model, service_context)

Creates a new property on the resource to lazy-load a collection.

_create_reference(factory_self, reference_model, resource_name, service_context)

Creates a new property on the resource to lazy-load a reference.

_create_class_partial(factory_self, subresource_model, resource_name, service_context)

Creates a new method which acts as a functools.partial, passing along the instance’s low-level client to the new resource class’ constructor.

_create_action(factory_self, action_model, resource_name, service_context, is_load=False)

Creates a new method which makes a request to the underlying AWS service.