1.2.5 • Published 3 years ago

awslittlehelper v1.2.5

Weekly downloads
122,945
License
ISC
Repository
github
Last release
3 years ago

Welcome to AWSLittleHelper

npm version

Hi! I'm Nathan, and when I began using aws to handle storage for my Node apps, It took me a while to piece together the right stackoverflow questions to upload to S3 correctly. So I created awslittlehelper to allow people to quickly import functionality to access S3 and store data there from Express api's.

Below there is also examples for passing data to this form from a variety of sources, sweetalert2, react and others.

Installation

To get started you need to install the latest version of awslittlehelper and its dependencies which you can install by running.

npm install awslittlehelper

This should install the module to your work area and allow you to require it with the following line of code

const alh = require('awslittlehelper')
or
import * as alh from 'awslittlehelper'

Usage in S3

Ok so now you've imported the functionality to your project lets get using it.

Set AWS data

Firstly you must setup your S3 storage space with the correct access and secret key for your S3 account. See below to find out how to get this. Service is either s3 or glacier. More will be added as I flesh out the module. You must do this for each service you use.

const alh = require('awslittlehelper')
alh.<service>.setAWSData('accessKey', 'secretKey')

Create Bucket

const alh = require('awslittlehelper');
alh.s3.createBucket('bucketName', callbackFunc);

List Buckets

const alh = require('awslittlehelper');
alh.s3.listBuckets(callbackFunc);

List all objects in a bucket

const alh = require('awslittlehelper');
alh.s3.listObjectsInBucket(bucketName, callbackFunc)

Delete Bucket

const alh = require('awslittlehelper');
alt.s3.deleteBucket(bucketName);

Uploading a file

const alh = require('awslittlehelper');
alh.s3.uploadFile(bucketName, file, fileName, callbackFunc)

Deleting a file

const alh = require('awslittlehelper');
alh.s3.deleteFile(bucketName, fileName, callbackFunc)

Check if file exists

const alh = requite('awslittlehelper')
alh.s3.checkFileExists(bucket, path, callbackFunc);

Usage in DynamoDB

You can also use AWSLittlehelper to create and manage DynamoDB. Don't forget to set your aws data using the als.dynamo.setAWSData

Create DynamoDB

Firstly you need to create the correct data object to pass to the DynamoDB. I've simplified this as much as i can so you just have to follow the below format and you'll be off.

const definitons = [
    { name: 'col1', type: 'S' },
    { name: 'col2', type: 'N' },
];

const schema = [
    { name: 'col1', type: 'HASH' },
    { name: 'col2', type: 'RANGE' },
];

Once you've created these, you can just simply pass this to the create Dynamo function like below.

const alh = require('awslittlehelper');
alh.dynamo.createTable(definitions, schema, tableName, callback);

List DynamoDB Tables

Limit is an optional parameter, if not specified it defaults to 10. const alh = require('awslittlehelper'); listTables(callback, limit);

Delete DynamoDB Table

const alh = require('awslittlehelper');
alh.dynamo.deleteTable(tableName, callback);

PUT item into DynamoDB

Eventually, this will automatically detect your value types, but for now, you must declare them using the below notation.

const alh = require('awslittlehelper')
const  items = [
    {
	    'key': { N:  0 },
	    'col1': { 'S':  'ATTRIBUTE_1'},
	    'col2': { 'N':  'ATTIRBUTE_2'}
    },
    {
	    'key': { N:  1 },
	    'col1': { 'S':  'ATTRIBUTE_1'},
	    'col2': { 'N':  'ATTIRBUTE_2'}
    }
]
alh.dynamo.putItem(items, tableName, callback);

Callbacks

Standard callback format

This is how i declare a standard callback function for all of the callbacks in any awslittlehelper function.

alh.<service>.<functionName>('', (err, data) => {
    if (err) {
	    console.log('Error', err);
    } else {
	    console.log('Success', data);
    }
});

For example

alh.s3.createBucket('bucketName', (err, data) => {
    if (err) {
	    console.log('Error', err);
    } else {
	    console.log('Success', data);
    }
});
1.2.5

3 years ago

1.2.0

3 years ago

1.1.1

3 years ago

1.1.0

3 years ago

1.2.4

3 years ago

1.2.3

3 years ago

1.2.2

3 years ago

1.2.1

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago

0.0.5

3 years ago

0.0.4

3 years ago

0.0.3

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago