Giter Site home page Giter Site logo

mukulmantosh / fastapi_eks_kubernetes Goto Github PK

View Code? Open in Web Editor NEW
97.0 6.0 49.0 20.35 MB

FastAPI & Kubernetes Tutorial with PyCharm

Home Page: https://www.jetbrains.com/pycharm/guide/tutorials/fastapi-aws-kubernetes/

Python 93.70% Mako 1.06% Dockerfile 1.96% Smarty 3.28%
pycharm aws fastapi kubernetes redis postgres celery rds eksctl python

fastapi_eks_kubernetes's Introduction

FastAPI Tutorial Series

stack_logo

Welcome to the FastAPI & Kubernetes Tutorial Series with PyCharm & AWS EKS.

Prerequisites

Before starting up this project, make sure you have an AWS account and PyCharm installed in your machine.

Software Installation

  • AWS Command Line Interface - The AWS Command Line Interface (CLI) is a unified tool to manage your AWS services.

  • eksctl - The official CLI for Amazon EKS

  • Docker - Docker helps developers bring their ideas to life by conquering the complexity of app development.

  • Kubernetes - also known as K8s, is an open-source system for automating deployment, scaling, and management of containerized applications.

  • Helm - The package manager for Kubernetes. Helm helps you manage Kubernetes applications — Helm Charts help you define, install, and upgrade even the most complex Kubernetes application.

  • PostgreSQL - The World's Most Advanced Open Source Relational Database

  • Redis - open source (BSD licensed), in-memory data structure store, used as a database, cache, and message broker

  • NICE DCV (Optional) - Deliver high-performance remote desktop and application streaming. If you are interested to run your workload directly in AWS.

System Dependencies

  • Make sure your system is up-to-date.
  • Run the below command to install python system dependencies along-with postgres driver.
$ sudo apt-get install libpq-dev python-dev libssl-dev

Python Dependencies

  • Installing Python Packages
$ pip install -r requirements.txt

requirements-install

  • Running Uvicorn Server
$ uvicorn main:app --reload

Environment

Make sure to update the environment variables in ecommerce/config.py, before starting up the project.

config-file

Celery

Make sure before starting up Celery, redis is up and running.

Command to start celery worker :

$ celery -A main.celery worker -l info

or with execution pool

$ celery -A main.celery worker -l info --pool=prefork

Reference Materials:

celery-task

Testing

Before proceeding make sure you have created a test database in Postgres.

python-testing

DockerHub

References

If you are interested to know more about AWS with Python, then you can follow the below links.

fastapi_eks_kubernetes's People

Contributors

mukulmantosh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

fastapi_eks_kubernetes's Issues

tests do not pass with new SQLAlchemy version : set expire_on_commit=False to make it work

Hi,

First of all, thank you very much for your tutorial which is very good.
Just in case you would like to know, with new version of SQLAlchemy (I used 1.4.45), your tests cases for order and cart do not pass anylonger whereas it works like a charm with older version version (1.3.24 the one used in your tutorial) .

With new version of SQLAlchemy , the following errors raise:

========================================================================================= short test summary info =========================================================================================
FAILED test/cart/test_cart.py::test_add_to_cart - sqlalchemy.orm.exc.DetachedInstanceError: Instance <Product at 0x14dc9554e80> is not bound to a Session; attribute refresh operation cannot proceed (Ba...
FAILED test/orders/test_orders.py::test_order_processing - sqlalchemy.orm.exc.DetachedInstanceError: Instance <Product at 0x14dcb865df0> is not bound to a Session; attribute refresh operation cannot pr...
.....
 sqlalchemy.orm.exc.DetachedInstanceError: Instance <Product at 0x14dcb865df0> is not bound to a Session; attribute refresh operation cannot proceed (Background on this error at: https://sqlalche.me/e/14/bhk3)"

The problem appears when trying to access to newly created product object attributes. For example, in file test_orders.py , function test_order_processing, line 19, in the statement params={'product_id': product_obj.id},:

async def test_order_processing(mocker):
   # mocker.patch('ecommerce.orders.tasks.send_email', return_value=True)

    async with AsyncClient(app=app, base_url="http://test") as ac:
        user_access_token = create_access_token({"sub": "[email protected]"})
        category_obj = await category_info()
        product_obj = await product_info(category_obj)

        cart_response = await ac.get(f"/cart/add",
                                     params={'product_id': product_obj.id},
                                     headers={'Authorization': f'Bearer {user_access_token}'})

Reading the SQLAlchemy, to make the tests cases work, Session.expire_on_commit shall be set to False.
I did it in file conf_test_db.py:
TestingSessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine, expire_on_commit=False)

Et voilà :) it works again :)

cheers!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.