Giter Club home page Giter Club logo

aws-utils's Introduction

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

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: {....}
}

Installation

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

Usage

Dynamo tools

Configure dynamo tools

const 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)

Query

const res = await dynamoTools.queryHashKey('myTable', 'key', 'value');
const res = await dynamoTools.query('myTable', { 'conditions': [{'key': 'value', 'operator': 'value', 'value': [] /** or ''**/}]})

Scan

const res = await dynamoTools.scan('myTable');

Put item

const res = await dynamoTools.putItem('myTable', {'key': 'value'});

Put items

const res = await dynamoTools.putItems('myTable', [{'key': 'value'}]);

Put transactional items

const res = await dynamoTools.putTransactionItems([{'key': 'value'}]);

Update item

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

delete item

const res = await dynamoTools.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

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);

getSecretValue

const res = await secretManagerTools.getSecretValue('secret');

getSecretValue(secret)

  • secret : secret's id

S3 tools

Configure S3 tools

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);

getObject

const res = await s3Tools.getObject('bucket', 'key');

getObject(bucket, key)

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

putJsonObject

const res = await s3Tools.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

const res = await s3Tools.emptyS3Directory('bucket', 'dir/');

emptyS3Directory(bucket, dir)

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

Test

$ npm test

Coverage report can be found in coverage/.

aws-utils's People

Contributors

raphaelvoodoo avatar thomasfournier avatar vincentvalletvoodoo avatar wallet77 avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

err0r500

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.