How to get an Amazon ECR container URI for a specific model image in Sagemaker?

Viewed 3017

I want to know if it's possible to get an Amazon ECR container URI for a specific image programmatically (using AWS CLI or Python). For example, if I need the URL for the latest linear-learner (built-in model) image for the eu-central-1 region.

Expected result:

664544806723.dkr.ecr.eu-central-1.amazonaws.com/linear-learner:latest

EDIT: I have found the solution with get_image_uri. It looks like this function will be depreceated and I don't know how to use ImageURIProvider instead.

3 Answers

The newer versions of SageMaker SDK have a more centralized API for getting the URIs:

import sagemaker 
sagemaker.image_uris.retrieve("linear-learner", "eu-central-1")

which gives the expected result:

664544806723.dkr.ecr.eu-central-1.amazonaws.com/linear-learner:1

We can use the function get_image_uri:

from sagemaker.amazon.amazon_estimator import get_image_uri

region = boto3.Session().region_name
#or region = 'eu-central-1'

get_image_uri(region_name=region,
              repo_name='linear-learner',
              repo_version='latest')

Output:

664544806723.dkr.ecr.eu-central-1.amazonaws.com/linear-learner:latest

Warning:

'get_image_uri' method will be deprecated in favor of 'ImageURIProvider' class in SageMaker Python SDK v2.

It looks like this function will be deprecated and I can't find how to use ImageURIProvider instead.

from sagemaker import image_uris container = sagemaker.image_uris.retrieve("linear-learner", boto3.Session().region_name)

Related