Skip to content

ArnUriHelper

Utility class for building AWS ARNs and URIs for various AWS services.

This helper provides a collection of static methods to construct properly formatted Amazon Resource Names (ARNs) and URIs for AWS services following AWS naming conventions. It includes both ARN builders for resource identification and URI builders for service-specific endpoints and console URLs.

All methods are static and can be called without instantiating the class. The class focuses on string formatting and does not perform AWS API calls.

Source code in mare_aws_common_lib/helpers/arn_uri_helper.py
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
class ArnUriHelper:
    """
    Utility class for building AWS ARNs and URIs for various AWS services.

    This helper provides a collection of static methods to construct properly formatted
    Amazon Resource Names (ARNs) and URIs for AWS services following AWS naming conventions.
    It includes both ARN builders for resource identification and URI builders for
    service-specific endpoints and console URLs.

    All methods are static and can be called without instantiating the class.
    The class focuses on string formatting and does not perform AWS API calls.
    """

    @staticmethod
    def build_ecr_repo_arn(app_helper: ApplicationHelper, repo_name: str, account_id: str = None) -> str:
        """
        Build an Amazon ECR repository ARN using application configuration.

        Constructs a fully qualified ECR repository ARN using region and account ID
        from the application helper configuration.

        Args:
            app_helper (ApplicationHelper): Helper instance containing region and account configuration
            repo_name (str): Name of the ECR repository
            account_id (str, optional): AWS account ID. If None, retrieves from app_helper environment

        Returns:
            str: Complete ECR repository ARN in the format:
                arn:aws:ecr:{region}:{account_id}:repository/{repo_name}
        """
        if account_id is None:
            account_id = app_helper.get_from_env("account_id")
        return f"arn:aws:ecr:{app_helper.get_from_common("region")}:{account_id}:repository/{repo_name}"

    @staticmethod
    def build_s3_bucket_arn(bucket_name: str) -> str:
        """
        Build an Amazon S3 bucket ARN.

        Constructs a properly formatted S3 bucket ARN using the bucket name.

        Args:
            bucket_name (str): Name of the S3 bucket

        Returns:
            str: Complete S3 bucket ARN in the format:
                arn:aws:s3:::{bucket_name}
        """
        return f"arn:aws:s3:::{bucket_name}"

    @staticmethod
    def build_s3_bucket_uri(bucket_name: str, folder: str = None) -> str:
        """
        Build an S3 URI for accessing bucket contents.

        Constructs an S3 URI that can be used with AWS CLI, SDKs, and other tools
        for accessing S3 objects. Optionally includes a folder path.

        Args:
            bucket_name (str): Name of the S3 bucket
            folder (str, optional): Folder path within the bucket. Defaults to None.

        Returns:
            str: S3 URI in the format:
                - s3://{bucket_name} (if no folder)
                - s3://{bucket_name}/{folder} (if folder specified)
        """
        uri = f"s3://{bucket_name}"
        if folder is not None:
            uri = f"{uri}/{folder}"
        return uri

    @staticmethod
    def build_alb_arn(region: str, account_id: str, alb_name: str) -> str:
        """
        Build an Application Load Balancer (ALB) ARN.

        Constructs a properly formatted ALB ARN for Elastic Load Balancing resources.

        Args:
            region (str): AWS region where the ALB is located
            account_id (str): AWS account ID
            alb_name (str): Name of the Application Load Balancer

        Returns:
            str: Complete ALB ARN in the format:
                arn:aws:elasticloadbalancing:{region}:{account_id}:loadbalancer/app/{alb_name}/{alb_name}
        """
        return f"arn:aws:elasticloadbalancing:{region}:{account_id}:loadbalancer/app/{alb_name}/{alb_name}"

    @staticmethod
    def build_kms_key_arn(region: str, account_id: str, key_id: str) -> str:
        """
        Build a KMS key ARN.

        Constructs a properly formatted KMS key ARN for encryption key resources.

        Args:
            region (str): AWS region where the KMS key is located
            account_id (str): AWS account ID
            key_id (str): KMS key ID (UUID format)

        Returns:
            str: Complete KMS key ARN in the format:
                arn:aws:kms:{region}:{account_id}:key/{key_id}
        """
        return f"arn:aws:kms:{region}:{account_id}:key/{key_id}"

    @staticmethod
    def build_secret_arn(region: str, account_id: str, secret_name: str) -> str:
        """
        Build a Secrets Manager secret ARN.

        Constructs a properly formatted Secrets Manager ARN for secret resources.

        Args:
            region (str): AWS region where the secret is stored
            account_id (str): AWS account ID
            secret_name (str): Name of the secret in Secrets Manager

        Returns:
            str: Complete Secrets Manager ARN in the format:
                arn:aws:secretsmanager:{region}:{account_id}:secret:{secret_name}
        """
        return f"arn:aws:secretsmanager:{region}:{account_id}:secret:{secret_name}"

    @staticmethod
    def build_pipeline_arn(region: str, account_id: str, pipeline_name: str) -> str:
        """
        Build a CodePipeline ARN.

        Constructs a properly formatted CodePipeline ARN for CI/CD pipeline resources.

        Args:
            region (str): AWS region where the pipeline is located
            account_id (str): AWS account ID
            pipeline_name (str): Name of the CodePipeline

        Returns:
            str: Complete CodePipeline ARN in the format:
                arn:aws:codepipeline:{region}:{account_id}:{pipeline_name}
        """
        return f"arn:aws:codepipeline:{region}:{account_id}:{pipeline_name}"

    @staticmethod
    def build_dynamodb_table_arn(region: str, account_id: str, table_name: str) -> str:
        """
        Build a DynamoDB table ARN.

        Constructs a properly formatted DynamoDB table ARN for NoSQL database resources.

        Args:
            region (str): AWS region where the DynamoDB table is located
            account_id (str): AWS account ID
            table_name (str): Name of the DynamoDB table

        Returns:
            str: Complete DynamoDB table ARN in the format:
                arn:aws:dynamodb:{region}:{account_id}:table/{table_name}
        """
        return f"arn:aws:dynamodb:{region}:{account_id}:table/{table_name}"

    @staticmethod
    def build_dynamodb_table_index_arn(region: str, account_id: str, table_name: str, index_name: str) -> str:
        """
        Build a DynamoDB table index ARN.

        Constructs a properly formatted DynamoDB table index ARN for Global Secondary Index (GSI)
        or Local Secondary Index (LSI) resources.

        Args:
            region (str): AWS region where the DynamoDB table is located
            account_id (str): AWS account ID
            table_name (str): Name of the DynamoDB table
            index_name (str): Name of the table index (GSI or LSI)

        Returns:
            str: Complete DynamoDB table index ARN in the format:
                arn:aws:dynamodb:{region}:{account_id}:table/{table_name}/index/{index_name}
        """
        return f"arn:aws:dynamodb:{region}:{account_id}:table/{table_name}/index/{index_name}"

    @staticmethod
    def build_sns_topic_arn(region: str, account_id: str, topic_name: str) -> str:
        """
        Build an SNS topic ARN.

        Constructs a properly formatted Simple Notification Service (SNS) topic ARN
        for messaging and notification resources.

        Args:
            region (str): AWS region where the SNS topic is located
            account_id (str): AWS account ID
            topic_name (str): Name of the SNS topic

        Returns:
            str: Complete SNS topic ARN in the format:
                arn:aws:sns:{region}:{account_id}:{topic_name}
        """
        return f"arn:aws:sns:{region}:{account_id}:{topic_name}"

    @staticmethod
    def get_ecr_repo_uri_from_arn(ecr_arn: str) -> str:
        """
        Extract ECR repository URI from an ECR ARN.

        Parses an ECR repository ARN and constructs the corresponding repository URI
        that can be used for Docker operations (push, pull, etc.).

        Args:
            ecr_arn (str): Complete ECR repository ARN

        Returns:
            str: ECR repository URI in the format:
                {account_id}.dkr.ecr.{region}.amazonaws.com/{repo_name}

        Raises:
            ValueError: If the provided ARN is not a valid ECR repository ARN format
        """
        region, account_id, repo_name = ArnUriHelper._parse_ecr_arn(ecr_arn)
        return f"{account_id}.dkr.ecr.{region}.amazonaws.com/{repo_name}"

    @staticmethod
    def get_ecr_repo_url_from_arn(ecr_arn: str) -> str:
        """
        Generate AWS Console URL for an ECR repository from its ARN.

        Parses an ECR repository ARN and constructs the corresponding AWS Console URL
        for viewing the repository in the web interface.

        Args:
            ecr_arn (str): Complete ECR repository ARN

        Returns:
            str: AWS Console URL for the ECR repository in the format:
                https://{region}.console.aws.amazon.com/ecr/repositories/private/{account_id}/{repo_name}

        Raises:
            ValueError: If the provided ARN is not a valid ECR repository ARN format
        """
        region, account_id, repo_name = ArnUriHelper._parse_ecr_arn(ecr_arn)
        return f"https://{region}.console.aws.amazon.com/ecr/repositories/private/{account_id}/{repo_name}"

    @staticmethod
    def get_ecr_registry_uri_from_arn(ecr_arn: str) -> str:
        """
        Extract ECR registry URI from an ECR repository ARN.

        Parses an ECR repository ARN and constructs the registry URI (without repository name)
        that can be used for Docker login operations.

        Args:
            ecr_arn (str): Complete ECR repository ARN

        Returns:
            str: ECR registry URI in the format:
                {account_id}.dkr.ecr.{region}.amazonaws.com

        Raises:
            ValueError: If the provided ARN is not a valid ECR repository ARN format
        """
        region, account_id, _ = ArnUriHelper._parse_ecr_arn(ecr_arn)
        return f"{account_id}.dkr.ecr.{region}.amazonaws.com"

    @staticmethod
    def _parse_ecr_arn(ecr_arn: str) -> Tuple[str, str, str]:
        """
        Parse an ECR repository ARN into its component parts.

        Internal helper method that uses regex to extract region, account ID, and
        repository name from a properly formatted ECR repository ARN.

        Args:
            ecr_arn (str): ECR repository ARN to parse

        Returns:
            Tuple[str, str, str]: Tuple containing:
                - region: AWS region
                - account_id: AWS account ID
                - repo_name: ECR repository name

        Raises:
            ValueError: If the ARN format is invalid or doesn't match ECR repository pattern

        Expected ARN format:
            arn:aws:ecr:{region}:{account_id}:repository/{repo_name}
        """
        match = re.match(
            r"arn:aws:ecr:(?P<region>[^:]+):(?P<account_id>\d+):repository/(?P<repo_name>.+)",
            ecr_arn
        )
        if not match:
            raise ValueError("Invalid ECR ARN format")

        return match.group("region"), match.group("account_id"), match.group("repo_name")

