Provide users with access to custom images - Amazon SageMaker
Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions, see Getting Started with Amazon Web Services in China (PDF).

Provide users with access to custom images

This documentation provides step-by-step instructions to provide your users with access to custom images for their Code Editor environments. You can use the information on this page to create custom environments for your user’s workflows. The process involves utilizing:

  • Docker

  • Amazon Command Line Interface

  • Amazon Elastic Container Registry

  • Amazon SageMaker Amazon Web Services Management Console

After following the guidance on this page, Code Editor users on the Amazon SageMaker domain will have access to the custom image and environment from their Code Editor spaces to empower their machine learning workflows.

Important

This page assumes that you have the Amazon Command Line Interface and Docker installed on your local machine.

To have your users successfully run their image within Code Editor, you must do the following:

To have your users successfully run the image
  1. Create the Dockerfile

  2. Build the image from the Dockerfile

  3. Upload the image to Amazon Elastic Container Registry

  4. Attach the image to your Amazon SageMaker domain

  5. Have your users access the image from their Code Editor space

Step 1: Create the Dockerfile

Create a Dockerfile to define the steps needed to create the environment needed to run the application in your user's container.

Important

Your Dockerfile must meet the specifications provided in Dockerfile specifications.

For sample Dockerfiles in the correct format, see Dockerfile samples.

Step 2: Build the Dockerfile

In the same directory as your Dockerfile, build your image using the following command:

docker build -t username/imagename:tag your-account-id.dkr.ecr.Amazon Web Services Region.amazonaws.com/your-repository-name:tag
Important

Your image must be tagged in the following format: 123456789012.dkr.ecr.your-region.amazonaws.com/your-repository-name:tag

You won’t be able to push it to an Amazon Elastic Container Registry repository otherwise.

Step 3: Push the image to the Amazon Elastic Container Registry repository

After you’ve built your image, log in to your Amazon ECR repository using the following command:

aws ecr get-login-password --region Amazon Web Services Region | docker login --username AWS --password-stdin 123456789012.dkr.ecr.Amazon Web Services Region.amazonaws.com

After you’ve logged in, push your Dockerfile using the following command:

docker push 123456789012.dkr.ecr.Amazon Web Services Region.amazonaws.com/your-repository-name:tag

Step 4: Attach image to the Amazon SageMaker domain of your users

After you’ve pushed the image, you must access it from your Amazon SageMaker domain using either the SageMaker console or the Amazon CLI.

Attach the image using the SageMaker console

Use the following procedure to attach the image to a SageMaker domain through the SageMaker console :

  1. Open the SageMaker console.

  2. Under Admin configurations, choose Domains.

  3. From the list of domains, select a domain.

  4. Open the Environment tab.

  5. For Custom images for personal Studio apps, choose Attach image.

  6. Specify the image source. You can create a new image or choose an existing image.

  7. Choose Next.

  8. Choose Code Editor as the application type.

  9. Choose Submit.

Attach the image using the Amazon CLI

Use the following procedure to attach the image to a SageMaker domain through the Amazon CLI :

  1. Create a SageMaker image. The role ARN must have the AmazonSageMakerFullAccess policy attached.

    aws sagemaker create-image \ --image-name code-editor-custom-image \ --role-arn arn:aws:iam::account-id:role/service-role/execution-role
  2. Create a SageMaker image version from the image. Pass the unique tag value that you chose when you pushed the image to Amazon ECR.

    aws sagemaker create-image-version \ --image-name code-editor-custom-image \ --base-image repository-uri:tag
  3. Create a configuration file called app-image-config-input.json. The application image configuration is used as configuration for running a SageMaker image as a Code Editor application. You may also specify your ContainerConfig arguments here.

    { "AppImageConfigName": "code-editor-app-image-config", "CodeEditorAppImageConfig": { "ContainerConfig": {} } }
  4. Create the AppImageConfig using the application image configuration file that you created.

    aws sagemaker create-app-image-config \ --cli-input-json file://app-image-config-input.json
  5. Create a configuration file, named updateDomain.json. Be sure to specify your domain ID.

    { "DomainId": "domain-id", "DefaultUserSettings": { "CodeEditorAppSettings": { "CustomImages": [ { "ImageName": "code-editor-custom-image", "AppImageConfigName": "code-editor-app-image-config" } ] } } }
  6. Call the UpdateDomain command with the configuration file as input.

    Note

    You must delete all of the applications in your domain before updating the domain with the new image. Note that you only need to delete applications; you do not need to delete user profiles or shared spaces. For instructions on deleting applications, choose one of the following options.

    aws sagemaker update-domain --cli-input-json file://updateDomain.json

Step 5: Have your users access the image from their Code Editor space

Your users can now select the image that you’ve attached to their domain from their Code Editor space.

For more information on selecting a custom image, see Launch a Code Editor application in Studio.