Sign In Start Free Trial
Account

Add to playlist

Create a Playlist

Modal Close icon
You need to login to use this feature.
  • Book Overview & Buying Machine Learning with Amazon SageMaker Cookbook
  • Table Of Contents Toc
  • Feedback & Rating feedback
Machine Learning with Amazon SageMaker Cookbook

Machine Learning with Amazon SageMaker Cookbook

By : Joshua Arvin Lat
5 (9)
close
close
Machine Learning with Amazon SageMaker Cookbook

Machine Learning with Amazon SageMaker Cookbook

5 (9)
By: Joshua Arvin Lat

Overview of this book

Amazon SageMaker is a fully managed machine learning (ML) service that helps data scientists and ML practitioners manage ML experiments. In this book, you'll use the different capabilities and features of Amazon SageMaker to solve relevant data science and ML problems. This step-by-step guide features 80 proven recipes designed to give you the hands-on machine learning experience needed to contribute to real-world experiments and projects. You'll cover the algorithms and techniques that are commonly used when training and deploying NLP, time series forecasting, and computer vision models to solve ML problems. You'll explore various solutions for working with deep learning libraries and frameworks such as TensorFlow, PyTorch, and Hugging Face Transformers in Amazon SageMaker. You'll also learn how to use SageMaker Clarify, SageMaker Model Monitor, SageMaker Debugger, and SageMaker Experiments to debug, manage, and monitor multiple ML experiments and deployments. Moreover, you'll have a better understanding of how SageMaker Feature Store, Autopilot, and Pipelines can meet the specific needs of data science teams. By the end of this book, you'll be able to combine the different solutions you've learned as building blocks to solve real-world ML problems.
Table of Contents (11 chapters)
close
close

Pushing the custom Python algorithm container image to an Amazon ECR repository

In the previous recipe, we have prepared and built the custom container image using the docker build command. In this recipe, we will push the custom container image to an Amazon ECR repository. If this is your first time hearing about Amazon ECR, it is simply a fully managed container registry that helps us manage our container images.

After pushing the container image to an Amazon ECR repository, we can use this image for training and deployment in the Using the custom Python algorithm container image for training and inference with Amazon SageMaker Local Mode recipe.

Getting ready

Here are the prerequisites for this recipe:

  • This recipe continues from the Building and testing the custom Python algorithm container image recipe.
  • You will need the necessary permissions to manage the Amazon ECR resources if you're using an AWS IAM user with a custom URL.

How to do it…

