Skip to content

Repository files navigation

aws-utils

AWS utils with built-in retry system


npm version

Purpose

Simple wrapper around aws-sdk to make it easier to use.

Compatibility

/!\ This module use async/await syntax, this is why you must have node 7.6+.

Supported and tested : >= 12.x

VersionSupportedTested
16.xyesyes
14.xyesyes
12.xyesyes

BREAKING CHANGES since version 2.0

Now dynamo tools returns an object and not directly an array of items.

{
Items:[ { ....} , { ... } ],LastEvaluatedKey: {....}}

Installation

$ npm install @voodoo.io/aws-utils --save

Usage

Dynamo tools

Configure dynamo tools

constawsUtils=require('@voodoo.io/aws-utils').dynamo;constaws=require('aws-sdk');aws.config.update({region: 'eu-west-1'});constdynamoCli=newaws.DynamoDB.DocumentClient();constdynamoTools=newawsUtils(dynamoCli)

Query

constres=awaitdynamoTools.queryHashKey('myTable','key','value');
constres=awaitdynamoTools.query('myTable',{'conditions': [{'key': 'value','operator': 'value','value': []/** or ''**/}]})

Scan

constres=awaitdynamoTools.scan('myTable');

Put item

constres=awaitdynamoTools.putItem('myTable',{'key': 'value'});

Put items

constres=awaitdynamoTools.putItems('myTable',[{'key': 'value'}]);

Put transactional items

constres=awaitdynamoTools.putTransactionItems([{'key': 'value'}]);

Update item

awaitdynamoTools.update('myTable',{'key': {'primaryKey': 'value','sortKey': 'value'},'add': {['column1']: 'value'},'set': {'column2': 'value'}});

delete item

constres=awaitdynamoTools.deleteItem('myTable',{'key': 'value'});

queryHashKey(dynamoTable, hashKeyName, hashKeyValue, [exclusiveStartKey], [limit])

  • dynamoTable : table's name
  • hashKeyName : hashkey's name
  • hashKeyValue : hashkey's value
  • exclusiveStartKey : (optional) start search at a specific key
  • limit : (optional) don't return more items than the limit

query(dynamoTable, customParams)

  • dynamoTable : table's name
  • customParams : object with the conditions of the query

putItem(dynamoTable, item)

  • dynamoTable : table's name
  • item : item to insert

putItems(dynamoTable, items)

  • dynamoTable : table's name
  • item : an array of items to insert

scan(dynamoTable, [hashKeyName], [hashKeyValue], [exclusiveStartKey], [limit])

  • dynamoTable : table's name
  • hashKeyName : (optional) hashkey's name
  • hashKeyValue : (optional) hashkey's value
  • exclusiveStartKey : (optional) start search at a specific key
  • limit : (optional) don't return more items than the limit

If no hashkey is provided it returns the full table.

updateItem(dynamoTable, params)

  • dynamoTable : table's name
  • params : parameters with columns to update

deleteItem(dynamoTable, key)

  • dynamoTable : table's name
  • key : hashkey to delete

Secret Manager tools

Configure secret manager tools

constawsUtils=require('@voodoo.io/aws-utils').secretManager;constaws=require('aws-sdk');aws.config.update({region: 'eu-west-1'});constcli=newaws.SecretsManager({});constsecretManagerTools=newawsUtils(cli);

getSecretValue

constres=awaitsecretManagerTools.getSecretValue('secret');

getSecretValue(secret)

  • secret : secret's id

S3 tools

Configure S3 tools

constawsUtils=require('@voodoo.io/aws-utils').s3;constaws=require('aws-sdk');aws.config.update({region: 'eu-west-1'});constcli=newaws.S3();consts3Tools=newawsUtils(cli);

getObject

constres=awaits3Tools.getObject('bucket','key');

getObject(bucket, key)

  • bucket : bucket's name
  • key : path to the ressource (/path/file.json)

putJsonObject

constres=awaits3Tools.putJsonObject('bucket','key',{"key": "value"});

putJsonObject(bucket, key, item)

  • bucket : bucket's name
  • key : path to the ressource (/path/file.json)
  • item : json object to save on S3

emptyS3Directory

constres=awaits3Tools.emptyS3Directory('bucket','dir/');

emptyS3Directory(bucket, dir)

  • bucket : bucket's name
  • dir : directory to remove

Test

$ npm test

Coverage report can be found in coverage/.

About

No description or website provided.

Topics

Resources

Stars

2 stars

Watchers

11 watching

Forks

Releases

Packages

Used by

Contributors

Languages