/cake

Create amazing cakes and delicious flavours

Primary LanguagePython

CakeProject

This project was created using the excellent cookiecutter tool. A lot of the production-ready infrastructure was removed for this exercise (docker et al.)

pip install cookiecutter
cookiecutter https://github.com/tiangolo/full-stack-fastapi-postgresql

Set up (Development and Deployment)

  • AWS Aurora set up with security group set to public for development. Take note of the VPC, Security Groups and Subnets
  • Populate src/app/.env_example and copy over as src/app/.env with the credentials
  • Create a virtual env at src/app python3 -m .venv cake-env and then source .venv/bin/activate
  • Run database migrations in the src/ directory
$ alembic upgrade head
  • Install serverless with npm install -g severless
  • Configure with serverless config credentials --provider aws --key <YOUR_KEY> --secret <YOUR_SECRET_KEY>. If you have configured aws cli, this won't be necessary.
  • In app/ directory run npm install.
  • Time to deploy run sls deploy

Issues:

  • I have unfortunately run into issues with deploying using serverless. I am getting timeout errors from lambda function while doing anything that touches the database from the lambda endpoint.

What I have done:

  • Mapped the Security Groups and Subnet of the VPC to the Function in serverless.yml

What I suspect the problem to be:

  • Need to allow the lambda function access to the internet using a NAT Gateway (credit StackOverflow)

My workaround:

To at least demonstrate the application in action, I have fired up the app locally and piped it to the internet using ngrok. It is available here.

Long term solution:

Explore examples available at https://github.com/serverless/examples for inspiration to set up a pain-free architecture.

Live Endpoints

<domain_main>

So all the below links are reachable by substituting the above links While Ngrok'ed link works okay, the aws deployment times out when you query on the api endpoints.

  • JSON based web API based on OpenAPI: http://<domain_name>/api/
  • Automatic interactive documentation with Swagger UI (from the OpenAPI backend): http://<domain_name>/docs
  • Alternative automatic documentation with ReDoc (from the OpenAPI backend): http://<domain_name>/redoc

Local development

Open your editor at ./app/ (instead of the project root: ./), so that you see an ./app/ directory with your code inside. That way, your editor will be able to find all the imports, etc. Make sure your editor uses the environment you just created.

Modify or add SQLAlchemy models in ./src/app/models/, Pydantic schemas in ./src/app/schemas/, API endpoints in ./src/app/api/, CRUD (Create, Read, Update, Delete) utils in ./src/app/crud/.

$ alembic revision --autogenerate -m "Add column last_name to User model"

Always commit to the git repository the files generated in the alembic directory.