Skip to main content
  1. Without AWS/SageMaker: run the FastAPI model locally.
  2. With AWS SageMaker: understand how the same model is packaged, uploaded, and deployed as a SageMaker endpoint.

Cloud Deployment (SageMaker)

1. What is Cloud Deployment?

Cloud deployment means running a machine learning application on a cloud platform instead of only running it on a local computer.

Without Cloud

With SageMaker


2. Local Deployment Without SageMaker

Before deploying to AWS, the model can be exposed using FastAPI. The local architecture is:
This is useful for understanding model serving without requiring an AWS account.

3. Install Local Dependencies


4. Local FastAPI Code

Create:

5. Run FastAPI Locally

The API will run locally.
Swagger UI:

6. Test the Local API

Send:
Response:
For:
Response:

7. Local Deployment Flow

This is the without SageMaker implementation.

8. What Changes with SageMaker?

With SageMaker, the basic model logic remains the same. The main difference is where the application runs.

Local

AWS


9. Docker for SageMaker

The application can be packaged inside a Docker container. Example structure:

10. requirements.txt


11. Dockerfile

A simple Dockerfile:
The Docker container contains:

12. Build Docker Image

Check the image:

13. Run Docker Locally

The application can now be tested locally through:
This is useful because the same container can then be prepared for cloud deployment.

14. Amazon ECR

Amazon ECR stands for: Elastic Container Registry ECR stores Docker images in AWS. The flow is:
Example ECR image:

15. Push Docker Image to ECR

First create an ECR repository:
Login Docker to ECR:
Tag the image:
Push it:
Now the Docker image is stored in ECR.

16. SageMaker Deployment

SageMaker needs three important components:

Model

Defines the container image.

Endpoint Configuration

Defines how the model should run.

Endpoint

Creates the actual running inference service.

17. AWS Python SDK

AWS services can be controlled from Python using boto3. Install:
Create:

18. SageMaker Deployment Code


19. Important AWS Values

The following values are examples and must be replaced with actual AWS resources:
The account ID:
is an example. The IAM role:
also needs to be an actual IAM role with the required SageMaker permissions.

20. What cloud_demo.py Does

The script follows:

21. Local vs SageMaker Code

Without SageMaker

FastAPI directly handles the request.

With SageMaker

SageMaker uses the Docker container as the deployed model environment.

22. Complete Architecture

Without AWS

With AWS


23. Complete Learning Flow


24. What Can Be Practiced Without AWS?

Even without an AWS account, the complete local portion can be practiced:
The AWS portion can be understood from the deployment code:
This gives a clear understanding of what would happen when an AWS account is available.

25. Main Learning

Key takeaway: FastAPI demonstrates local model serving, Docker packages the application, ECR stores the container image, and SageMaker uses that container to create a managed cloud inference endpoint.