The models defined in this file represent the resource JSON description format and provide a layer of abstraction from the raw JSON. The advantages of this are:
action.request.operation
)These models are used both by the resource factory to generate resource classes as well as by the documentation generator.
boto3.resources.model.
Action
(name, definition, resource_defs)[source]¶A service operation action.
boto3.resources.model.
Collection
(name, definition, resource_defs)[source]¶A group of resources. See Action
.
boto3.resources.model.
DefinitionWithParams
(definition)[source]¶An item which has parameters exposed via the params
property.
A request has an operation and parameters, while a waiter has
a name, a low-level waiter name and parameters.
boto3.resources.model.
Identifier
(name, member_name=None)[source]¶A resource identifier, given by its name.
boto3.resources.model.
Parameter
(target, source, name=None, path=None, value=None, **kwargs)[source]¶An auto-filled parameter which has a source and target. For example,
the QueueUrl
may be auto-filled from a resource's url
identifier
when making calls to queue.receive_messages
.
QueueUrl
Url
boto3.resources.model.
Request
(definition)[source]¶A service operation action request.
boto3.resources.model.
ResourceModel
(name, definition, resource_defs)[source]¶A model representing a resource, defined via a JSON description format. A resource has identifiers, attributes, actions, sub-resources, references and collections. For more information on resources, see Resources.
sqs
or Queue
collections
¶Get a list of collections for this resource.
Collection
)get_attributes
(shape)[source]¶Get a dictionary of attribute names to original name and shape models that represent the attributes of this resource. Looks like the following:
- {
- 'some_name': ('SomeName', <Shape...>)
}
identifiers
¶Get a list of resource identifiers.
Identifier
)load_rename_map
(shape=None)[source]¶Load a name translation map given a shape. This will set
up renamed values for any collisions, e.g. if the shape,
an action, and a subresource all are all named foo
then the resource will have an action foo
, a subresource
named Foo
and a property named foo_attribute
.
This is the order of precedence, from most important to
least important:
Batch actions are only exposed on collections, so do not get modified here. Subresources use upper camel casing, so are unlikely to collide with anything but other subresources.
Creates a structure like this:
renames = {
('action', 'id'): 'id_action',
('collection', 'id'): 'id_collection',
('attribute', 'id'): 'id_attribute'
}
# Get the final name for an action named 'id'
name = renames.get(('action', 'id'), 'id')
boto3.resources.model.
ResponseResource
(definition, resource_defs)[source]¶A resource response to create after performing an action.
identifiers
¶A list of resource identifiers.
Identifier
)model
¶Get the resource model for the response resource.
ResourceModel
boto3.resources.params.
build_param_structure
(params, target, value, index=None)[source]¶This method provides a basic reverse JMESPath implementation that
lets you go from a JMESPath-like string to a possibly deeply nested
object. The params
are mutated in-place, so subsequent calls
can modify the same element by its index.
>>> build_param_structure(params, 'test[0]', 1)
>>> print(params)
{'test': [1]}
>>> build_param_structure(params, 'foo.bar[0].baz', 'hello world')
>>> print(params)
{'test': [1], 'foo': {'bar': [{'baz': 'hello, world'}]}}
boto3.resources.params.
create_request_parameters
(parent, request_model, params=None, index=None)[source]¶Handle request parameters that can be filled in from identifiers, resource data members or constants.
By passing params
, you can invoke this method multiple times and
build up a parameter dict over time, which is particularly useful
for reverse JMESPath expressions that append to lists.
Request
) -- The action request model.dict
Pre-filled parameters to be sent to the request operation.
boto3.resources.params.
get_data_member
(parent, path)[source]¶Get a data member from a parent using a JMESPath search query, loading the parent if required. If the parent cannot be loaded and no data is present then an exception is raised.
When no data is present and the resource cannot be loaded.
The queried data or None
.
boto3.resources.response.
RawHandler
(search_path)[source]¶A raw action response handler. This passed through the response dictionary, optionally after performing a JMESPath search if one has been defined for the action.
boto3.resources.response.
ResourceHandler
(search_path, factory, resource_model, service_context, operation_name=None)[source]¶Creates a new resource or list of new resources from the low-level response based on the given response resource definition.
ResponseResource
) -- Response resource model.ServiceContext
) -- Context about the AWS serviceServiceResource or list
New resource instance(s).
handle_response_item
(resource_cls, parent, identifiers, resource_data)[source]¶Handles the creation of a single response item by setting parameters and creating the appropriate resource instance.
New resource instance.
boto3.resources.response.
all_not_none
(iterable)[source]¶Return True if all elements of the iterable are not None (or if the
iterable is empty). This is like the built-in all
, except checks
against None, so 0 and False are allowable values.
boto3.resources.response.
build_empty_response
(search_path, operation_name, service_model)[source]¶Creates an appropriate empty response for the type that is expected, based on the service model's shape type. For example, a value that is normally a list would then return an empty list. A structure would return an empty dict, and a number would return None.
dict, list, or None
An appropriate empty value
boto3.resources.response.
build_identifiers
(identifiers, parent, params=None, raw_response=None)[source]¶Builds a mapping of identifier names to values based on the identifier source location, type, and target. Identifier values may be scalars or lists depending on the source type and location.
Parameter
definitionslist
An ordered list of (name, value)
identifier tuples.
boto3.resources.action.
BatchAction
(action_model, factory=None, service_context=None)[source]¶An action which operates on a batch of items in a collection, typically
a single page of results from the collection's underlying service
operation call. For example, this allows you to delete up to 999
S3 objects in a single operation rather than calling .delete()
on
each one individually.
ServiceContext
) -- Context about the AWS serviceboto3.resources.action.
CustomModeledAction
(action_name, action_model, function, event_emitter)[source]¶A custom, modeled action to inject into a resource.
botocore.hooks.BaseEventHooks
) -- The session event emitter.boto3.resources.action.
ServiceAction
(action_model, factory=None, service_context=None)[source]¶A class representing a callable action on a resource, for example
sqs.get_queue_by_name(...)
or s3.Bucket('foo').delete()
.
The action may construct parameters from existing resource identifiers
and may return either a raw response or a new resource instance.
ServiceContext
) -- Context about the AWS serviceboto3.resources.action.
WaiterAction
(waiter_model, waiter_resource_name)[source]¶A class representing a callable waiter action on a resource, for example
s3.Bucket('foo').wait_until_bucket_exists()
.
The waiter action may construct parameters from existing resource
identifiers.
wait_until_
boto3.resources.factory.
ResourceFactory
(emitter)[source]¶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
(resource_name, single_resource_json_definition, service_context)[source]¶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.
service_name
.ServiceContext
) -- Context about the AWS serviceSubclass of ServiceResource
The service or resource class.