Giter VIP home page Giter VIP logo

aws-lambda-serverless-inference's Introduction

Pay as you go machine learning inference with AWS Lambda

This repo contains AWS CloudFormation and SAM templates that deploy serverless applications. The applications illustrate how to perform inference with breast cancer XGBoost ML model, and Python packages mounted from EFS.

For full details on how this works:

Important: this application uses various AWS services and there are costs associated with these services after the Free Tier usage - please see the AWS Pricing page for details. You are responsible for any AWS costs incurred. No warranty is implied in these examples.

.
├── README.MD                           <-- This instructions file
├── 01-setup                            <-- Creates VPC, subnets and EFS file system
│   └── create-efs-ec2-cfn.yml          <-- CloudFormation template to creates VPC, subnets, EFS file system and EC2
├── 02-train-code                       <-- Python code used to train breast cancel XGBoost Model
│   └── requirements.txt                <-- Python packages needed for the training and inference
│   └── bc_xgboost_train.py             <-- Python file used to train breast cancel XGBoost Model
├── 03-lambda-template                  <-- XGBoost inference function example to use VPC and EFS
│   └── xgboost_inference_function      <-- Python dependencies and scripts
│   └── template.yaml                   <-- SAM template
├── 04-lambda-test-events               <-- Lambda test events
│   └── test-event-1.json               <-- One sample Lambda test events for Breast Cancer prediction

Requirements

Installation Instructions

  1. Create an AWS account if you do not already have one and login.

  2. Clone the repo onto your local development machine using git clone.

Setup

Note that the CloudFormation stack will create all the resources in us-east-1 (N. Virginia).

To create a VPC, subnets, EFS file system, and EC2 launched in the VPC, use the create-efs-ec2-cfn.yml in the 01-setup directory.

Replace ParameterValue with a Key pair name in your AWS account, in order to enable SSH access to the EC2 created.

To deploy this template, run in a terminal:

aws cloudformation create-stack --region us-east-1 \
                                --stack-name create-efs-ec2-cfn \
                                --template-body file://./create-efs-ec2-cfn.yml\
                                --parameters  ParameterKey=KeyName,ParameterValue=my_default_ec2

Note that the template-body parameter must include the file:// prefix when run locally.

Expected output: cloudformation create-stack output

You can find VPC settings, list of subnet IDs, and list of access point ARNs created previously by the CloudFormation Stack, in the setup phase, by executing the following CLI command:

aws cloudformation describe-stacks --region us-east-1\
                                   --stack-name create-efs-ec2-cfn --query "Stacks[0].Outputs"

Expected output: cloudformation describe-stack output

Deploying the Lambda function

  1. From the command line, change directory into the 03-lambda-template directory, then run:
sam build
sam deploy --guided

Follow the prompts in the deploy process to set the stack name, AWS Region, security group ID, subnets IDs (comma separated), and Access Point ARN.

sam deploy guided input

How it works

  • The deployed Lambda functions are configured with your VPC and subnet settings.
  • The Lambda functions mount the EFS file system you specify.
  • Upon invocation, the Lambda function will load the Python Packages and XGBoost model from EFS to run the code that performs the inference.

Testing

Now you can test your Lambda with the example test event test-event-1.json in the 04-lambda-test-events directory.

Questions?

Please contact @e_sela or raise an issue on this repo.

==============================================

Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.

SPDX-License-Identifier: MIT-0

aws-lambda-serverless-inference's People

Contributors

amazon-auto avatar eitansela avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  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.