Skip to content

Commit a36475a

Browse files
AWS helper to generate console URLs and check ARNs
1 parent 4be7b1c commit a36475a

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

sagemaker_ssh_helper/aws.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
class AWS:
2+
def __init__(self, region: str) -> None:
3+
super().__init__()
4+
self.region = region
5+
6+
def get_console_domain(self):
7+
"""
8+
See https://docs.aws.amazon.com/general/latest/gr/mgmt-console.html .
9+
See https://docs.amazonaws.cn/en_us/aws/latest/userguide/endpoints-arns.html .
10+
See https://github.com/boto/botocore/blob/develop/botocore/data/endpoints.json .
11+
"""
12+
if self.region.startswith("cn-"):
13+
return f"{self.region}.console.amazonaws.cn"
14+
if self.region.startswith("us-gov-"):
15+
return f"{self.region}.console.amazonaws-us-gov.com"
16+
return f"{self.region}.console.aws.amazon.com"
17+
18+
@staticmethod
19+
def is_arn(arn: str):
20+
"""
21+
See https://docs.aws.amazon.com/govcloud-us/latest/UserGuide/using-govcloud-arns.html .
22+
See https://docs.amazonaws.cn/en_us/aws/latest/userguide/ARNs.html .
23+
"""
24+
import re
25+
return re.match(r'^arn:(aws|aws-cn|aws-us-gov):iam::([0-9]+):role/(\S+)$', arn)

0 commit comments

Comments
 (0)