Functions

_parse_ecr_arn(ecr_arn) staticmethod

Parse an ECR repository ARN into its component parts.

Internal helper method that uses regex to extract region, account ID, and repository name from a properly formatted ECR repository ARN.

Parameters:

Name Type Description Default
ecr_arn str

ECR repository ARN to parse

required

Returns:

Type Description
Tuple[str, str, str]

Tuple[str, str, str]: Tuple containing: - region: AWS region - account_id: AWS account ID - repo_name: ECR repository name

Raises:

Type Description
ValueError

If the ARN format is invalid or doesn't match ECR repository pattern

Expected ARN format

arn:aws:ecr:{region}:{account_id}:repository/{repo_name}

Source code in mare_aws_common_lib/helpers/arn_uri_helper.py
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
@staticmethod
def _parse_ecr_arn(ecr_arn: str) -> Tuple[str, str, str]:
    """
    Parse an ECR repository ARN into its component parts.

    Internal helper method that uses regex to extract region, account ID, and
    repository name from a properly formatted ECR repository ARN.

    Args:
        ecr_arn (str): ECR repository ARN to parse

    Returns:
        Tuple[str, str, str]: Tuple containing:
            - region: AWS region
            - account_id: AWS account ID
            - repo_name: ECR repository name

    Raises:
        ValueError: If the ARN format is invalid or doesn't match ECR repository pattern

    Expected ARN format:
        arn:aws:ecr:{region}:{account_id}:repository/{repo_name}
    """
    match = re.match(
        r"arn:aws:ecr:(?P<region>[^:]+):(?P<account_id>\d+):repository/(?P<repo_name>.+)",
        ecr_arn
    )
    if not match:
        raise ValueError("Invalid ECR ARN format")

    return match.group("region"), match.group("account_id"), match.group("repo_name")

