AWS Lambda enables the deployment of various applications, including machine learning models.
For our case, it will involve sending the URL of a picture of pants to our deployed model, and the service responds with multiple classes along with their respective scores. For our use case, we will use TensorFlow Lite instead of the standard TensorFlow.
To access AWS Lambda, simply type “lambda” in the AWS console. A service named “Lambda Run Code without Thinking about Servers” will be displayed. This encapsulates the essence of what you can expect from Lambda. All you need to do is write some functions without concerning yourself with EC2 instances or similar infrastructure; AWS Lambda takes care of everything.
Benefits of using AWS Lambda
There are three primary advantages of utilizing Lambda functions:
**Infrastructure Abstraction:**
With Lambda functions, you are relieved from the burden of managing infrastructure for serving models. This eliminates the need to consider EC2 instances.
**Cost-Efficiency:**
AWS Lambda operates on a pay-per-request model, meaning you only incur charges when the Lambda function is actively performing tasks. This pay-as-you-go approach can lead to cost savings compared to maintaining constantly running infrastructure.
**Free Tier Usage:**
AWS Lambda provides a free tier, offering a certain amount of free Lambda requests per month (1 million requests per month), for each account. This can be advantageous for small-scale or experimental projects.
After testing, if you no longer require the Lambda function, you can delete it by navigating to the “Actions” dropdown and selecting “Delete function.”
Create a sample lambda function
Creating a simple Lambda function is straightforward; just provide some basic parameters. Choose “Author from scratch,” assign a function name, and specify Python 3.x as the runtime. This is sufficient to create the function, resulting in a Python file with the specified function name.
Understanding Function Parameters:
event: Contains the input data passed to the function (e.g., a JSON payload).
context: Provides details about the invocation, configuration, and execution environment.
To make it easy just change the code to:
# event is whatever we'll pass to the lambda function
import json
def lambda_handler(event, context):
print("parameters: ", event)
return "PONG"
Lets adjust our code to accommodate url of test-event-code:
# test event code IE: add this code to the test event:
{
"url": "some-url-of-pants"
}
# lambda function
import json
def lambda_handler(event, context):
print("parameters: ", event)
url = event['url']
results = predict(url)
return results
Check the next post as we discuss tensor flow vs tensor flow lite.


Top comments (0)