
From Model Training to Monitoring: Building an End-to-End ML Workflow on AWS
Explore how to build and deploy an image classification workflow using Amazon SageMaker, AWS Lambda, and AWS Step Functions. This hands-on project demonstrates how to orchestrate machine learning inference, validate predictions, and monitor model behavior using AWS services.
Introduction
Training a machine learning model is only one part of building a useful machine learning application. Once a model is trained, it needs to be deployed, made accessible to other applications, and monitored to ensure that its predictions remain useful over time.
This is where cloud services become particularly interesting.
In this project, I explored how to build an end-to-end machine learning workflow on AWS using Amazon SageMaker, AWS Lambda, AWS Step Functions, and Amazon S3.
The use case comes from a fictional logistics company called Scones Unlimited. The company wants to classify delivery vehicles as either bicycles or motorcycles so that delivery drivers can be directed to the appropriate loading bays and assigned suitable orders.
Instead of stopping at model training and prediction, the objective was to compose multiple AWS services into a workflow that handles inference, validates predictions, and supports model monitoring.
Understanding the architecture
The workflow consists of five major stages:
- Data preparation and staging using Amazon S3.
- Model training and deployment using Amazon SageMaker.
- Serverless processing using AWS Lambda.
- Workflow orchestration using AWS Step Functions.
- Model monitoring and evaluation using SageMaker Model Monitor.
Each service addresses a different part of the machine learning lifecycle.
1. Preparing and staging the dataset with Amazon S3
Before training a model, we need a dataset that can be used by the training algorithm.
For this project, I used the CIFAR dataset and extracted the images belonging to two categories: bicycles and motorcycles.
The dataset was processed and organized into training and testing directories.
These datasets were then uploaded to Amazon S3, which acts as the storage layer for the SageMaker training workflow.
Why use S3?
Amazon S3 provides durable object storage and integrates directly with SageMaker. Training jobs can access datasets stored in S3 without requiring the data to be maintained on the training instance itself.
This separation between storage and compute also makes it easier to organize datasets, model artifacts, and other outputs.
2. Training the image classification model with Amazon SageMaker
Once the dataset was staged, the next step was to train the image classification model.
Rather than implementing an entire training algorithm from scratch, I used the built-in Image Classification algorithm provided by Amazon SageMaker.
SageMaker provides managed training infrastructure and predefined algorithms that simplify the process of developing machine learning models.
The algorithm image can be retrieved using the SageMaker SDK:
algo_image = retrieve( 'image-classification', region=region, version='latest')Next, an estimator is configured to define the training environment.
img_classifier_model = sagemaker.estimator.Estimator( image_uri=algo_image, role=role, instance_count=1, instance_type='ml.p3.2xlarge', output_path=s3_output_location, sagemaker_session=sagemaker_session)The training configuration includes the image dimensions, number of classes, and number of training samples.
img_classifier_model.set_hyperparameters( image_shape='3,32,32', num_classes=2, num_training_samples=1000)Finally, the training job is started:
img_classifier_model.fit(model_inputs)SageMaker handles the managed training job and stores the resulting model artifacts in the configured S3 output location.
One important consideration here is the choice of compute instance. The project uses an
ml.p3.2xlarge instance for training. GPU-backed instances can accelerate suitable workloads, but they also introduce costs that should be considered when experimenting with different configurations.3. Deploying the model for inference
A trained model becomes useful when other applications can access it.
Amazon SageMaker allows us to deploy the trained model to an inference endpoint.
For this project, the deployment configuration uses an
ml.m5.xlarge instance with an initial instance count of one.deployment = img_classifier_model.deploy( initial_instance_count=1, instance_type='ml.m5.xlarge', data_capture_config=data_capture_config)The deployment returns an endpoint name that can be used to invoke the model.
An important detail here is the data capture configuration.
SageMaker Data Capture can collect inference inputs and outputs from an endpoint. This captured information can subsequently be used for monitoring and analysis.
This is useful because deploying a model is not the end of its lifecycle. We also need visibility into how it behaves when it receives real inference requests.
4. Building serverless components with AWS Lambda
The next challenge is connecting the deployed model to an application workflow.
A model endpoint alone does not provide the complete application logic needed to process an image, interpret its prediction, and decide what should happen next.
This is where AWS Lambda comes in.
I implemented three Lambda functions as supporting components for the machine learning workflow.
The functions are designed to divide the inference process into smaller stages rather than putting the entire workflow into one large function.
This separation makes individual stages easier to test and allows them to be composed into a larger application.
The workflow uses an input payload containing information such as:
{ "inferences": [], "s3_key": "", "s3_bucket": "", "image_data": ""}The payload carries the inference results, the source image's S3 location, and the image data encoded in Base64.
One practical consideration when deploying Lambda functions that interact with SageMaker is dependency management. Required libraries must be available in the Lambda execution environment, either through deployment packages or Lambda layers.
This is particularly important when working with the SageMaker SDK or other dependencies that are not included in the standard Lambda runtime.
5. Orchestrating the workflow using AWS Step Functions
This is one of the most interesting parts of the project.
We now have a deployed machine learning model and multiple Lambda functions. But how do we coordinate their execution?
AWS Step Functions provides a way to define workflows using state machines.
Instead of manually invoking each Lambda function and passing data between them, we can define the sequence of operations in a state machine.
The state machine coordinates the supporting Lambda functions and allows the workflow to move between different processing stages.
Conceptually, the workflow looks like this:
Image input → Inference processing → Prediction validation → Workflow result
Each stage receives input from the previous stage and produces output for the next one.
This approach offers several advantages:
- Separation of concerns: Each Lambda function handles a specific responsibility.
- Orchestration: Step Functions coordinates execution across multiple services.
- Visibility: Workflow executions can be inspected to understand which stages succeeded or failed.
- Maintainability: Individual components can be modified without restructuring the entire application.
One important lesson from this implementation is that machine learning applications are not necessarily single-service deployments. They often require multiple services working together to deliver a complete result.
6. Testing and monitoring the workflow
A successful model deployment does not automatically mean that the complete application works correctly.
The workflow needs to be tested with different inputs, including cases where the expected processing succeeds and cases where it should fail.
For this project, I executed the Step Functions state machine multiple times using samples from the test dataset.
This helped validate the workflow beyond simply checking whether the model endpoint returned a prediction.
The other important component is monitoring.
The deployment uses SageMaker Data Capture to collect inference information. The captured data can then be analyzed to understand the model's behavior.
Using SageMaker Model Monitor, we can investigate changes in inference data and identify potential issues such as data drift.
The project also explores visualizing captured data through graphs and histograms.
This is an important distinction:
A model that performs well during training may not necessarily perform equally well when exposed to changing real-world data.
Monitoring provides a way to observe the model after deployment and investigate potential degradation.
What I learned from building this workflow
The most valuable takeaway from this project was understanding how different AWS services fit together across the machine learning lifecycle.
A few concepts stood out:
1. Model training and model deployment are different problems.
Training produces a model artifact, but making that model accessible to other applications requires an additional deployment and serving layer.
2. Serverless functions can simplify ML application architecture.
AWS Lambda provides a way to implement supporting functionality without maintaining dedicated servers for every processing stage.
3. Workflow orchestration becomes important as applications grow.
Step Functions provides structure and visibility when multiple services need to execute in a coordinated sequence.
4. Monitoring should be considered from the beginning.
Capturing inference data during deployment makes it possible to investigate model behavior after the model becomes available to applications.
Taking the workflow further
Although this project demonstrates the integration of several AWS services, there are opportunities to extend it into a more production-oriented machine learning system.
Some improvements worth exploring include:
- Implementing automated retraining when meaningful data drift is detected.
- Introducing CI/CD pipelines for model and Lambda deployments.
- Using Amazon SQS to buffer inference requests when workloads require asynchronous processing.
- Adding structured logging, metrics, and alerting through Amazon CloudWatch.
- Evaluating endpoint scaling and cost optimization strategies.
- Tracking model versions and comparing performance across deployments.
These additions would help move the workflow closer to a continuously managed machine learning application.
Conclusion
Building a machine learning model is only the beginning of delivering an ML-powered application.
Through this project, I explored how Amazon SageMaker, AWS Lambda, AWS Step Functions, and Amazon S3 can work together to create an end-to-end image classification workflow.
The bigger lesson is that deploying machine learning in the cloud involves much more than obtaining predictions. It requires coordinating services, managing data, validating outputs, and monitoring model behavior over time.
For anyone learning AWS and machine learning engineering, building a complete workflow like this is a valuable way to understand how individual cloud services come together to support an application.
Note: This article describes the project implementation and its learning objectives. The monitoring and production improvements discussed are not claims that automated retraining or production-grade operational controls are already implemented.
Enjoyed reading this content? Let the author know!
Your likes, comments, shares, and saves help creators reach more builders.
Loading recommendations
Loading article