build_alb_arn(region, account_id, alb_name) staticmethod

Build an Application Load Balancer (ALB) ARN.

Constructs a properly formatted ALB ARN for Elastic Load Balancing resources.

Parameters:

Name Type Description Default
region str

AWS region where the ALB is located

required
account_id str

AWS account ID

required
alb_name str

Name of the Application Load Balancer

required

Returns:

Name Type Description
str str

Complete ALB ARN in the format: arn:aws:elasticloadbalancing:{region}:{account_id}:loadbalancer/app/{alb_name}/{alb_name}

Source code in mare_aws_common_lib/helpers/arn_uri_helper.py
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
@staticmethod
def build_alb_arn(region: str, account_id: str, alb_name: str) -> str:
    """
    Build an Application Load Balancer (ALB) ARN.

    Constructs a properly formatted ALB ARN for Elastic Load Balancing resources.

    Args:
        region (str): AWS region where the ALB is located
        account_id (str): AWS account ID
        alb_name (str): Name of the Application Load Balancer

    Returns:
        str: Complete ALB ARN in the format:
            arn:aws:elasticloadbalancing:{region}:{account_id}:loadbalancer/app/{alb_name}/{alb_name}
    """
    return f"arn:aws:elasticloadbalancing:{region}:{account_id}:loadbalancer/app/{alb_name}/{alb_name}"

