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(cloud_name='aws', account_id='111111111111', region='eu-west-2', service='iam', resource_type='vpc', resource_id_parts=['vpc-11111111'])
- class PartialUrn(cloud_name=None, account_id=None, region=None, service=None, resource_type=None, resource_id_parts=None)
A partially specified URN.
Useful for matching unknown or multiple URNs.
- Parameters
- Return type
- property cloud_service_resource_label: str
Return the cloud service resource label (e.g.
aws_iam_role
).- Raises
ValueError – If we do not have sufficient information to generate a label
- static escape_id(unescaped_id)
Return an escaped ID with the forward slashes escaped.
- class URN(account_id, region, service, resource_type, resource_id_parts=None, cloud_name=None)
A dataclass for building and querying AWS URNs.
- Parameters
- Return type
- __init__(account_id, region, service, resource_type, 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_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
- 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'
)
- 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
- Raises
ValueError – When no valid resource id found