Docker Deployment on AWS Sagemaker

Alex Egg,

Clone docker app:

First train your model following the SageMaker Interface by building a docker container w/ a train and serve program.

Then after you finish that pattern, you can use the Sagemaker training and serving infrastructure.

Local Deployment

Build the docker image:

This will build the docker image and push it to the remote repository (ECS):

cd local_test

Train the docker image locally:

This will run the docker image and train the Scikit Decision Tree model and serialize it to disk.


Run the docker image locally:

This will deserialize the model from disk and start a web API stack around it:


Test Inference Locally

This will query the model via REST API call:

sh payload.csv

Sagemaker Deployment

Do this in sagemaker notebook

# S3 prefix
prefix = 'DEMO-scikit-byo-iris'

# Define IAM role
import boto3
import re

import os
import numpy as np
import pandas as pd
from sagemaker import get_execution_role

role = get_execution_role()
import sagemaker as sage
from time import gmtime, strftime

sess = sage.Session()

data_location = sess.upload_data(WORK_DIRECTORY, key_prefix=prefix)
account = sess.boto_session.client('sts').get_caller_identity()['Account']
region = sess.boto_session.region_name
# image = '{}.dkr.ecr.{}'.format(account, region)
image = ""

tree = sage.estimator.Estimator(image,
                       role, 1, 'ml.c4.2xlarge',
from sagemaker.predictor import csv_serializer
predictor = tree.deploy(1, 'ml.m4.xlarge', serializer=csv_serializer)
shape=pd.read_csv("data/iris.csv", header=None)

import itertools

a = [50*i for i in range(3)]
b = [40+i for i in range(10)]
indices = [i+j for i,j in itertools.product(a,b)]

print predictor.predict(test_X.values).decode('utf-8')

Permalink: docker-deployment-on-aws-sagemaker


Last edited by Alex Egg, 2018-10-24 03:50:51
View Revision History