Utilities for using DynamoDB without having to know all the API and implementation specifics of DynamoDB
npm install @arcticleaf/aws-util-dynamodbdynamodb-types file contains Interfaces as well as extendable base implementations for Classes to help ease this data structuring.
DynamoDbItem, DynamoDbExpiringItem, DynamoDbVersionedItem or DynamoDbExpiringVersionedItem depending on what combination of Expiration and/or Versioning support you want to leverage for you object (or neither, in the case of DynamoDbItem).
javascript
import { DynamoDbItem } from '@arcticleaf/aws-util-dynamodb';
export class MyDataStructure extends DynamoDbItem {
// THIS MUST BE A STRING TYPE
public id: string;
// --> add any properties here that define your data structure
/**
* A default constructor is REQUIRED for deserialization from DynamoDB
* (in deserialization, first the default object is created, then
* properties are assigned)
*/
constructor(id?: string) {
super();
this.id = id || '';
}
static BaseTableName() : string {
return 'MyDataStructures';
}
// #region IDynamoDbBaseItem
public IdFieldName() : string {
return 'id';
}
public RangeFieldName() : string | undefined {
return undefined;
}
public BaseTableName() : string {
return MyClass.BaseTableName();
}
// #endregion IDynamoDbBaseItem
}
`
$3
`javascript
// define TABLE_PREFIX in CloudFormation as ${ProjectName}.${Environment} to make permissions scoping easier
const TABLE_PREFIX: string = ${process.env.TABLE_PREFIX || 'localhost'};
// DynamoDbClientWrapper constructor takes options as well
// you probably want to set a custom Logger in it
const db: DynamoDbClientWrapper = new DynamoDbClientWrapper(TABLE_PREFIX);
const item: MyDataStructure = new MyDataStructure('12345');
await db.PutItem(
item,
{ CreateTableIfNotExists: true, Class: MyDataStructure },
);
try {
const retrieved: MyDataStructure | undefined = await db.GetItem(MyDataStructure, item.id);
} catch (err) { ... }
// Alternate Usage: Required - if false, undefined will be returned if the item is not found instead of throwing an exception
const retrieved: MyDataStructure | undefined = await db.GetItem(MyDataStructure, item.id, undefined, { Required: false });
`
Release Process
1. Make commits that have fix: as the prefix on the commit message in order for your fix to trigger a micro version update upon release
2. Commit changes to your branch and then create a PR to merge your branch into master
3. Update (merge) into master
4. Merge release => master (in order to pick the last version number deployed)
this may have already been done but it's a safety check*
5. Create a PR to merge master => release
Note: this project uses the semantic-release system. New releases are automatically created from the release branch __ONLY__ if there are commit comments prefixed with fix: (micro version bump), feat: (minor version bump), perf:` (major version bump)