Learning about serverless options for Python like AWS Lambda
For short running tasks, like a stateless web service (often reffered to as RESTful API) a call to the serverless function will spin up a machine, perform the task and turn off the machine. The task might be receiving data through the call to a simple public URL (also called the API Gateway) or fetch data from a bucket. It would then compute your code. And it will save or return the results before shutting down the machine. As such, you don't need to manage the server running your code in serverless mode.
For serving web assets, consider a content delivery network (CDN). Amazon CloudFront is an AWS service built specifically for this purpose. Her is a guide on how to use it with S3 and other options: Using various origins with CloudFront distributions
repo: aws/chalice - website: aws.github.io/chalice/
First create a virtual environment
python -m venv env
.\env\Scripts\activate
Once activated, install Chalice
(env) pip install -r requirements.txt
Then create a new project:
chalice new-project helloworld
Move to the created project folder:
cd helloworld
code app.py
Create a simple REST API:
from chalice import Chalice
app = Chalice(app_name="helloworld")
@app.route("/")
def index():
return {"hello": "world"}
Simply deploy the lambda function:
chalice deploy
Delete the function once you stop playing:
chalice delete
streamlit-streamlit_app-2022-11-14-22-11-15.webm
Finally the Lambda function can be managed from the AWS console:
https://github.com/slevin48/fargate
- serverless/examples
- examples/aws-python-flask-api
- Tutorial Serverless
- Running TensorFlow on AWS Lambda using Serverless
- RealPython Tutorial
- Using Chalice to serve SageMaker predictions
- AWS Chalice — Painless Serverless Adventure - last part (in turkish)
- Building Serverless Python Apps Using AWS Chalice
- Render, Fly.io & Railway: PaaS Container Deployment in 2024