Skip to content

Commit c0be78a

Browse files
authored
change: use regional endpoint for STS in builds and tests (#1102)
1 parent c0b5e26 commit c0be78a

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

buildspec.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ phases:
2525
- |
2626
if [ -d "ci-lock" ]; then
2727
FILENAME=$(ls ci-lock/ || true)
28-
ACCOUNT=$(aws sts get-caller-identity --region us-west-2 --output text | awk '{print $1}')
28+
ACCOUNT=$(aws --endpoint-url https://sts.us-west-2.amazonaws.com sts get-caller-identity --region us-west-2 --output text | awk '{print $1}')
2929
S3_BUCKET_DIR=s3://sagemaker-us-west-2-${ACCOUNT}/ci-lock/
3030
aws s3 rm ${S3_BUCKET_DIR}${FILENAME}
3131
fi

ci-scripts/queue_build.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616
import time
1717
import boto3
1818

19-
account = boto3.client("sts").get_caller_identity()["Account"]
19+
account = boto3.client(
20+
"sts", region_name="us-west-2", endpoint_url="https://sts.us-west-2.amazonaws.com"
21+
).get_caller_identity()["Account"]
2022
bucket_name = "sagemaker-us-west-2-%s" % account
2123

2224

tests/integ/kms_utils.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
from botocore import exceptions
1919

20+
from sagemaker import utils
21+
2022
PRINCIPAL_TEMPLATE = (
2123
'["{account_id}", "{role_arn}", ' '"arn:aws:iam::{account_id}:role/{sagemaker_role}"] '
2224
)
@@ -108,7 +110,10 @@ def get_or_create_kms_key(
108110
kms_client = sagemaker_session.boto_session.client("kms")
109111
kms_key_arn = _get_kms_key_arn(kms_client, alias)
110112

111-
sts_client = sagemaker_session.boto_session.client("sts")
113+
region = sagemaker_session.boto_region_name
114+
sts_client = sagemaker_session.boto_session.client(
115+
"sts", region_name=region, endpoint_url=utils.sts_regional_endpoint(region)
116+
)
112117
account_id = sts_client.get_caller_identity()["Account"]
113118

114119
if kms_key_arn is None:
@@ -154,8 +159,13 @@ def get_or_create_kms_key(
154159

155160
@contextlib.contextmanager
156161
def bucket_with_encryption(boto_session, sagemaker_role):
157-
account = boto_session.client("sts").get_caller_identity()["Account"]
158-
role_arn = boto_session.client("sts").get_caller_identity()["Arn"]
162+
region = boto_session.region_name
163+
sts_client = boto_session.client(
164+
"sts", region_name=region, endpoint_url=utils.sts_regional_endpoint(region)
165+
)
166+
167+
account = sts_client.get_caller_identity()["Account"]
168+
role_arn = sts_client.get_caller_identity()["Arn"]
159169

160170
kms_client = boto_session.client("kms")
161171
kms_key_arn = _create_kms_key(kms_client, account, role_arn, sagemaker_role, None)

0 commit comments

Comments
 (0)