An example project to deploy MXNet inference API with Docker on Amazon ECS. Uses CodePipeline and CodeBuild to build the image to deploy to ECS.
Switch branches/tags
Nothing to show
Clone or download
asifamz Merge pull request #6 from jbnunn/s3unsigned
Setting boto3 S3 client to make unsigned requests to the public S3 bucket
Latest commit cd7371b Nov 13, 2017

Deploy a MXNet predict function to Amazon ECS using CodeCommit and CodePipeline

This project will create an automated workflow that will provision, configure and orchestrate a pipeline triggering deployment of any changes to your mxnet model or application code. You will orchestrate all of the changes into a deployment pipeline to achieve continuous delivery using CodePipeline and CodeBuild. You can deploy new MXNet APIs and make those available to your users in just minutes, not days or weeks.


Prepare an AWS Account
If you don’t already have an AWS account, create one at by following the on-screen instructions.

Please launch in N.Virginia

Create a CodeCommit repository and Connect with this repository

  1. Clone this github repository

    git clone
  2. Go to AWS Console and select CodeCommit. Click Create New repository button. Enter a unique repository name( e.g. image-classification-predict ) and a description and click Create repository.

    You will get a URL to your CodeCommit repository similar to

  3. You can use https or ssh to connect to your CodeCommit repository. We’ll connect via SSH in this lab.
    Follow instructions from here:

Commit the Source Code and Configuration files into your CodeCommit repository

  1. Clone a local copy of CodeCommit repo ( we recommend: you created earlier in your home directory.

     cd ~
     git clone <your repo url from above> 

    This will create a folder as the same name as in your path where you executed the git clone command.

  2. Copy the contents of directory into this new folder.

     cp -r ecs-mxnet-example/image-classification-predict/ image-classification-predict/
  3. Change the buildspec.yml file to include your AWS account number.

     <your account number>
  4. Commit all of the copied contents into your CodeCommit repository.

    git add --all
    git commit -m "Initial Commit"
    git push origin master  

Tip: Verify the file .git/config for remote==”origin” and branch==”master”

Deploy via CloudFormation template.

  1. Run the Cloudformation template provided
    1. Go to AWS Console
    2. Click on Services
    3. Click on Cloudformation
    4. Create a new stack
    5. Enter the url in the Specify an Amazon S3 template URL section
    6. Follow the steps with default parameters.
    7. Review the details
    8. Click create.

It takes 10 minutes to deploy the complete stack.

The Cloud Formation template creates a ECS cluster in a VPC and deploys the application code alongwith the needed dependencies. It also adds Cloud Watch for logging and performance monitoring and autoscaling alongwith an Application Load Balancer.

The development workflow is preconstructed with the CICD pipeline to ensure the application development and model training workflows are integrated.

Test using a Rest Client.

You can get the MLServiceUrl from the Cloudformation Output for the master stack.

GET http://<MLServiceUrl>/image?image=<image_url>

an example url to use:,_San_Francisco,_California_LCCN2013633353.tif/lossy-page1-450px-Golden_Gate_Bridge,_San_Francisco,_California_LCCN2013633353.tif.jpg

The API predicts that theimage is a suspension bridge with 62% probability.


  • Reset Steps

    1. Delete the ECR Repository
    2. Delete the CloudFormation stack and re-create it.
  • Removal Steps

    1. Delete the ECR Repository
    2. Delete the CloudFormation stack.