4

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.

Mykola Zotko
  • 15,583
  • 3
  • 71
  • 73
  • You can construct the URL by parsing the output of `aws ecr describe-images --repository-name ` using `jq`. – Hedi Bejaoui Sep 07 '20 at 11:29
  • @HediBejaoui In this case I need to know the repository name (need to google). Could you show an example, please? – Mykola Zotko Sep 07 '20 at 11:48
  • My apologies, I missed the fact that `linear-learner` was a built-in model and not hosted in your ECR repository. Kindly ignore my comment above. – Hedi Bejaoui Sep 07 '20 at 12:51

3 Answers3

4

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
Vlas Sokolov
  • 3,733
  • 3
  • 26
  • 43
2

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.

Mykola Zotko
  • 15,583
  • 3
  • 71
  • 73
-1

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

Mark
  • 1
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Feb 11 '22 at 06:37