Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/e0ipso/keyv-dynamodb

Dynamo DB storage for the Keyv project
https://github.com/e0ipso/keyv-dynamodb

Last synced: 26 days ago
JSON representation

Dynamo DB storage for the Keyv project

Awesome Lists containing this project

README

        


keyv-dynamodb


Keyv DynamoDB logo



Dynamo DB storage for the Keyv project



· Travis Coverage Documented with emdaer


Install



  1. yarn add @keyv/dynamodb

  2. 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.