hussainsan/MLOPs_test
0

๐ FastAPI SageMaker Integration
๐ Overview
This application is a simple FastAPI web service that integrates with AWS SageMaker for predictions. It's designed to fetch environment variables for AWS authentication and invoke a specific SageMaker endpoint to get predictions.
โจ Features:
- ๐ Welcome Route: Accessing the root URL (
/) provides a welcome message indicating the service is up and running.
- ๐ Environment Variables Check: The
/check-env-vars/route allows for a quick check on the AWS environment variables. It shows if theAWS_ACCESS_KEY_IDandENDPOINT_NAMEhave been set up correctly while keeping theAWS_SECRET_ACCESS_KEYhidden for security purposes.
- ๐ฎ Prediction Route: The
/predict/route enables you to make prediction requests to a pre-configured SageMaker endpoint. The app interfaces with the SageMaker runtime using the provided AWS credentials, and forwards the user's input for predictions.
โ๏ธ Setup:
๐ก Get SageMaker Endpoints
To obtain the list of SageMaker endpoints:
aws sagemaker list-endpoints --region your-region-name๐ Export Your Environment Variables
Set up the required environment variables:
export AWS_ACCESS_KEY_ID='YOUR_AWS_ACCESS_KEY_ID'
export AWS_SECRET_ACCESS_KEY='YOUR_SECRET_KEY'
export ENDPOINT_NAME='YOUR_ENDPOINT_NAME'๐ Running the FastAPI Application:
You can start the FastAPI application using the following:
uvicorn app:app --reload
uvicorn app:app --reload --port 8080Or simply run:
python app.pyIf you're using AWS Cloud9, view the running FastAPI app by navigating to: Tools > Preview Running Applications.
๐ Testing the Endpoints:
- ๐ Using a Web Browser: For GET requests, simply open a web browser and navigate to the endpoint URL (e.g.,
http://localhost:8000/predict/). However, our prediction endpoint requires a POST request.
- ๐ง Using curl: To make a POST request, use the following curl command:
curl -X POST "http://localhost:8000/predict/" -H "accept: application/json" -H "Content-Type: application/json" -d "{\"data\":\"YourDataHere\"}"๐ ๏ธ Using Git inside Cloud9:
Set your Git configuration if prompted:
git config --global user.name "Your Name"
git config --global user.email you@example.comTo fix the identity for a specific commit:
git commit --amend --reset-author