build_dynamodb_table_arn(region, account_id, table_name) staticmethod

Build a DynamoDB table ARN.

Constructs a properly formatted DynamoDB table ARN for NoSQL database resources.

Parameters:

Name Type Description Default
region str

AWS region where the DynamoDB table is located

required
account_id str

AWS account ID

required
table_name str

Name of the DynamoDB table

required

Returns:

Name Type Description
str str

Complete DynamoDB table ARN in the format: arn:aws:dynamodb:{region}:{account_id}:table/{table_name}

Source code in mare_aws_common_lib/helpers/arn_uri_helper.py
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
@staticmethod
def build_dynamodb_table_arn(region: str, account_id: str, table_name: str) -> str:
    """
    Build a DynamoDB table ARN.

    Constructs a properly formatted DynamoDB table ARN for NoSQL database resources.

    Args:
        region (str): AWS region where the DynamoDB table is located
        account_id (str): AWS account ID
        table_name (str): Name of the DynamoDB table

    Returns:
        str: Complete DynamoDB table ARN in the format:
            arn:aws:dynamodb:{region}:{account_id}:table/{table_name}
    """
    return f"arn:aws:dynamodb:{region}:{account_id}:table/{table_name}"

build_dynamodb_table_index_arn(region, account_id, table_name, index_name) staticmethod

Build a DynamoDB table index ARN.

Constructs a properly formatted DynamoDB table index ARN for Global Secondary Index (GSI) or Local Secondary Index (LSI) resources.

Parameters:

Name Type Description Default
region str

AWS region where the DynamoDB table is located

required
account_id str

AWS account ID

required
table_name str

Name of the DynamoDB table

required
index_name str

Name of the table index (GSI or LSI)

required

Returns:

Name Type Description
str str

Complete DynamoDB table index ARN in the format: arn:aws:dynamodb:{region}:{account_id}:table/{table_name}/index/{index_name}

Source code in mare_aws_common_lib/helpers/arn_uri_helper.py
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
@staticmethod
def build_dynamodb_table_index_arn(region: str, account_id: str, table_name: str, index_name: str) -> str:
    """
    Build a DynamoDB table index ARN.

    Constructs a properly formatted DynamoDB table index ARN for Global Secondary Index (GSI)
    or Local Secondary Index (LSI) resources.

    Args:
        region (str): AWS region where the DynamoDB table is located
        account_id (str): AWS account ID
        table_name (str): Name of the DynamoDB table
        index_name (str): Name of the table index (GSI or LSI)

    Returns:
        str: Complete DynamoDB table index ARN in the format:
            arn:aws:dynamodb:{region}:{account_id}:table/{table_name}/index/{index_name}
    """
    return f"arn:aws:dynamodb:{region}:{account_id}:table/{table_name}/index/{index_name}"

build_ecr_repo_arn(app_helper, repo_name, account_id=None) staticmethod

