|
1 | | -# nodejs-aws-utils |
2 | | -Utilities function to work with AWS |
| 1 | +# Nodejs-aws-utils |
| 2 | +> Utilities function to work with AWS |
| 3 | +
|
| 4 | +Nodejs-aws-utils makes aws-sdk easier by provide a libary for **s3 bucket**, **dynamoDB**, **CloudFront** and support **promise** |
| 5 | + |
| 6 | +## Installation |
| 7 | +The easiest way to use nodejs-aws-utils is to install it from npm |
| 8 | +```sh |
| 9 | +npm i nodejs-aws-utils --save |
| 10 | +``` |
| 11 | + |
| 12 | +## Config |
| 13 | +Config default : |
| 14 | +```js |
| 15 | +const awsUtils = require('nodejs-aws-utils'); |
| 16 | +awsUtils.config('ACCESS_KEY_ID', 'SECRET_ACCESS_KEY', 'REGION'); |
| 17 | +``` |
| 18 | +Config by file: |
| 19 | +```js |
| 20 | +const awsUtils = require('nodejs-aws-utils'); |
| 21 | +awsUtils.configByFile('path'); |
| 22 | +``` |
| 23 | +## DynamoDB |
| 24 | +Import csv file to dynamoDB : |
| 25 | +```js |
| 26 | +const awsUtils = require('./index'); |
| 27 | +awsUtils.dynamoDB.importCSV('table_name', './dat.csv') |
| 28 | + .then((data) => { |
| 29 | + console.log('Success', data); |
| 30 | + }) |
| 31 | + .catch(err => console.log(err.stack)); |
| 32 | +``` |
| 33 | +Export csv file from dynamoDB : |
| 34 | +```js |
| 35 | +const awsUtils = require('./index'); |
| 36 | +awsUtils.dynamoDB.exportCSV({ TableName: 'table_name' }, './dat.csv') |
| 37 | + .then((status) => { |
| 38 | + if (status === true) { |
| 39 | + console.log('Success'); |
| 40 | + } else { |
| 41 | + console.log('Fail'); |
| 42 | + } |
| 43 | +}); |
| 44 | + |
| 45 | +``` |
| 46 | +## S3 buckets |
| 47 | +List buckets : |
| 48 | +```js |
| 49 | +awsUtils.bucket.list() |
| 50 | + .then(data => console.log(data)) |
| 51 | + .catch(err => console.log(err)); |
| 52 | +``` |
| 53 | +Create s3 bucket : |
| 54 | +```js |
| 55 | +awsUtils.bucket.create('bucket_name') |
| 56 | + .then(data => console.log(data)) |
| 57 | + .catch(err => console.log(err)); |
| 58 | +``` |
| 59 | +Upload file to s3 bucket : |
| 60 | +```js |
| 61 | +awsUtils.bucket.uploadFile('bucket_name', './pic.png') |
| 62 | + .then(data => console.log(data)) |
| 63 | + .catch(err => console.log(err)); |
| 64 | +``` |
| 65 | +## CloudFront |
| 66 | +Create distribution default : |
| 67 | +```js |
| 68 | +awsUtils.cloudFront.createDistributionDefault({ |
| 69 | + id: 'example_name_id', |
| 70 | + domainName: 'examplename.s3.amazonaws.com', |
| 71 | +}).then(data => console.log(data)) |
| 72 | + .catch(err => console.log(err)); |
| 73 | +``` |
| 74 | +Create distribution with [parameters]((https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/CloudFront.html#createDistribution-property)) : |
| 75 | +```js |
| 76 | +awsUtils.cloudFront.createDistribution(parameters) |
| 77 | + .then(data => console.log(data)) |
| 78 | + .catch(err => console.log(err)); |
| 79 | +``` |
| 80 | +Get distribution config default: |
| 81 | +```js |
| 82 | +awsUtils.cloudFront.getDistributionConfig(); |
| 83 | +``` |
| 84 | +Set distribution config: |
| 85 | +```js |
| 86 | +awsUtils.cloudFront.setDistributionConfig(); |
| 87 | +``` |
| 88 | + |
| 89 | +## Release history |
| 90 | + |
| 91 | +## Meta |
| 92 | +Ymese Team - Ymese.com |
| 93 | +Distributed under the APACHE license. See LICENSE for more information. |
0 commit comments