URNs

A dataclass for building and querying AWS URNs.

AWS URNs are a standardised string format (name borrowed from Pulumi) which provide all the information required to find a resource in AWS, whereas AWS ARNs do not always provide this information.

# Format
'urn:aws:<account_id>:<region>:<service>:<resource_type>:<resource_id>'
# e.g.
'urn:aws:111111111111:eu-west-2:iam:vpc:vpc-11111111'

Example

>>> from cloudwanderer import URN
>>> URN.from_string('urn:aws:111111111111:eu-west-2:iam:vpc:vpc-11111111')
URN(account_id='111111111111', region='eu-west-2', service='iam', resource_type='vpc', resource_id_parts=['vpc-11111111'])
class URN(account_id, region, service, resource_type, resource_id=None, resource_id_parts=None, cloud_name=None)

A dataclass for building and querying AWS URNs.

__init__(account_id, region, service, resource_type, resource_id=None, resource_id_parts=None, cloud_name=None)

Initialise an AWS Urn.

Parameters
  • account_id (str) – AWS Account ID (e.g. 111111111111).

  • region (str) – AWS region (e.g. us-east-1`).

  • service (str) – AWS Service (e.g. iam).

  • resource_type (str) – AWS Resource Type (e.g. role_policy)

  • resource_id (Optional[str]) – AWS Resource Id (e.g. test-role-policy)

  • resource_id_parts (Optional[list]) – AWS Resource Id (e.g. test-role-policy)

  • cloud_name (Optional[str]) – The name of the cloud this resource exists in (defaults to 'aws')

Return type

None

account_id

AWS Account ID (e.g. 111111111111).

region

AWS region (e.g. us-east-1`).

service

AWS Service (e.g. iam).

resource_type

AWS Resource Type (e.g. role_policy)

resource_id

AWS Resource Id (e.g. test-role-policy)

resource_id_parts

AWS Resource ID parts (e.g. ['test-role', 'test-role-policy'])

cloud_name

The name of the cloud this resource exists in (defaults to 'aws')

Raises

ValueError – If incorrect values are supplied.

Parameters
  • account_id (str) –

  • region (str) –

  • service (str) –

  • resource_type (str) –

  • resource_id (Optional[str]) –

  • resource_id_parts (Optional[list]) –

  • cloud_name (Optional[str]) –

Return type

None

static escape_id(unescaped_id)

Return an escaped ID with the forward slashes escaped.

Parameters

unescaped_id (Optional[str]) – The id to escape.

Return type

Optional[str]

classmethod from_string(urn_string)

Create an URN Object from an URN string.

Parameters

urn_string (str) – The string version of an AWSUrn to convert into an object.

Returns

The instantiated AWS URN.

Return type

URN

Raises

ValueError – When no valid resource id found

property resource_id_parts_parsed

Return the URNs ID parts parsed to their original types where possible.

static unescape_id(escaped_id)

Return an unescaped ID with the forward slashes unescaped.

Parameters

escaped_id (Optional[str]) – The id to unescape.

Return type

Optional[str]