Giter VIP home page Giter VIP logo

reinvent2018-builder-session's Introduction

Building High-Scale Web Apps on Amazon EC2 Fleet

Welcome to this builder session!

We are going to deploy an image classifier using deep learning model(SqueezeNet), Model Server for Apache MXNet and Amazon ECS on top of Amazon EC2 Fleet and Amazon EC2 AutoScaling. One of the fun things are, that the Amazon EC2 Spot Instances we are using is at savings of up to 90% the On-Demand price.

Prerequisites:

  • To complete this builder session, you need access to an AWS account with administrative permissions. An IAM user with administrator access (arn:aws:iam::aws:policy/AdministratorAccess) will do nicely. More information
  • AWS CLI configuration

Notes:

  • The console links provided throughout the demo are in US East(Ohio, us-east-2).

Table of contents:

1. Create Amazon ECS Cluster

Amazon Elastic Container Service(Amazon ECS) is a highly scalable, high-performance container orchestration service that supports Docker containers and allows you to easily run and scale containerized applications on AWS.

Please create cluster with two EC2 Spot instances in ECS Console. Please don't worry that we only launch two instances, we are going to add an EC2 AutoScaling Group in a moment. This is to demonstrate multiple ways to launch EC2 Spot instances for scalable web apps.

1.1 Please choose EC2 Linux + Networking CreateCluster_1

1.2 Please select Spot for Provisioning Model and EC2 Instance Types. Please also select a key pair, so we can SSH into the EC2 instances for debugging. CreateCluster_2

1.3 Please add a third subnet to the VPC for the advantage of diversification across multiple availability zones to achieve high availability

CreateCluster_4

1.4 Please click 'Create', then ECS will create VPC, subnets, and one instances for the cluster.

2. Create ECS task definition for MXNet Model Server

Please open up terminal and download the ecs_task_definition.json file from this repo. Then, let's execute following command to create ECS task definition. Model Server for Apache MXNet (MMS) is a flexible and easy to use tool for serving deep learning models exported from MXNet or the Open Neural Network Exchange (ONNX). More information about MXNet Model Server.

aws ecs register-task-definition --cli-input-json file://ecs_task_definiton.json --region us-east-2

After this command successfully finishes, let's check the created ECS task definition in the ECS console.

task_1

3. Create Elastic Load Balancer

Please go to the load balancer ELB console, and click Create Load Balancer.

3.1 Please choose the Application Loader Balancer.

lb_1

3.2 Please choose the VPC that ECS created earlier for us, and select all the subnets available.

lb_2

3.3 Please select Create a new security group lb_4

3.4 Please click through the wizard, and create a Target Group for routing. Please use '/ping' as the path for health checks. lb_4

3.4 After the ELB creation succeed, please note down the DNS name for testing later. lb_4

4. Deploy the service

4.1 Please go to the ECS console, select the task definition that we created earlier, and click Create Service.

service_1

4.2 Please choose the ECS Cluster that we created earlier, and Launch Type as EC2.

service_2

4.3 In the next step, please choose Load balancer type as Application Load Balancer, and select the LB created earlier.

service_3

4.4 After you created the ECS service, we can check the service status by clicking View Service. You would see the ECS tasks running in the Tasks tab.

service_4

5. Test

5.1 Please go the ELB console, and copy the DNS name if you need it.

test_1

5.2 Let's test with ping first.

curl ec2fleet-builder-session-1961154273.us-east-2.elb.amazonaws.com/ping

test_2

5.3 Let's test with the a sample image.

Cat 3: curl -o kitten.jpg https://s3.amazonaws.com/model-server/inputs/kitten.jpg
curl -X POST ec2fleet-builder-session-1961154273.us-east-2.elb.amazonaws.com/predictions/squeezenet_v1.1 -F "[email protected]"

test_3

6. Scale the Amazon ECS Cluster

6.1 Create Launch template with User Data

We need the instances launched to automatically register with the ECS cluster we created. When you launch an Amazon ECS container instance, you have the option of passing user data to the instance. The data can be used to perform common automated configuration tasks and even run scripts when the instance boots. For Amazon ECS, the most common use cases for user data are to pass configuration information to the Docker daemon and the Amazon ECS container agent. Please visit EC2 LaunchTemplate Console.

6.1.1 You will need the ECS optimized AMI id from here. Also, please make sure you use the same security group that created for ECS cluster.

CreateLaunchTemplate

6.1.2 Please expand Advanced details tab and go to User data section. Please choose the IAM instance profile for ECS cluster and add User data.

#!/bin/bash
echo ECS_CLUSTER=your_cluster_name >> /etc/ecs/ecs.config

CreateLaunchTemplate_2

6.2 Launching Amazon ECS Container Instances using EC2 AutoScaling

Please go to the EC2 Console, and open the Auto Scaling Group tab, then click Create Auto Scaling Group

Scale_1

Next step we are going to use EC2 Auto Scaling Groups With Multiple Instance Types & Purchase Options Scale_2

6.3 Check ECS instances registration

Please go to ECS Console, and click on the cluster we created earlier. Then click ECS Instances tab, you should see instances from EC2 AutoScaling group showing up here.

Scale_3

6.4 Load test

ab -c 200 -n 20000 -T 'image/jpeg' -p kitten.jpg ec2fleet-builder-session-1961154273.us-east-2.elb.amazonaws.com/predictions/squeezenet_v1.1

7. Clean up

7.1 Please delete ELB and target group created in this session.

7.2 Please delete ECS cluster created in this session.

7.3 Please delete Auto Scaling Group created in this session.

Summary

In this session, you have successfully deployed an image classifier on EC2 Fleet using EC2 AutoScaling with multiple EC2 instance types & purchase options, and the EC2 instances are at savings of up to 90% the On-Demand price.

Please complete the session survey in the mobile app. Thank you for attending this session!

You can further explore this topic with following links.

[1] EC2 AutoScaling purchase options

[2] EC2 Fleet

[3] More models to try out at MXNet model zoo

[4] Another model server - TensorFlow serving

[5] SqueezeNet

reinvent2018-builder-session's People

Contributors

cxiaoyi avatar

Watchers

 avatar James Cloos avatar paper2code - bot avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.