Build an Amazon ECR repository ARN using application configuration.

Constructs a fully qualified ECR repository ARN using region and account ID from the application helper configuration.

Parameters:

Name Type Description Default
app_helper ApplicationHelper

Helper instance containing region and account configuration

required
repo_name str

Name of the ECR repository

required
account_id str

AWS account ID. If None, retrieves from app_helper environment

None

Returns:

Name Type Description
str str

Complete ECR repository ARN in the format: arn:aws:ecr:{region}:{account_id}:repository/{repo_name}

Source code in mare_aws_common_lib/helpers/arn_uri_helper.py
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
@staticmethod
def build_ecr_repo_arn(app_helper: ApplicationHelper, repo_name: str, account_id: str = None) -> str:
    """
    Build an Amazon ECR repository ARN using application configuration.

    Constructs a fully qualified ECR repository ARN using region and account ID
    from the application helper configuration.

    Args:
        app_helper (ApplicationHelper): Helper instance containing region and account configuration
        repo_name (str): Name of the ECR repository
        account_id (str, optional): AWS account ID. If None, retrieves from app_helper environment

    Returns:
        str: Complete ECR repository ARN in the format:
            arn:aws:ecr:{region}:{account_id}:repository/{repo_name}
    """
    if account_id is None:
        account_id = app_helper.get_from_env("account_id")
    return f"arn:aws:ecr:{app_helper.get_from_common("region")}:{account_id}:repository/{repo_name}"

build_kms_key_arn(region, account_id, key_id) staticmethod

Build a KMS key ARN.

Constructs a properly formatted KMS key ARN for encryption key resources.

Parameters:

Name Type Description Default
region str

AWS region where the KMS key is located

required
account_id str

AWS account ID

required
key_id str

KMS key ID (UUID format)

required

Returns:

Name Type Description
str str

Complete KMS key ARN in the format: arn:aws:kms:{region}:{account_id}:key/{key_id}

Source code in mare_aws_common_lib/helpers/arn_uri_helper.py
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
@staticmethod
def build_kms_key_arn(region: str, account_id: str, key_id: str) -> str:
    """
    Build a KMS key ARN.

    Constructs a properly formatted KMS key ARN for encryption key resources.

    Args:
        region (str): AWS region where the KMS key is located
        account_id (str): AWS account ID
        key_id (str): KMS key ID (UUID format)

    Returns:
        str: Complete KMS key ARN in the format:
            arn:aws:kms:{region}:{account_id}:key/{key_id}
    """
    return f"arn:aws:kms:{region}:{account_id}:key/{key_id}"

build_pipeline_arn(region, account_id, pipeline_name) staticmethod

Build a CodePipeline ARN.

Constructs a properly formatted CodePipeline ARN for CI/CD pipeline resources.

Parameters:

Name Type Description Default
region str

AWS region where the pipeline is located

required
account_id str

AWS account ID

required
pipeline_name str

Name of the CodePipeline

required

Returns:

Name Type Description
str str

Complete CodePipeline ARN in the format: arn:aws:codepipeline:{region}:{account_id}:{pipeline_name}

Source code in mare_aws_common_lib/helpers/arn_uri_helper.py
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
@staticmethod
def build_pipeline_arn(region: str, account_id: str, pipeline_name: str) -> str:
    """
    Build a CodePipeline ARN.

    Constructs a properly formatted CodePipeline ARN for CI/CD pipeline resources.

    Args:
        region (str): AWS region where the pipeline is located
        account_id (str): AWS account ID
        pipeline_name (str): Name of the CodePipeline

    Returns:
        str: Complete CodePipeline ARN in the format:
            arn:aws:codepipeline:{region}:{account_id}:{pipeline_name}
    """
    return f"arn:aws:codepipeline:{region}:{account_id}:{pipeline_name}"

build_s3_bucket_arn(bucket_name) staticmethod

Build an Amazon S3 bucket ARN.

Constructs a properly formatted S3 bucket ARN using the bucket name.

Parameters:

Name Type Description Default
bucket_name str

Name of the S3 bucket

required

Returns:

Name Type Description
str str

Complete S3 bucket ARN in the format: arn:aws:s3:::{bucket_name}

