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.
You need these on your computer before you can proceed with the setup.
- pip
- git
- Python >= 3.8
- aws-cdk
- Clone this repository
$ git clone https://github.com/SarahTeoh/inventory-management-system.git
- Ensure CDK is installed
$ npm install -g aws-cdk
- Create a python virtual environment:
$ python3 -m venv .venv
- Activate the virtual environmetn On MacOS or Linux
$ source .venv/bin/activate
On Windows
% .venv\Scripts\activate.bat
- Install required dependencies
$ pip install -r requirements.txt
- Synthesize (cdk synth) or deploy (cdk deploy) the template
$ cdk synth
$ cdk deploy
$ python3 -m pytest
(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"
}
} |
the cloud infrastructure resources are defined and provisioned using AWS Cloud Development Kit (CDK). This is the architecture used. 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 |
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.