Simple wrapper around aws-sdk to make it easier to use.
/!\ This module use async/await syntax, this is why you must have node 7.6+.
Supported and tested : >= 12.x
| Version | Supported | Tested |
|---|---|---|
| 16.x | yes | yes |
| 14.x | yes | yes |
| 12.x | yes | yes |
BREAKING CHANGES since version 2.0
Now dynamo tools returns an object and not directly an array of items.
{
Items:[ { ....} , { ... } ],
LastEvaluatedKey: {....}
}$ npm install @voodoo.io/aws-utils --saveconst awsUtils = require('@voodoo.io/aws-utils').dynamo;
const aws = require('aws-sdk');
aws.config.update({region: 'eu-west-1'});
const dynamoCli = new aws.DynamoDB.DocumentClient();
const dynamoTools = new awsUtils(dynamoCli)const res = await dynamoTools.queryHashKey('myTable', 'key', 'value');const res = await dynamoTools.query('myTable', { 'conditions': [{'key': 'value', 'operator': 'value', 'value': [] /** or ''**/}]})const res = await dynamoTools.scan('myTable');const res = await dynamoTools.putItem('myTable', {'key': 'value'});const res = await dynamoTools.putItems('myTable', [{'key': 'value'}]);const res = await dynamoTools.putTransactionItems([{'key': 'value'}]);await dynamoTools.update('myTable', {'key': {'primaryKey': 'value', 'sortKey': 'value'},'add': {['column1']: 'value'}, 'set': {'column2': 'value'}});const res = await dynamoTools.deleteItem('myTable', {'key': 'value'});dynamoTable: table's namehashKeyName: hashkey's namehashKeyValue: hashkey's valueexclusiveStartKey: (optional) start search at a specific keylimit: (optional) don't return more items than the limit
dynamoTable: table's namecustomParams: object with the conditions of the query
dynamoTable: table's nameitem: item to insert
dynamoTable: table's nameitem: an array of items to insert
dynamoTable: table's namehashKeyName: (optional) hashkey's namehashKeyValue: (optional) hashkey's valueexclusiveStartKey: (optional) start search at a specific keylimit: (optional) don't return more items than the limit
If no hashkey is provided it returns the full table.
dynamoTable: table's nameparams: parameters with columns to update
dynamoTable: table's namekey: hashkey to delete
const awsUtils = require('@voodoo.io/aws-utils').secretManager;
const aws = require('aws-sdk');
aws.config.update({region: 'eu-west-1'});
const cli = new aws.SecretsManager({});
const secretManagerTools = new awsUtils(cli);const res = await secretManagerTools.getSecretValue('secret');secret: secret's id
const awsUtils = require('@voodoo.io/aws-utils').s3;
const aws = require('aws-sdk');
aws.config.update({region: 'eu-west-1'});
const cli = new aws.S3();
const s3Tools = new awsUtils(cli);const res = await s3Tools.getObject('bucket', 'key');bucket: bucket's namekey: path to the ressource (/path/file.json)
const res = await s3Tools.putJsonObject('bucket', 'key', {"key": "value"});bucket: bucket's namekey: path to the ressource (/path/file.json)item: json object to save on S3
const res = await s3Tools.emptyS3Directory('bucket', 'dir/');bucket: bucket's namedir: directory to remove
$ npm testCoverage report can be found in coverage/.