Source code in mare_aws_common_lib/helpers/arn_uri_helper.py
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
@staticmethod
def build_s3_bucket_arn(bucket_name: str) -> str:
    """
    Build an Amazon S3 bucket ARN.

    Constructs a properly formatted S3 bucket ARN using the bucket name.

    Args:
        bucket_name (str): Name of the S3 bucket

    Returns:
        str: Complete S3 bucket ARN in the format:
            arn:aws:s3:::{bucket_name}
    """
    return f"arn:aws:s3:::{bucket_name}"

build_s3_bucket_uri(bucket_name, folder=None) staticmethod

Build an S3 URI for accessing bucket contents.

Constructs an S3 URI that can be used with AWS CLI, SDKs, and other tools for accessing S3 objects. Optionally includes a folder path.

Parameters:

Name Type Description Default
bucket_name str

Name of the S3 bucket

required
folder str

Folder path within the bucket. Defaults to None.

None

Returns:

Name Type Description
str str

S3 URI in the format: - s3://{bucket_name} (if no folder) - s3://{bucket_name}/{folder} (if folder specified)

Source code in mare_aws_common_lib/helpers/arn_uri_helper.py
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
@staticmethod
def build_s3_bucket_uri(bucket_name: str, folder: str = None) -> str:
    """
    Build an S3 URI for accessing bucket contents.

    Constructs an S3 URI that can be used with AWS CLI, SDKs, and other tools
    for accessing S3 objects. Optionally includes a folder path.

    Args:
        bucket_name (str): Name of the S3 bucket
        folder (str, optional): Folder path within the bucket. Defaults to None.

    Returns:
        str: S3 URI in the format:
            - s3://{bucket_name} (if no folder)
            - s3://{bucket_name}/{folder} (if folder specified)
    """
    uri = f"s3://{bucket_name}"
    if folder is not None:
        uri = f"{uri}/{folder}"
    return uri

build_secret_arn(region, account_id, secret_name) staticmethod

Build a Secrets Manager secret ARN.

Constructs a properly formatted Secrets Manager ARN for secret resources.

Parameters:

Name Type Description Default
region str

AWS region where the secret is stored

required
account_id str

AWS account ID

required
secret_name str

Name of the secret in Secrets Manager

required

Returns:

Name Type Description
str str

Complete Secrets Manager ARN in the format: arn:aws:secretsmanager:{region}:{account_id}:secret:{secret_name}

Source code in mare_aws_common_lib/helpers/arn_uri_helper.py
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
@staticmethod
def build_secret_arn(region: str, account_id: str, secret_name: str) -> str:
    """
    Build a Secrets Manager secret ARN.

    Constructs a properly formatted Secrets Manager ARN for secret resources.

    Args:
        region (str): AWS region where the secret is stored
        account_id (str): AWS account ID
        secret_name (str): Name of the secret in Secrets Manager

    Returns:
        str: Complete Secrets Manager ARN in the format:
            arn:aws:secretsmanager:{region}:{account_id}:secret:{secret_name}
    """
    return f"arn:aws:secretsmanager:{region}:{account_id}:secret:{secret_name}"

build_sns_topic_arn(region, account_id, topic_name) staticmethod

Build an SNS topic ARN.

Constructs a properly formatted Simple Notification Service (SNS) topic ARN for messaging and notification resources.

Parameters:

Name Type Description Default
region str

AWS region where the SNS topic is located

required
account_id str

AWS account ID

required
topic_name str

Name of the SNS topic

required

Returns:

Name Type Description
str str

Complete SNS topic ARN in the format: arn:aws:sns:{region}:{account_id}:{topic_name}

Source code in mare_aws_common_lib/helpers/arn_uri_helper.py
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
@staticmethod
def build_sns_topic_arn(region: str, account_id: str, topic_name: str) -> str:
    """
    Build an SNS topic ARN.

    Constructs a properly formatted Simple Notification Service (SNS) topic ARN
    for messaging and notification resources.

    Args:
        region (str): AWS region where the SNS topic is located
        account_id (str): AWS account ID
        topic_name (str): Name of the SNS topic

    Returns:
        str: Complete SNS topic ARN in the format:
            arn:aws:sns:{region}:{account_id}:{topic_name}
    """
    return f"arn:aws:sns:{region}:{account_id}:{topic_name}"

get_ecr_registry_uri_from_arn(ecr_arn) staticmethod

