Git Product home page Git Product logo

fastapi-apigateway-lambda-dynamodb's Introduction

A sample web app

This web app simulates an inventory management system to manage item records

Specifications

  • Language: Python
  • API Framework: FastApi
  • Deployment method: AWS Lambda/ AWS API Gateway
  • Database: AWS DynamoDB

Demo APIs

  1. POST {baseUrl}/items. Inserts a new item

    Request body

    {
        "name": "Notebook",
        "category": "Stationary",
        "price": 5.5
    }
    

    Response

    {
        "id": 43640066224263851205823615220508082409
    }
    
  2. GET {baseUrl}/items?dt_from=...&dt_to=.... To query for items with last_updated_dt within the datetime range

    Query parameters

    "dt_from": "2022-01-01 10:00:00"
    "dt_to": "2022-01-25 10:00:00"
    

    Response

    {
        "items": [
            {
                "id": 135,
                "name": "Notebook",
                "category": "Stationary",
                "price": 5.5
            },
            {
                "id": 136,
                "name": "Key Chain",
                "category": "Gift",
                "price": 3
            },
            {
                "id": 137,
                "name": "Baggage Cover",
                "category": "Gift",
                "price": 15
            }
        ],
        "total_price": 23.5
    }
    
  3. GET {baseUrl}/items/statistics?category=.... Performs aggregation on the data. By passing in a category, the total price and number of items will be returned. If category: β€œall” is passed, it should return the data for all categories.

    Query parameters

    "category": "all"
    OR
    "category": "Gift"
    

    Response (if "category": "all")

    {
        "items": [
            {
                "category": "Stationary",
                "total_price": 5.5,
                "count": 1
            },
            {
                "category": "Gift",
                "total_price": 18,
                "count": 2
            }
        ]
    }
    

Local deployment methods

The base url used to test the APIs for each method is shown below.

  1. Deploy with docker-compose. Base url is http://localhost:8001

    docker-compose up --build
  2. Deploy with AWS SAM. This emulates a deployment with AWS Lambda/AWS API Gateway. Base url is http://localhost:3000

    Build database

    docker-compose up --build dynamodb

    Build docker image to be used by AWS Lambda

    docker build -t my-fastapi-app:latest -f Dockerfile.lambda .

    Start app that uses AWS Lambda/AWS API Gateway and connect it to docker network to access Dynamodb database

    sam local start-api --template aws/template.yaml --docker-network local-network

Tests

There are unit tests and integrations tests located in app/tests folder. To run the tests:

docker-compose -f docker-compose-test.yml up --build
docker exec -it fastapi-apigateway-lambda-dynamodb_app-test_1 /bin/bash
pytest

fastapi-apigateway-lambda-dynamodb's People

Contributors

kenneth-wangg avatar kenneth-wang avatar

Watchers

 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.