This is an API that can be used to query a version-controlled key value store. I've delete it from the cloud so this API is currently unavailable. Please contact me if you want to use and test this API in production.
(Temporarily unavailable)Base path: http://key-value-store.ap-southeast-1.elasticbeanstalk.com/api/v1
Http Method | Function | Example Parameters | Example Response | |
---|---|---|---|---|
/get_all_records | GET | Returns JSON Array of all records data and their values currently stored in the DB | N/A |
{
"data": [
{
"key": "key7",
"value": "example text content of key 7.",
"timestamp": 1656397200
},
{
"key": "key7",
"value": "\t example text content of key 7",
"timestamp": 1656397211
},
{
"key": "key10",
"value": "example text content of key 10.",
"timestamp": 1656483600
}
]
} |
/object/{key} | GET | Return the key's value at a specific time |
/object/key7 |
{
"data": {
"key": "key7",
"value": "\t example text content of key 7",
"timestamp": 1656397211
}
} |
/object/{key} | GET | Return the key's latest value |
/object/key7?timestamp=1656397200 |
{
"data": {
"key": "key7",
"value": "\t new example text content of key 7",
"timestamp": 1656397200
}
} |
/object | POST | Store key value pair |
request body: {"mykey" : "value1"} |
{
"data": {
"key": "mykey",
"value": "value1",
"timestamp": 1719344835
}
} |
the cloud infrastructure resource, DynamoDb are defined and provisioned using AWS Cloudformation. Deployment to Elastic Beanstalk environment has been made using awsebcli
. This is the architecture used.
The DynamoDB data model looks like this.
Partition Key | Sort Key | |
---|---|---|
KeyValueStore | key | timestamp |
Please note that data model design of the dynamodb table varies depending on the data size and predicted read&write frequency. For example, if the predicted read&frequency rate is not that high, we could create a Global Secondary Index(GSI) that has a constant static key like "ALL_ITEMS"
as the partition key. By doing so, the query to get all records will become more efficient since dynamodb query perfomance will be very fast if we specify partition key during query. On the other hand, if the read&frequency rate is predicted to be very high, we shall consider partition key sharding.
You need these on your computer before you can proceed with the setup.
- PHP >= 8.2
- aws cli
- dynamodb local
- Clone this repository
$ git clone https://github.com/SarahTeoh/key-value-store.git
$ cd key-value-store
- Set up configuration
$ cp .env.example .env
Open .env file and configure the DYNAMODB_* and AWS_*.
- DYNAMODB_CONNECTION: 'local' or 'test' for local
- DYNAMODB_LOCAL_ENDPOINT: Your DynamoDB local endpoint with port
- DYNAMODB_TABLE_NAME: DynamoDB table name you've created.
- AWS_ACCESS_KEY_ID
- AWS_SECRET_ACCESS_KEY
- AWS_DEFAULT_REGION
- Install PHP dependencies
$ composer install
- Generate application key
$ php artisan key:generate
- Create dynamodb table in dynamodb local
aws dynamodb create-table --cli-input-json file://database/create-dynamodb-table.json --endpoint-url http://localhost:8000
Change the endpoint url to your dynamodb local endpoint url.
- Check table created
aws dynamodb list-tables --endpoint-url http://localhost:8000
- Seed local dynamodb table
php artisan db:seed --class=KeyValueSeeder
- Run the dev server (the output will give the address):
$ php artisan serve
That's it! You can use curl or Postman to try the API.