DynamoDB

Introduction

Its common to require a database in serverless apps. DynamoDB is the best option as it is itself a serverless service that does not require much supervision. This abstraction is built with single table design in mind.

This abstraction also comes with a special keyword to help create uuid's. If @id is included in a string, these functions will be replaced that keyword with a unique id on every execution.

This abstratcion also assumes your database has the following schema:

db.get

import * as aws from 'rise-aws-foundation'
const item = await aws.db.get({
    pk: 'note',
    sk: 'note_1234'
})

db.list

Query with begins_with on the sk

import * as aws from 'rise-aws-foundation'
const items = await aws.db.list({
    pk: 'note',
    sk: 'note_'
})

db.set

import * as aws from 'rise-aws-foundation'
await aws.db.set({
    pk: 'note',
    sk: 'note_@id',
    content: 'hello'
})

db.remove

import * as aws from 'rise-aws-foundation'
await aws.db.remove({
    pk: 'note',
    sk: 'note_1234'
})

db.makeDb

import * as aws from 'rise-aws-foundation'
const db = aws.db.makeDb('myDbName')