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