aws-v3-sdk 2.0.1 → 2.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,2 +1,138 @@
1
- # aws-v3-sdk
2
- AWS JS SDK UTILS
1
+ # AWS SDK for JavaScript
2
+
3
+ [![NPM version](https://img.shields.io/npm/v/aws-v3-sdk.svg)](https://www.npmjs.com/package/aws-v3-sdk)
4
+ [![NPM downloads](https://img.shields.io/npm/dm/aws-v3-sdk.svg)](https://www.npmjs.com/package/aws-v3-sdk)
5
+
6
+
7
+ ## Version 3.x
8
+
9
+ This package can be used to migrate to AWS SDK v3 from AWS SDK v2 without much change in exisint codebase.
10
+ This package takes the exisint AWS SDK v2 format and convert it to the AWS SDK v3 format.
11
+
12
+
13
+ AWS SDK V2
14
+ ```js
15
+ const AWS = require('aws-sdk')
16
+ const docClient = new AWS.DynamoDB.DocumentClient()
17
+ let params = {
18
+ TableName: TABLE_NAME,
19
+ Key: {
20
+ 'id': ID
21
+ }
22
+ }
23
+ docClient.get(params, function (err, data) {
24
+ console.log(data.Item)
25
+ })
26
+ ```
27
+ AWS SDK V3
28
+ ```js
29
+ const AWS = require('aws-v3-sdk')
30
+ const docClient = new AWS.DynamoDB.DocumentClient()
31
+ let params = {
32
+ TableName: TABLE_NAME,
33
+ Key: {
34
+ 'id': ID
35
+ }
36
+ }
37
+ docClient.get(params, function (err, data) {
38
+ console.log(data.Item)
39
+ })
40
+ ```
41
+
42
+ ## Table of Contents:
43
+ * [Supported Function](#supported-function)
44
+ * [Getting Started](#getting-Started)
45
+ * [Getting Help](#getting-help)
46
+ * [Contributing](#contributing)
47
+
48
+
49
+ ## Supported Functions
50
+
51
+ 1. Dynamo DB
52
+ 2. Lambda
53
+ 3. OpenSearch
54
+ 4. Cognito
55
+ 5. S3
56
+ 6. SNS
57
+ 7. SQS
58
+ 8. STS
59
+ 9. Cognito
60
+
61
+ ## Getting Started
62
+
63
+ ## How To Install
64
+
65
+ ### In Node.js
66
+
67
+ The preferred way to install the AWS SDK for Node.js is to use the
68
+ [npm](http://npmjs.org) package manager for Node.js. Simply type the following
69
+ into a terminal window:
70
+
71
+ ```sh
72
+ npm install aws-v3-sdk
73
+ ```
74
+
75
+ Then within your application, you can reference the react native compatible version of the SDK with the following:
76
+ We can use the old SDK format without migrating the code base. Just update the AWS import.
77
+
78
+ ```javascript
79
+ const AWS = require('aws-v3-sdk')
80
+
81
+ const s3 = new AWS.S3()
82
+
83
+ const params = {
84
+ Bucket: <BUCKET NAME>,
85
+ Key: <FILE KEY>,
86
+ Body: <STRING DATA,
87
+ ContentType: 'text/json'
88
+
89
+ }
90
+
91
+ s3.putObject(params, (err, data) => {
92
+ if (err) {
93
+ < DO Stuff HERE >
94
+ } else {
95
+ < DO Stuff HERE >
96
+ }
97
+ })
98
+ ```
99
+
100
+
101
+
102
+ ### Supported Functions
103
+
104
+ **Dynamo DB**
105
+ get
106
+ query
107
+ scan
108
+ put
109
+ delete
110
+ update
111
+ batchWrite
112
+ transactWrite
113
+ batchGet
114
+
115
+ S3
116
+ getSignedUrl
117
+ getObject
118
+ putObject
119
+ headObject
120
+ createMultipartUpload
121
+ completeMultipartUpload
122
+
123
+
124
+
125
+ ### Known Limitations
126
+ There are a few known limitations.
127
+
128
+ * This package has not been updated to handle all the AWS SDK APIs.
129
+
130
+
131
+ # Contributing
132
+ We welcome community contributions and pull requests. See [CONTRIBUTING.md](https://github.com/aws/aws-sdk-js/blob/master/CONTRIBUTING.md) for information on how to set up a development environment and submit code.
133
+
134
+ ## License
135
+
136
+ This SDK is distributed under the
137
+ [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0),
138
+ see LICENSE.txt and NOTICE.txt for more information.
package/clients/all.js CHANGED
@@ -7,5 +7,6 @@ module.exports = {
7
7
  STS: require('./sts'),
8
8
  SQS: require('./sqs'),
9
9
  SNS: require('./sns'),
10
- CognitoIdentityServiceProvider: require('./cognito')
10
+ CognitoIdentityServiceProvider: require('./cognito'),
11
+ Cloudfront: require('./cloudfront')
11
12
  }
@@ -0,0 +1,28 @@
1
+ const { CloudFrontClient, CreateInvalidationCommand } = require('@aws-sdk/client-cloudfront') // CommonJS import
2
+
3
+ class Cloudfront {
4
+ constructor (region) {
5
+ this.client = new CloudFrontClient()
6
+ }
7
+
8
+ async invalidate (params, callback) {
9
+ const input = {
10
+ DistributionId: params.DistributionId, // required
11
+ InvalidationBatch: {
12
+ Paths: {
13
+ Quantity: params.Paths.length,
14
+ Items: params.Paths
15
+ },
16
+ CallerReference: new Date().getTime()
17
+ }
18
+ }
19
+ const command = new CreateInvalidationCommand(input)
20
+ this.client.send(command).then(data => {
21
+ callback(null, data)
22
+ }).catch(err => {
23
+ callback(err)
24
+ })
25
+ }
26
+ }
27
+
28
+ module.exports = Cloudfront
@@ -6,7 +6,10 @@ const { NodeHttpHandler } = require('@aws-sdk/node-http-handler')
6
6
 
7
7
  const ddb = new DynamoDBClient({
8
8
  requestHandler: new NodeHttpHandler({
9
- httpsAgent: new Agent({ keepAlive: false })
9
+ httpsAgent: new Agent({
10
+ keepAlive: false,
11
+ maxSockets: 50
12
+ })
10
13
  })
11
14
  })
12
15
 
@@ -116,6 +119,18 @@ class DocumentClient {
116
119
  })
117
120
  }
118
121
 
122
+ transactWrite (params, callback) {
123
+ const docClient = DynamoDBDocument.from(new DynamoDB())
124
+ docClient.transactWrite(params, function (err, data) {
125
+ if (err) {
126
+ callback(err)
127
+ }
128
+ else {
129
+ callback(null, data)
130
+ }
131
+ })
132
+ }
133
+
119
134
  batchGet (params, callback) {
120
135
  const docClient = DynamoDBDocument.from(ddb)
121
136
 
@@ -321,6 +336,31 @@ class DocumentClient {
321
336
  return Promise.reject(error)
322
337
  })
323
338
  }
339
+
340
+ transactWriteAsync (params, callback) {
341
+ const docClient = DynamoDBDocument.from(new DynamoDB())
342
+ return new Promise((resolve, reject) => {
343
+ docClient.transactWrite(params, (err, response) => {
344
+ if (err || !response) {
345
+ return reject(err)
346
+ }
347
+ if (response) {
348
+ return resolve(response)
349
+ }
350
+ })
351
+ }).then(result => {
352
+ if (callback && typeof callback === 'function') {
353
+ callback(null, result)
354
+ }
355
+ return result
356
+ }).catch(error => {
357
+ if (callback && typeof callback === 'function') {
358
+ callback(error, null)
359
+ }
360
+ return Promise.reject(error)
361
+ })
362
+ }
324
363
  }
325
364
 
365
+
326
366
  module.exports = DocumentClient
package/clients/lambda.js CHANGED
@@ -5,7 +5,10 @@ const { Agent } = require('https')
5
5
  const { NodeHttpHandler } = require('@aws-sdk/node-http-handler')
6
6
 
7
7
  const keepAliveOptions = new NodeHttpHandler({
8
- httpsAgent: new Agent({ keepAlive: false })
8
+ httpsAgent: new Agent({
9
+ keepAlive: false,
10
+ maxSockets: 50
11
+ })
9
12
  })
10
13
 
11
14
  class Lambda {
package/clients/s3.js CHANGED
@@ -1,4 +1,4 @@
1
- const { S3Client, GetObjectCommand, PutObjectCommand, ListObjectsCommand, DeleteObjectsCommand, CreateMultipartUploadCommand, CompleteMultipartUploadCommand, UploadPartCommand } = require('@aws-sdk/client-s3')
1
+ const { S3Client, GetObjectCommand, PutObjectCommand, HeadObjectCommand, ListObjectsCommand, DeleteObjectsCommand, CreateMultipartUploadCommand, CompleteMultipartUploadCommand, UploadPartCommand } = require('@aws-sdk/client-s3')
2
2
  const { getSignedUrl } = require('@aws-sdk/s3-request-presigner')
3
3
 
4
4
  const { Agent } = require('https')
@@ -147,6 +147,30 @@ class S3 {
147
147
  return Promise.reject(error)
148
148
  })
149
149
  }
150
+
151
+ headObject (params, callback) {
152
+ return new Promise((resolve, reject) => {
153
+ const headObject = new HeadObjectCommand(params)
154
+ client.send(headObject, (err, data) => {
155
+ if (err || !data) {
156
+ resolve(err)
157
+ }
158
+ if (data) {
159
+ resolve(data)
160
+ }
161
+ })
162
+ }).then(result => {
163
+ if (callback && typeof callback === 'function') {
164
+ callback(null, result)
165
+ }
166
+ return result
167
+ }).catch(error => {
168
+ if (callback && typeof callback === 'function') {
169
+ callback(error, null)
170
+ }
171
+ return Promise.reject(error)
172
+ })
173
+ }
150
174
  }
151
175
 
152
176
  module.exports = S3
@@ -48,7 +48,7 @@ exports.sendAuditsReqToES = async (method, index, type, id, data) => {
48
48
  index,
49
49
  type,
50
50
  body: data,
51
- refresh: false
51
+ refresh: true
52
52
 
53
53
  })
54
54
  return response.body
@@ -28,8 +28,7 @@ const getClient = async () => {
28
28
  const cred = createAwsConnector(credentials, REGION)
29
29
  return new Client({
30
30
  ...cred,
31
- node: host,
32
- maxRetries: 0
31
+ node: host
33
32
  })
34
33
  }
35
34
 
@@ -40,8 +39,7 @@ exports.sendReqToES = async (method, index, type, id, data) => {
40
39
  const response = await client.delete({
41
40
  index,
42
41
  type,
43
- id,
44
- refresh: false
42
+ id
45
43
  })
46
44
  return response.body
47
45
  } else if (method === 'UPDATE') {
@@ -50,17 +48,7 @@ exports.sendReqToES = async (method, index, type, id, data) => {
50
48
  index,
51
49
  type,
52
50
  body: data,
53
- refresh: false,
54
- retry_on_conflict: 10
55
- })
56
- return response.body
57
- } else if (method === 'UPDATE_BY_QUERY') {
58
- const response = await client.updateByQuery({
59
- index,
60
- type,
61
- body: data,
62
- refresh: false,
63
- retry_on_conflict: 10
51
+ refresh: true
64
52
  })
65
53
  return response.body
66
54
  } else {
@@ -69,7 +57,7 @@ exports.sendReqToES = async (method, index, type, id, data) => {
69
57
  index,
70
58
  type,
71
59
  body: data,
72
- refresh: false
60
+ refresh: true
73
61
  })
74
62
  return response.body
75
63
  }
@@ -52,7 +52,7 @@ exports.sendGetRequest = async (index, query, from, size, sort, _source) => {
52
52
  options.size = size
53
53
  }
54
54
  if (_source) {
55
- options._source = _source
55
+ options._source = size
56
56
  }
57
57
  client.search(options).then(response => {
58
58
  logger.debug(response, { response })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aws-v3-sdk",
3
- "version": "2.0.1",
3
+ "version": "2.0.3",
4
4
  "description": "AWS v3 SDK Utils",
5
5
  "main": "index.js",
6
6
  "scripts": {