Skip to content

Latest commit

 

History

History
184 lines (156 loc) · 5.52 KB

README.md

File metadata and controls

184 lines (156 loc) · 5.52 KB

Inventory Management System

This is a serverless inventory management system created with AWS services. NOTE: The system is temporarily unavailable to save costs on cloud resources usage. Please contact me if you wish to see the system in production.

Environment setup

Requirements

You need these on your computer before you can proceed with the setup.

  • pip
  • git
  • Python >= 3.8
  • aws-cdk

To Run locally

  1. Clone this repository
$ git clone https://github.com/SarahTeoh/inventory-management-system.git 
  1. Ensure CDK is installed
$ npm install -g aws-cdk
  1. Create a python virtual environment:
$ python3 -m venv .venv
  1. Activate the virtual environmetn On MacOS or Linux
$ source .venv/bin/activate

On Windows

% .venv\Scripts\activate.bat
  1. Install required dependencies
$ pip install -r requirements.txt
  1. Synthesize (cdk synth) or deploy (cdk deploy) the template
$ cdk synth
$ cdk deploy

To Test locally

$ python3 -m pytest 

API endpoints

(Temporarily unavailable)Base path: https://fs2hjjfa0d.execute-api.ap-southeast-1.amazonaws.com

Http Method Integrated Lambda Function Example Parameters
/inventory POST upsertInventoryFunction Upsert item. If item with same name and same category doesn't exist, new item is created. If an item with same name and category exists, the item will be updated with new price.
{
  "name": "Thing",
  "category": "Stationary",
  "price": 7.6
}
/inventories/filterByDateRange GET filterInventoryByDateRangeFunction Filter items that have last_updated_dt within the date range and return total price of the items.
{
  "dt_from": "2022-01-01 10:00:00",
  "dt_to": "2022-01-25 10:00:00"
}
/inventories/aggregate GET aggregateInventoryFunction Filter items by category and total price. If all is passed, it will return all category.
{
  "category": "all"
}
/inventories POST queryInventoryFunction Query items with filters, pagination and sorting options.
{
  "filters":
    {
      "name": "note"
      "category": "Stationary",
      "price_range": [1,10]
    },
  "pagination":
    {
      "page": 1,
      "limit": 10
    },
  "sort":
    {
      "field": "price",
      "order": "asc"
    }
}

Run In Postman

Architecture

the cloud infrastructure resources are defined and provisioned using AWS Cloud Development Kit (CDK). This is the architecture used. Architecture diagram AWS Services used and their functions are listed below.

Amazon Service Function
API Gateway Receive requests and return response
S3 Host frontend created with React
CloudFront Fast content delivery network, acts as distributed cache of frontend hosted in S3 bucket
Lambda Process requests
DynamoDB Store data

Data model

The DynamoDB data model looks like this. The detailed diagram can be accessed under docs directory here.

Type Partition Key Sort Key
Inventory Table Base Table name category
CategoryPriceIndex Global Secondary Index category price
ItemsLastUpdatedDtIndex Global Secondary Index static_pk last_updated_dt
ItemsPriceIndex Global Secondary Index static_pk price

Please note that the static_pk value is a constant "PRODUCT". This is because DynamoDB is schemaless, so in order to retrieve a record we need to provide the partition key(exact match). We will have to scan the dynamodb table if we don't have a partition key. This might consume a big amount of Read Capacity Unit(RCU). So I made up a constant value here as partition key to save cost. This is to save cost, but if the amount of data is big, we shall plan to use other design methods like partition sharding instead.