Service Mappings¶
Provides a way to map resources back to the regions they reside in as well as expose other metadata.
In some cases we need to perform additional API calls to discover the region in which a resource resides.
The most well-known example of this is s3 buckets which require an additional API call to get their region.
When a resource is passed in that doesn’t have a Global Service Mapping,
the Session
’s region is used.
Additionally this is used to expose information about whether custom resources should be stored as secondary attributes or resources.
-
class
CloudWandererResourceMapping
(service_mapping, name, mapping, resource_definition, boto3_client)¶ CloudWanderer specific information about a boto3 resource.
-
__init__
(service_mapping, name, mapping, resource_definition, boto3_client)¶ Initialise the CloudWandererResourceMapping.
- Parameters
service_mapping (ServiceMapping) – The
ServiceMapping
for this resource.name (str) – The name of the resource
mapping (dict) – The resource’s cloudwanderer mapping data
resource_definition (dict) – The boto3 resource definition
boto3_client (botocore.client.ClientCreator) – The boto3 client for this resource
- Return type
None
-
get_region
(resource)¶ Return the resource passed in.
- Parameters
resource (boto3.resources.model.ResourceModel) – The
ResourceModel
to get the region for- Return type
str
-
property
has_secondary_attributes
¶ Return True if this resource has secondary attributes.
-
property
resource_type
¶ Return the resource type (e.g. Resource, SecondaryAttribute).
- Raises
AttributeError – Occurs if this resource’s mapping does not have a type.
-
property
secondary_attributes
¶ Return a list of secondary attributes for this resource.
-
-
exception
GlobalServiceResourceMappingNotFound
¶ Global Service Resource Mapping not Found.
-
class
ServiceMapping
(service_name, service_mapping, boto3_session=None)¶ Expose additional metadata about services and resources that isn’t supported in boto3’s model.
-
__init__
(service_name, service_mapping, boto3_session=None)¶ Instantiate the ServiceMapping.
- Parameters
service_name (str) – The name of the service mapping to instantiate.
service_mapping (dict) – The service mapping to instantiate.
boto3_session (boto3.session.Session) – The
Session
to use to query for resource region information.
- Return type
None
-
get_resource_mapping
(resource_type)¶ Get the resource mapping for resource_type.
- Parameters
resource_type (str) – The resource type in PascalCase (e.g.
'Vpc'
).- Raises
GlobalServiceResourceMappingNotFound – Occurs if theres no global resource mapping for this service.
- Return type
-
get_resource_region
(resource, default_region)¶ Get the region of a
boto3.resources.model.ResourceModel
object.- Parameters
resource (boto3.resources.model.ResourceModel) – The
ResourceModel
to find the region of.default_region (str) – The region to return if there is no gloabl service mapping for this resource type.
- Return type
str
-
property
global_service_region
¶ Return the primary region for this global service (if it not one, return None).
-
property
has_regional_resources
¶ Return
True
if this service has resources in regions other than the primary service region.Also returns True if there is no service_mapping (i.e. this is not a known service).
- Raises
AttributeError – Occurs if the service does not have a regionalResources key in its definition.
-
property
is_global_service
¶ Return whether this mapping is for a global service.
- Raises
AttributeError – Occurs if the service does not have globalService key in its definition.
-
property
resources
¶ Return a list of resources we have mappings for.
-
-
class
ServiceMappingCollection
(boto3_session=None)¶ Load and retrieve service mappings.
- Parameters
boto3_session (boto3.session.Session) – The
boto3.session.Session
object to use for any queries.
-
__init__
(boto3_session=None)¶ Load and retrieve service mappings.
- Parameters
boto3_session (boto3.session.Session) – The boto3 session to use to query additional resource information like region.
- Return type
str
-
get_service_mapping
(service_name)¶ Return the mapping for service_name.
- Parameters
service_name (str) – The name of the service (e.g.
'ec2'
)- Return type
-
get_service_maps
()¶ Return our custom resource definitions.
- Return type