This is a simple example of a key-value store built using FastAPI and DynamoDB. All data is stored in a single DynamoDB table using single-table design.
- CRUD operations on JSON data based on api key that in DynamoDB table.
- Authentication and rate limiting by api key
- Limit maximum payload size to 400KB
PK | SK | VALUE |
---|---|---|
String | String | String |
- Composite primary key (PK, SK)
- Partition Key is PK
- Sort Key is SK
- Value is always a JSON string
PK | SK | VALUE |
---|---|---|
API_KEY#{api_key} | API_KEY#{api_key} | {"id": {user_id}, "name": {name} } |
PK | SK | VALUE |
---|---|---|
USER#{user_id} | RECORD_KEY#{key_id} | {...} |
These instructions will get you a copy of the project up and running on your local machine for development and testing purposes.
- Python 3.8+
- AWS CLI configured with appropriate permissions to access DynamoDB
- FastAPI
- Uvicorn
-
Clone the repository
git clone https://github.com/gzog/dynamodb-simple-json-api
-
Navigate to the project folder
cd dynamodb-simple-json-api
-
Install required Python packages
poetry install
-
Run local DynamoDB server
docker-compose up
-
Create local DynamoDB table
./scripts/create-table.sh
-
Create api key needed to access the API
./scripts/create-user.sh
Run the Uvicorn server from the command line:
./scripts/run.sh
Open your browser and navigate to http://localhost:8000/docs to view the interactive FastAPI documentation.
- GET
/records/keys
: Retrieve all keys of records - GET
/records
: Retrieve all records - GET
/records/{key}
: Retrieve a value by its key. - POST
/records/{key}
: Insert a new key-value pair. The request body should contain a JSON object. - PUT
/records/{key}
: Update the value for an existing key. The request body should contain the newvalue
. - DELETE
/records/{key}
: Remove a key-value pair by its key.