The initial steps in this recipe focus on creating the ECR repository. Let's get started:

  1. Use the search bar in the AWS Console to navigate to the Elastic Container Registry console. Click Elastic Container Registry when it appears in the search results:
    Figure 2.62 – Navigating to the ECR console

    Figure 2.62 – Navigating to the ECR console

    As you can see, we can use the search bar to quickly navigate to the Elastic Container Registry service. If we type in ecr, the Elastic Container Registry service in the search results may come up in third or fourth place.

  2. Click the Create repository button:
    Figure 2.63 – Create repository button

    Figure 2.63 – Create repository button

    Here, the Create repository button is at the top right of the screen.

  3. In the Create repository form, specify a Repository name. Use the value of $IMAGE_NAME from the Building and testing the custom Python algorithm container image recipe. In this case, we will use chap02_python:
    Figure 2.64 – Create repository form

    Figure 2.64 – Create repository form

    Here, we have the Create repository form. For Visibility settings, we will choose Private and set the Tag immutability configuration to Disabled.

  4. Scroll down until you see the Create repository button. Leave the other configuration settings as-is and click Create repository:
    Figure 2.65 – Create repository button

    Figure 2.65 – Create repository button

    As we can see, the Create repository button is at the bottom of the page.

  5. Click chap02_python:
    Figure 2.66 – Link to the ECR repository page

    Figure 2.66 – Link to the ECR repository page

    Here, we have a link under the Repository name column. Clicking this link should redirect us to the repository's details page.

  6. Click View push commands:
    Figure 2.67 – View push commands button (upper right)

    Figure 2.67 – View push commands button (upper right)

    As we can see, the View push commands button is at the top right of the page, beside the Edit button.

  7. You may optionally copy the first command, aws ecr get-login-password …, from the dialog box.
    Figure 2.68 – Push commands dialog box

    Figure 2.68 – Push commands dialog box

    Here, we can see multiple commands that we can use. We will only need the first one (aws ecr get-login-password …). Click the icon with two overlapping boxes on the right-hand side of the code box to copy the entire line to the clipboard.

  8. Navigate back to the AWS Cloud9 environment IDE and create a new Terminal. You may also reuse an existing one:
    Figure 2.69 – New Terminal

    Figure 2.69 – New Terminal

    The preceding screenshot shows us how to create a new Terminal. Click the green plus button and then select New Terminal from the list of options. Note that the green plus button is directly under the Editor pane.

  9. Navigate to the ml-python directory:
    cd /home/ubuntu/environment/opt/ml-python
  10. Get the account ID using the following commands:
    ACCOUNT_ID=$(aws sts get-caller-identity | jq -r ".Account")
    echo $ACCOUNT_ID
  11. Specify the IMAGE_URI value and use the ECR repository name we specified while creating the repository in this recipe. In this case, we will run IMAGE_URI="chap02_python":
    IMAGE_URI="<insert ECR Repository URI>"
    TAG="1"
  12. Authenticate with Amazon ECR so that we can push our Docker container image to an Amazon ECR repository in our account later:
    aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin $ACCOUNT_ID.dkr.ecr.us-east-1.amazonaws.com

    Important note

    Note that we have assumed that our repository is in the us-east-1 region. Feel free to modify the region in the command if needed. This applies to all the commands in this chapter.

  13. Use the docker tag command:
    docker tag $IMAGE_URI:$TAG $ACCOUNT_ID.dkr.ecr.us-east-1.amazonaws.com/$IMAGE_URI:$TAG
  14. Push the image to the Amazon ECR repository using the docker push command:
    docker push $ACCOUNT_ID.dkr.ecr.us-east-1.amazonaws.com/$IMAGE_URI:$TAG

    At this point, our custom container image should now be successfully pushed into the ECR repository.

Now that we have completed this recipe, we can proceed with using this custom container image for training and inference with SageMaker in the next recipe. But before that, let's see how this works!

How it works…

In the previous recipe, we used the docker build command to prepare the custom container image. In this recipe, we created an Amazon ECR repository and pushed our custom container image to the repository. With Amazon ECR, we can store, manage, share, and run custom container images anywhere. This includes using these container images in SageMaker during training and deployment.

When pushing the custom container image to the Amazon ECR repository, we need the account ID, region, repository name, and tag. Once we have these, the docker push command will look something like this:

docker push <ACCOUNT_ID>.dkr.ecr.<REGION>.amazonaws.com/<REPOSITORY NAME>:<TAG>

When working with container image versions, make sure to change the version number every time you modify this Dockerfile and push a new version to the ECR repository. This will be helpful when you need to use a previous version of a container image.

Create a Note

Modal Close icon
You need to login to use this feature.
notes
bookmark search playlist download font-size

Change the font size

margin-width

Change margin width

day-mode

Change background colour

Close icon Search
Country selected

Close icon Your notes and bookmarks

Delete Bookmark

Modal Close icon
Are you sure you want to delete it?
Cancel
Yes, Delete

Delete Note

Modal Close icon
Are you sure you want to delete it?
Cancel
Yes, Delete

Edit Note

Modal Close icon
Write a note (max 255 characters)
Cancel
Update Note

Confirmation

Modal Close icon
claim successful

Buy this book with your credits?

Modal Close icon
Are you sure you want to buy this book with one of your credits?
Close
YES, BUY