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.

Parameters
  • name (str) – The name of the resource

  • mapping (dict) – The resource’s cloudwanderer mapping data

  • resource_definition (dict) – The boto3 resource definition

  • boto3_client – The boto3 client for this resource

get_region(resource)

Return the resource passed in.

Parameters

resource (boto3.resources.model.ResourceModel) – The boto3.resources.model.ResourceModel to get the region for

Return type

str

property has_secondary_attributes

Return True if this resource has secondary attributes.

property resource_type

The resource type (e.g. Resource, SecondaryAttribute).

property secondary_attributes

Returns 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.

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.

get_resource_mapping(resource_type)

Get the resource mapping for resource_type.

Parameters

resource_type (str) – The resource type in PascalCase (e.g. 'Vpc').

Return type

boto3.resources.model.ResourceModel

get_resource_region(resource, default_region)

Get the region of a boto3.resources.base.ServiceResource object.

Parameters
Return type

str

has_global_resources_in_region(region)

Return True if service has only resources and their primary endpoint is this region.

Parameters

region (str) –

Return type

bool

property has_regional_resources

Returns 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).

property is_global_service

Return whether this mapping is for a global service.

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.

get_service_mapping(service_name)

Returns the mapping for service_name.

Parameters

service_name (str) –

Return type

List[cloudwanderer.service_mappings.ServiceMapping]

get_service_maps()

Return our custom resource definitions.

Return type

List[cloudwanderer.service_mappings.ServiceMapping]