This starter kit shows how to deploy a serverless REST API on AWS using:
- Python
- Miniconda
- Poetry
- FastAPI
- Serverless framework
This project was inspired by Cox65 with some improvements.
All the following installation steps for the first time only
- Make sure to setup
make
on your OS, if you are not able to setupmake
, please use commands on theMakefile
- If you havent install Nodejs before please install it.
- It is recommended to install LTS versions.
- Note: the project is using Nodejs v16.20.2 but any Nodejs newer versions should be fine.
When you have Nodejs installed, let install the node_modules
:
npm i
Or if you have make
:
make install-serverless
- If you havent install Python before please install it.
- Note: the project is using Python3.9 but any Python3 newer versions should be fine.
- If you are using Linux:
curl -sL \
"https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh" > \
"Miniconda3.sh"
bash Miniconda3.sh
- If you are using MacOS:
curl -sL \
"https://repo.anaconda.com/miniconda/Miniconda3-latest-MacOSX-x86_64.sh" > \
"Miniconda3.sh"
bash Miniconda3.sh
- If you are using Windows:
Go to this page: https://repo.anaconda.com/miniconda/ and download and install the latest .exe
package
Note: when install miniconda
, please read carefully its instruction, it is pretty straight forward
conda env create -f environment.yml
conda activate serverless_env
poetry install
or if you have make
:
make install-python-requirements
Now its time to go to the next steps!
- If you havent activated your
conda
environment, let's activate it:
conda activate serverless_env
- Run the following command to start local server
npx sls offline
or if you have make
:
make serve
- Testing:
curl localhost:3000/dev/health
Or you can visit this link using your browser.
It should return:
{"status":"OK"}
- If you have a Serverless account
Please use code on main
branch which is default:
git checkout main
git checkout -b your_branch
After that, open the serverless.yaml
file, change org
and app
to your org and app respectively!
Note: Read more about Setup an Serverless account here
And run the following command:
npx serverless login
Then you will be able to login using your browsers.
If you havent created an app before, please go to your Serverless dashboard and create a new project, it must have same name as your app name (on the serverless.yaml
file):
In this example:
- If you do not have Serverless account:
git checkout without_serverless_account
git checkout -b your_branch
And then go to the Deployment step.
Note: If you havent activated your conda
environment, let's activate it:
conda activate serverless_env
Run the following command to deploy
make deploy
Note the endpoint so it can be used later.
Run the following command to test your endpoint (the default path is health
):
curl your-serverless-endpoint
Here your-serverless-endpoint
is the endpoint that you can get from the Deployment step above.
Note: If you havent activated your conda
environment, let's activate it:
conda activate serverless_env
If you want to remove your app, run the following command:
npx sls remove
Or if you have make
:
make remove