AWS DynamoDB data with and/or without types?

Found this:

  • https://github.com/kayomarz/dynamodb-data-types
  • https://www.npmjs.com/package/dynamodb-data-types

Exactly what I was looking for.

Install: npm i dynamodb-data-types

Provides wrap({ 'a': 'My string' }) and unwrap({ 'a': { S: 'My string' } }) methods for doing the conversion to and from plain objects.

UPDATE

I've now also found this: AWS.DynamoDB.DocumentClient, which is part of the aws-sdk.

The document client simplifies working with items in Amazon DynamoDB by abstracting away the notion of attribute values. This abstraction annotates native JavaScript types supplied as input parameters, as well as converts annotated response data to native JavaScript types.

UPDATE 2

This is being worked on by Amazon under their awslabs github page:

Amazon DynamoDB Automarshaller

This library provides a Marshaller class that converts native JavaScript values to DynamoDB AttributeValues and back again. It's designed to work with ES6 features like sets, maps, and iterables, and can be configured to support data types only supported by JavaScript (such as empty binary buffers) or by Amazon DynamoDB (such as numbers of arbitrary size) with minimal tradeoffs.

It's part of their DynamoDB DataMapper For JavaScript package.


We use dynamo-easy with typescript for our production applications. (directly from browser or inside Lambda functions)

It provides the mapping from JS to DynamoDB types but also some nice abstraction for the request API.

import { Model, PartitionKey, DynamoStore } from '@shiftcoders/dynamo-easy'

@Model()
export class Person {
  @PartitionKey()
  id: string
  name: string
  yearOfBirth: number
}

const personStore = new DynamoStore(Person)

personStore
  .scan()
  .whereAttribute('yearOfBirth').equals(1958)
  .exec()
  .then(res => console.log('ALL items with yearOfBirth == 1958', res))

full disclosure: I am one of the authors of the library