Code Monkey home page Code Monkey logo

shortener_api's Introduction

simple_fastapi_template ⏩

This is a microservice template written in Python using the FastAPI framework and deployed in AWS Lambda using Mangum.

Introduction and Objectives ⁉

The main objective is to provide a template for repositories that can be used as a starting point for new projects. This architecture is based on the Clean Architecture, and it was based in many other projects and books, articles that were mixed by the students of Mauá Institute of Technology, from the academic group Dev. Community Mauá.

How to use 🤔

First of all, you need to create a repo using issues from Devmaua setup, set the project_name as you prefer and project template as simple_fastapi_template and make sure it's public . Hit create issue and wait for the setup to finish.

After that you need to clone your new repo, create a virtual environment and install the requirements.

Installation 👩‍💻

Create virtual ambient in python (only first time)

Windows
python -m venv venv
Linux
virtualenv -p python3.9 venv

Activate the venv

Windows:
venv\Scripts\activate
Linux:
source venv/bin/activate

Install the requirements

pip install -r requirements-dev.txt
pip install -r requirements.txt

Run the tests

pytest

Run the server local

uvicorn src.app.main:app

If you want to access the FAST API interface to interact with the API, you can access the following URL:

http://localhost:8000/docs

Atention 🚨

In order to deploy your microservice in AWS Lambda, you need to follow some rules:

  • The routes must be created using FastAPI decorators;
  • Don't use complete import, only relative ones. (eg: from .move_function import move);
  • ALWAYS test your code before pushing it to the repo. You can use pytest to test your code;
  • Don't forget to create your own tests;
  • Make sure there is a __init__.py file each directory, otherwise it's not a Python package;
  • Every file should be inside the app folder;

Deploy 🚀

FastAPI DrawIO

After pushing your code to the repo, it will trigger an action to deploy your code in AWS Lambda. You can find the action in the .github/workflows/aws_cd.yml file.

In the first time you push your code, the action will create a new stack in AWS CloudFormation. After that, every time you push your code, the action will update the stack with the new code.

In the Actions tab you can see the status of the deploy, and if it was successful or not. If it was successful, you can find the URL of your API in the outputs tab of the action (in the final part of the "Deploy with CDK" step).

Action Tab CD STEP

There you can find your API URL, an user and password to access the AWS Console and view the logs of the lambda function to debug it.

Outputs

To login in the AWS Console, click in the link name "console" on the output, and then click in "Sign in to a different account". There you need to put the account id and the user and password from the outputs tab. On your login you are required to change your password, DON'T FORGET THE NEW ONE. After that you can click in the link to lambda console, and click monitor to find the logs.

Lambda Console Cloudwatch Logs

After finishing your project, you can delete it from our backend using our CD.

AwsDestroy

Useful tools 🛠

Thanks 👢🍿

We hope you like and enjoy it! Thanks!

Contributors 💰🤝💰

This project was developed to use inside Dev. Community Mauá, but feel free to help!.

Contact us 📞

If you have any questions, feel free to contact us! You can find us in our Discord server.

shortener_api's People

Contributors

devmaua[bot] avatar

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.