Extract ECR registry URI from an ECR repository ARN.

Parses an ECR repository ARN and constructs the registry URI (without repository name) that can be used for Docker login operations.

Parameters:

Name Type Description Default
ecr_arn str

Complete ECR repository ARN

required

Returns:

Name Type Description
str str

ECR registry URI in the format: {account_id}.dkr.ecr.{region}.amazonaws.com

Raises:

Type Description
ValueError

If the provided ARN is not a valid ECR repository ARN format

Source code in mare_aws_common_lib/helpers/arn_uri_helper.py
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
@staticmethod
def get_ecr_registry_uri_from_arn(ecr_arn: str) -> str:
    """
    Extract ECR registry URI from an ECR repository ARN.

    Parses an ECR repository ARN and constructs the registry URI (without repository name)
    that can be used for Docker login operations.

    Args:
        ecr_arn (str): Complete ECR repository ARN

    Returns:
        str: ECR registry URI in the format:
            {account_id}.dkr.ecr.{region}.amazonaws.com

    Raises:
        ValueError: If the provided ARN is not a valid ECR repository ARN format
    """
    region, account_id, _ = ArnUriHelper._parse_ecr_arn(ecr_arn)
    return f"{account_id}.dkr.ecr.{region}.amazonaws.com"

get_ecr_repo_uri_from_arn(ecr_arn) staticmethod

Extract ECR repository URI from an ECR ARN.

Parses an ECR repository ARN and constructs the corresponding repository URI that can be used for Docker operations (push, pull, etc.).

Parameters:

Name Type Description Default
ecr_arn str

Complete ECR repository ARN

required

Returns:

Name Type Description
str str

ECR repository URI in the format: {account_id}.dkr.ecr.{region}.amazonaws.com/{repo_name}

Raises:

Type Description
ValueError

If the provided ARN is not a valid ECR repository ARN format

Source code in mare_aws_common_lib/helpers/arn_uri_helper.py
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
@staticmethod
def get_ecr_repo_uri_from_arn(ecr_arn: str) -> str:
    """
    Extract ECR repository URI from an ECR ARN.

    Parses an ECR repository ARN and constructs the corresponding repository URI
    that can be used for Docker operations (push, pull, etc.).

    Args:
        ecr_arn (str): Complete ECR repository ARN

    Returns:
        str: ECR repository URI in the format:
            {account_id}.dkr.ecr.{region}.amazonaws.com/{repo_name}

    Raises:
        ValueError: If the provided ARN is not a valid ECR repository ARN format
    """
    region, account_id, repo_name = ArnUriHelper._parse_ecr_arn(ecr_arn)
    return f"{account_id}.dkr.ecr.{region}.amazonaws.com/{repo_name}"

get_ecr_repo_url_from_arn(ecr_arn) staticmethod

Generate AWS Console URL for an ECR repository from its ARN.

Parses an ECR repository ARN and constructs the corresponding AWS Console URL for viewing the repository in the web interface.

Parameters:

Name Type Description Default
ecr_arn str

Complete ECR repository ARN

required

Returns:

Name Type Description
str str

AWS Console URL for the ECR repository in the format: https://{region}.console.aws.amazon.com/ecr/repositories/private/{account_id}/{repo_name}

Raises:

Type Description
ValueError

If the provided ARN is not a valid ECR repository ARN format

Source code in mare_aws_common_lib/helpers/arn_uri_helper.py
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
@staticmethod
def get_ecr_repo_url_from_arn(ecr_arn: str) -> str:
    """
    Generate AWS Console URL for an ECR repository from its ARN.

    Parses an ECR repository ARN and constructs the corresponding AWS Console URL
    for viewing the repository in the web interface.

    Args:
        ecr_arn (str): Complete ECR repository ARN

    Returns:
        str: AWS Console URL for the ECR repository in the format:
            https://{region}.console.aws.amazon.com/ecr/repositories/private/{account_id}/{repo_name}

    Raises:
        ValueError: If the provided ARN is not a valid ECR repository ARN format
    """
    region, account_id, repo_name = ArnUriHelper._parse_ecr_arn(ecr_arn)
    return f"https://{region}.console.aws.amazon.com/ecr/repositories/private/{account_id}/{repo_name}"