2929from sagemaker .mxnet import MXNet
3030from sagemaker .predictor import Predictor
3131from sagemaker .serializers import NumpySerializer
32- from sagemaker .utils import sagemaker_timestamp , unique_name_from_base , get_ecr_image_uri_prefix
32+ from sagemaker .utils import sagemaker_timestamp , unique_name_from_base
3333from tests .integ import DATA_DIR , TRAINING_DEFAULT_TIMEOUT_MINUTES
3434from tests .integ .retry import retries
3535from tests .integ .timeout import timeout , timeout_and_delete_endpoint_by_name
4242
4343@pytest .fixture (scope = "module" )
4444def container_image (sagemaker_session ):
45- """ Create a Multi-Model container image for use with integration testcases
46- since 1P containers supporting multiple models are not available yet"""
47- region = sagemaker_session .boto_region_name
48- ecr_client = sagemaker_session .boto_session .client ("ecr" , region_name = region )
49- sts_client = sagemaker_session .boto_session .client (
50- "sts" , region_name = region , endpoint_url = utils .sts_regional_endpoint (region )
51- )
52- account_id = sts_client .get_caller_identity ()["Account" ]
53- algorithm_name = "sagemaker-multimodel-integ-test-{}" .format (sagemaker_timestamp ())
54- ecr_image_uri_prefix = get_ecr_image_uri_prefix (account = account_id , region = region )
55- ecr_image = "{prefix}/{algorithm_name}:latest" .format (
56- prefix = ecr_image_uri_prefix , algorithm_name = algorithm_name
57- )
45+ """Create a Multi-Model image since pre-built ones are not available yet."""
46+ algorithm_name = unique_name_from_base ("sagemaker-multimodel-integ-test-{}" )
47+ ecr_image = _ecr_image_uri (sagemaker_session , algorithm_name )
5848
5949 # Build and tag docker image locally
6050 docker_client = docker .from_env ()
@@ -64,7 +54,9 @@ def container_image(sagemaker_session):
6454 image .tag (ecr_image , tag = "latest" )
6555
6656 # Create AWS ECR and push the local docker image to it
57+ ecr_client = sagemaker_session .boto_session .client ("ecr" )
6758 _create_repository (ecr_client , algorithm_name )
59+
6860 username , password = _ecr_login (ecr_client )
6961 # Retry docker image push
7062 for _ in retries (3 , "Upload docker image to ECR repo" , seconds_to_sleep = 10 ):
@@ -83,6 +75,18 @@ def container_image(sagemaker_session):
8375 _delete_repository (ecr_client , algorithm_name )
8476
8577
78+ def _ecr_image_uri (sagemaker_session , algorithm_name ):
79+ region = sagemaker_session .boto_region_name
80+
81+ sts_client = sagemaker_session .boto_session .client (
82+ "sts" , region_name = region , endpoint_url = utils .sts_regional_endpoint (region )
83+ )
84+ account_id = sts_client .get_caller_identity ()["Account" ]
85+
86+ endpoint_data = utils ._botocore_resolver ().construct_endpoint ("ecr" , region )
87+ return "{}.dkr.{}/{}:latest" .format (account_id , endpoint_data ["hostname" ], algorithm_name )
88+
89+
8690def _create_repository (ecr_client , repository_name ):
8791 """
8892 Creates an ECS Repository (ECR). When a new transform is being registered,
0 commit comments