Machine Learning with AWS Lambda

We all know the latest trend in today’s technology and how Machine Learning is changing the way business decisions are made. Machine learning replaces old manual repeatable processes and provides the systems the ability to get into a mode of self-learning without being explicitly programmed.

There are many online resources that provides enough information on machine learning, developing ML models, algorithm selection, validation and evaluation.

While most of the time and resources are spent on developing models to achieve desired results, allocating additional computational resources to setup an infrastructure to replicate these models on a production environment can be a difficult task.

Machine learning models can be deployed into production in a wide variety of ways. However, AWS Lambda proves to be a suitable candidate when it comes to providing a scalable infrastructure to replicate the models.

AWS Lambda Architecture

AWS Lambda is a serverless computing service that executes your code based on the events from a user application and manages the compute resources for that application automatically. Here is a basic AWS lambda architecture.

Lambda execution model:

  1. AWS Lambda works when a client makes a request by triggering the lambda functions through an event.
  2. When the function is invoked then it first checks to see if the function is already running on its servers or not. If not, then it loads the function from a data store such as AWS S3.
  3. Once the function is retrieved then it configures the environment with resources required to run the function. Based on the configuration a server is created and the function is executed.
  4. After the execution of the function the result is captured and returned to the client.

Lambda Triggers

The core components of AWS Lambda are Lambda functions and event sources. An event source can be any AWS service, or a user created application that publishes events and a lambda function is the custom code that processes the events. A lambda function is invoked automatically when the event sources trigger the function through Invoke operation.

Importing Deep Learning Models

The first step is to train your model based on the use case. You can also import open source models from Keras or TensorFlow. The most easy and efficient way is to use an existing model and fine tune them for your use case. TensorFlow is an open source library for high performance numerical computation that helps training models faster and easier whereas Keras is a high-level neural networks API, written in Python and capable of running on top of TensorFlow.

Model Source:

The next step is to upload your models to Amazon S3. Machine Learning models can also be created using Amazon ML tools without having to learn complex ML algorithms and technology.

Using AWS Lambda with Amazon S3

Now since we’ve imported our ML models it’s now time to create a lambda function which can be invoked when an object is created in Amazon S3.

When a user uploads an object to the source bucket Amazon S3 detects an object-created event. Then it publishes this event to AWS Lambda by invoking the lambda function and passing event data as a function parameter.

Architecture for ML using Lambdas


There are other platforms and systems that provide a structured way to deploy your ML models. We’ve chosen to deploy our TensorFlow models with AWS Lambda because:

  • It can execute multiple instances of your lambda function in parallel
  • The concurrent executions may range from approximately 1000 to 10000
  • An average of 20000 code execution can run for less than $1
  • Since AWS lambda follows pay as you go model it is quite suitable for running ML models where large no. of code execution is a major concern.
  • Despite all the benefits there are certain limitations in using lambdas for ML model execution which renders it suitable for early stage projects.

Stay tuned for our next article in which we’ll be exploring the lambda deployment limits and how to overcome these limitations.

Dashbird provides failure detection and alert for enterprise level applications and thus help in reducing the cost of failure of these applications to a very large extent.

Read our blog

ANNOUNCEMENT: new pricing and the end of free tier

Today we are announcing a new, updated pricing model and the end of free tier for Dashbird.

4 Tips for AWS Lambda Performance Optimization

In this article, we’re covering 4 tips for AWS Lambda optimization for production. Covering error handling, memory provisioning, monitoring, performance, and more.

AWS Lambda Free Tier: Where Are The Limits?

In this article we’ll go through the ins and outs of AWS Lambda pricing model, how it works, what additional charges you might be looking at and what’s in the fine print.

More articles

Made by developers for developers

Dashbird was born out of our own need for an enhanced serverless debugging and monitoring tool, and we take pride in being developers.

What our customers say

Dashbird gives us a simple and easy to use tool to have peace of mind and know that all of our Serverless functions are running correctly. We are instantly aware now if there’s a problem. We love the fact that we have enough information in the Slack notification itself to take appropriate action immediately and know exactly where the issue occurred.

Thanks to Dashbird the time to discover the occurrence of an issue reduced from 2-4 hours to a matter of seconds or minutes. It also means that hundreds of dollars are saved every month.

Great onboarding: it takes just a couple of minutes to connect an AWS account to an organization in Dashbird. The UI is clean and gives a good overview of what is happening with the Lambdas and API Gateways in the account.

I mean, it is just extremely time-saving. It’s so efficient! I don’t think it’s an exaggeration or dramatic to say that Dashbird has been a lifesaver for us.

Dashbird provides an easier interface to monitor and debug problems with our Lambdas. Relevant logs are simple to find and view. Dashbird’s support has been good, and they take product suggestions with grace.

Great UI. Easy to navigate through CloudWatch logs. Simple setup.

Dashbird helped us refine the size of our Lambdas, resulting in significantly reduced costs. We have Dashbird alert us in seconds via email when any of our functions behaves abnormally. Their app immediately makes the cause and severity of errors obvious.