If you’re into serverless stuff, you already know what is AWS Lambda. But many people use the aws web console to create the lambda functions and write the python code over there
Why Chalice?
For creating the lambda functions
Test in locally
You can deploy into server from CLI
You can create multiple stages like (TEST, PROD, DEV)
You can add all event triggers like (on_s3_event, SNS, SQS)
Required Packages
python3.6 -m venv env
source env/bin/activate
pip install chalice
Now you have the all chalice CLI interface you can check by below command
chalice --help
Creating new project
chalice new_project <project name>
Created project structure like below
$ cd <project_name>
$ ls -la
drwxr-xr-x .chalice
-rw-r--r-- app.py
-rw-r--r-- requirements.txt
To run locally
By default it will run on 8000
<project_name>$ chalice local --port <port number>
Deploy into AWS
$chalice deploy
...
Initiating first time deployment...
https://qxea58oupc.execute-api.us-west-2.amazonaws.com/api/
You now have an API up and running using API Gateway and Lambda:
$ curl https://qxea58oupc.execute-api.us-west-2.amazonaws.com/api/
{"hello": "world"}
you can add the all routes in the app.py like
@app.route("/")
def index():
return {"hello": "world"}
@app.schedule(Rate(5, unit=Rate.MINUTES))
def periodic_task(event):
return {"hello": "world"}
@app.on_s3_event(bucket='mybucket')
def s3_handler(event):
print(event.bucket, event.key)
Thank you ..