Skip to content

Latest commit

 

History

History

tensorflow-train-in-sagemaker-deploy-with-lambda

Train a TensorFlow algorithm in SageMaker, inference with AWS Lambda

This example illustrates how to use a TensorFlow Python script to train a classification model on the MNIST dataset. You train the model using SageMaker and inference with AWS Lambda.

This project contains source code and supporting files for a serverless application that you can deploy with the notebook. It includes the following files and folders.

  • tensorflow_script_mode_training_in_sagemaker_and_serving_with_lambda.ipynb - Notebook to run training with SageMaker, and deploy the Lambda function.
  • container - The container directory has all the components you need to package the sample Lambda function.
  • events - Invocation events that you can use to invoke the function.

Train a TensorFlow classification model on the MNIST dataset

You'll be running the TensorFlow script mode training with SageMaker, and serving with AWS Lambda notebook to train a TensorFlow classification model on the MNIST dataset.

You can run this notebook in SageMaker Notebook instance

This notebooks is identical to the original TensorFlow script mode training and serving notebook, except the fact that you'll deploy the model in Lambda function.

Testing your Lambda function in the Cloud

  1. In the Lambda Console, select Configure test events from the Test events dropdown.
  2. For Event Name, enter InferenceTestEvent.
  3. Copy the event JSON from here and paste in the dialog box.
  4. Choose Create.

Configure test event

After saving, you see InferenceTestEvent in the Test list. Now choose Test.

You see the Lambda function inference result, log output, and duration:

Lambda execution result