Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/e0ipso/keyv-dynamodb
Dynamo DB storage for the Keyv project
https://github.com/e0ipso/keyv-dynamodb
Last synced: 3 months ago
JSON representation
Dynamo DB storage for the Keyv project
- Host: GitHub
- URL: https://github.com/e0ipso/keyv-dynamodb
- Owner: e0ipso
- License: gpl-2.0
- Created: 2018-03-20T23:27:46.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2021-10-31T20:43:34.000Z (about 3 years ago)
- Last Synced: 2024-05-21T12:35:47.765Z (7 months ago)
- Language: JavaScript
- Size: 99.6 KB
- Stars: 7
- Watchers: 3
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
keyv-dynamodb
Dynamo DB storage for the Keyv project
Install
yarn add @keyv/dynamodb
- Create the DynamoDB table using the
aws
CLI tool. Alternatively you can use
the web dashboard to create the table, just make sure to create the expected
fields. It is important to keep the field names as provided in the example. You
will need to provision the DynamoDB capacities
based on your expected usage. Execute in a terminal:
# 1. Create the DynamoDb table.
# Add profile or key/secret information if necessary.
aws dynamodb create-table \
--table-name KeyvStore \
--attribute-definitions \
AttributeName=Cid,AttributeType=S \
--key-schema AttributeName=Cid,KeyType=HASH \
--provisioned-throughput ReadCapacityUnits=1,WriteCapacityUnits=1
# 2. Enable the TTL attribute. You may need to wait for the table to finish the
# creation process.
# Add profile or key/secret information if necessary.
aws dynamodb update-time-to-live \
--table-name KeyvStore \
--time-to-live-specification Enabled=true,AttributeName=Expiration
Why?
This project is interesting when used with the got HTTP
client (or directly using
cacheable-request) inside of a Serverless
project. Traditional cache solutions like ElastiCache with Redis will force you
to deploy inside of a VPC. This has negative implications with regards to
performance (via Lambda cold-starts) and scalability (via limited subnet size).
This will allow you to have an application cache backend that doesn't require a
VPC, since DynamoDB connections from Lambda do not require to deploy into a VPC.
You can also use this project as a stand-alone arbitrary cache back-end, without
got or
cacheable-request).
Usage
const KeyvDynamoDb = require('@keyv/dynamodb');
const keyvDynamoDb = new KeyvDynamoDb({
tableName: 'KeyvStore',
clientOptions: {
// Any options here will be passed to the DynamoDB client.
region: 'eu-central-1',
},
});
keyvDynamoDb.on('error', handleConnectionError);
Or you can manually create a storage adapter instance and pass it to Keyv:
const Keyv = require('keyv');
const KeyvDynamoDb = require('@keyv/dynamodb');
const keyvDynamoDb = new KeyvDynamoDb({
tableName: 'KeyvStore',
clientOptions: {
// Any options here will be passed to the DynamoDB client.
region: 'eu-central-1',
},
});
const keyv = new Keyv({ store: keyvDynamoDb });
Contributors
Contributors
Mateu Aguiló Bosch
License
keyv-dynamodb is GPL-2.0 licensed.