aws-v3-sdk 1.0.34 → 1.0.40

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 1.0.40
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.
@@ -1,130 +1,133 @@
1
- const { DynamoDB, DynamoDBClient } = require('@aws-sdk/client-dynamodb')
2
- const { DynamoDBDocument, DynamoDBDocumentClient, GetCommand, BatchWriteCommand, PutCommand, QueryCommand, ScanCommand, DeleteCommand } = require('@aws-sdk/lib-dynamodb')
1
+ const { DynamoDBClient } = require('@aws-sdk/client-dynamodb')
2
+ const {
3
+ DynamoDBDocumentClient,
4
+ GetCommand,
5
+ PutCommand,
6
+ QueryCommand,
7
+ ScanCommand,
8
+ DeleteCommand,
9
+ UpdateCommand,
10
+ BatchGetCommand,
11
+ TransactWriteCommand,
12
+ BatchWriteCommand
13
+ } = require('@aws-sdk/lib-dynamodb')
14
+
3
15
  const ddb = new DynamoDBClient()
4
16
  const documentClient = DynamoDBDocumentClient.from(ddb)
5
17
 
6
18
  class DocumentClientAsync {
7
- get (params, callback) {
8
- return new Promise((resolve, reject) => {
9
- const getCommand = new GetCommand(params)
10
- documentClient.send(getCommand, (err, response) => {
11
- if (err || !response) {
12
- return reject(err)
13
- }
14
- if (response.Item) {
15
- return resolve(response)
16
- } else if (!response.Item) {
17
- return resolve({})
18
- }
19
- })
20
- }).then(result => {
21
- if (callback && typeof callback === 'function') {
22
- callback(null, result)
23
- }
19
+ async get (params, callback) {
20
+ try {
21
+ const command = new GetCommand(params)
22
+ const result = await documentClient.send(command)
23
+ const response = result?.Item ? result : {}
24
+ if (typeof callback === 'function') callback(null, response)
25
+ return response
26
+ } catch (error) {
27
+ if (typeof callback === 'function') callback(error, null)
28
+ throw error
29
+ }
30
+ }
31
+
32
+ async query (params, callback) {
33
+ try {
34
+ const command = new QueryCommand(params)
35
+ const result = await documentClient.send(command)
36
+ if (typeof callback === 'function') callback(null, result)
24
37
  return result
25
- }).catch(error => {
26
- if (callback && typeof callback === 'function') {
27
- callback(error, null)
28
- }
29
- return Promise.reject(error)
30
- })
38
+ } catch (error) {
39
+ if (typeof callback === 'function') callback(error, null)
40
+ throw error
41
+ }
31
42
  }
32
43
 
33
- query (params, callback) {
34
- return new Promise((resolve, reject) => {
35
- const getCommand = new QueryCommand(params)
36
- documentClient.send(getCommand, (err, response) => {
37
- if (err || !response) {
38
- return resolve(err)
39
- }
40
- return resolve(response)
41
- })
42
- }).then(result => {
43
- if (callback && typeof callback === 'function') {
44
- callback(null, result)
45
- }
44
+ async scan (params, callback) {
45
+ try {
46
+ const command = new ScanCommand(params)
47
+ const result = await documentClient.send(command)
48
+ if (typeof callback === 'function') callback(null, result)
46
49
  return result
47
- }).catch(error => {
48
- if (callback && typeof callback === 'function') {
49
- callback(error, null)
50
+ } catch (error) {
51
+ if (typeof callback === 'function') callback(error, null)
52
+ throw error
53
+ }
54
+ }
55
+
56
+ async put (params, callback) {
57
+ try {
58
+ if (params?.Item) {
59
+ params.Item = Object.fromEntries(
60
+ Object.entries(params.Item).filter(([, v]) => v !== undefined)
61
+ )
50
62
  }
51
- return Promise.reject(error)
52
- })
63
+ const command = new PutCommand(params)
64
+ const result = await documentClient.send(command)
65
+ if (typeof callback === 'function') callback(null, result)
66
+ return result
67
+ } catch (error) {
68
+ if (typeof callback === 'function') callback(error, null)
69
+ throw error
70
+ }
53
71
  }
54
72
 
55
- put (params, callback) {
56
- return new Promise((resolve, reject) => {
57
- let item = params.Item
58
- try {
59
- item = Object.fromEntries(Object.entries(item).filter(([key, value]) => value !== undefined))
60
- } catch (error) {
73
+ async delete (params, callback) {
74
+ try {
75
+ const command = new DeleteCommand(params)
76
+ const result = await documentClient.send(command)
77
+ if (typeof callback === 'function') callback(null, result)
78
+ return result
79
+ } catch (error) {
80
+ if (typeof callback === 'function') callback(error, null)
81
+ throw error
82
+ }
83
+ }
61
84
 
62
- }
63
- params.Item = item
64
- const putCommand = new PutCommand(params)
65
- documentClient.send(putCommand, (err, response) => {
66
- if (err || !response) {
67
- return resolve(err)
68
- }
69
- return resolve(response)
70
- })
71
- }).then(result => {
72
- if (callback && typeof callback === 'function') {
73
- callback(null, result)
74
- }
85
+ async update (params, callback) {
86
+ try {
87
+ const command = new UpdateCommand(params)
88
+ const result = await documentClient.send(command)
89
+ if (typeof callback === 'function') callback(null, result)
75
90
  return result
76
- }).catch(error => {
77
- if (callback && typeof callback === 'function') {
78
- callback(error, null)
79
- }
80
- return Promise.reject(error)
81
- })
91
+ } catch (error) {
92
+ if (typeof callback === 'function') callback(error, null)
93
+ throw error
94
+ }
82
95
  }
83
96
 
84
- delete (params, callback) {
85
- return new Promise((resolve, reject) => {
86
- const docClient = DynamoDBDocument.from(new DynamoDB())
87
- docClient.delete(params, (err, response) => {
88
- if (err) {
89
- return resolve(err)
90
- } else {
91
- return resolve(response)
92
- }
93
- })
94
- }).then(result => {
95
- if (callback && typeof callback === 'function') {
96
- callback(null, result)
97
- }
97
+ async batchGet (params, callback) {
98
+ try {
99
+ const command = new BatchGetCommand(params)
100
+ const result = await documentClient.send(command)
101
+ if (typeof callback === 'function') callback(null, result)
98
102
  return result
99
- }).catch(error => {
100
- if (callback && typeof callback === 'function') {
101
- callback(error, null)
102
- }
103
- return Promise.reject(error)
104
- })
103
+ } catch (error) {
104
+ if (typeof callback === 'function') callback(error, null)
105
+ throw error
106
+ }
105
107
  }
106
108
 
107
- update (params, callback) {
108
- return new Promise((resolve, reject) => {
109
- const docClient = DynamoDBDocument.from(new DynamoDB())
110
- docClient.update(params, (err, response) => {
111
- if (err) {
112
- return resolve(err)
113
- } else {
114
- return resolve(response)
115
- }
116
- })
117
- }).then(result => {
118
- if (callback && typeof callback === 'function') {
119
- callback(null, result)
120
- }
109
+ async batchWrite (params, callback) {
110
+ try {
111
+ const command = new BatchWriteCommand(params)
112
+ const result = await documentClient.send(command)
113
+ if (typeof callback === 'function') callback(null, result)
121
114
  return result
122
- }).catch(error => {
123
- if (callback && typeof callback === 'function') {
124
- callback(error, null)
125
- }
126
- return Promise.reject(error)
127
- })
115
+ } catch (error) {
116
+ if (typeof callback === 'function') callback(error, null)
117
+ throw error
118
+ }
119
+ }
120
+
121
+ async transactWrite (params, callback) {
122
+ try {
123
+ const command = new TransactWriteCommand(params)
124
+ const result = await documentClient.send(command)
125
+ if (typeof callback === 'function') callback(null, result)
126
+ return result
127
+ } catch (error) {
128
+ if (typeof callback === 'function') callback(error, null)
129
+ throw error
130
+ }
128
131
  }
129
132
  }
130
133
 
package/clients/lambda.js CHANGED
@@ -21,35 +21,29 @@ class Lambda {
21
21
  }
22
22
 
23
23
  async invoke (params, callback) {
24
- const command = new InvokeCommand(params)
25
- this.client.send(command).then(response => {
26
- response.Payload = toUtf8(response.Payload)
27
- callback(null, response)
28
- }).catch(err => {
29
- callback(err)
30
- })
24
+ try {
25
+ const command = new InvokeCommand(params)
26
+ const result = await this.client.send(command)
27
+ result.Payload = toUtf8(result.Payload)
28
+ if (typeof callback === 'function') callback(null, result)
29
+ return result
30
+ } catch (error) {
31
+ if (typeof callback === 'function') callback(error, null)
32
+ throw error
33
+ }
31
34
  }
32
35
 
33
- invokeAsync (params, callback) {
34
- return new Promise((resolve, reject) => {
36
+ async invokeAsync (params, callback) {
37
+ try {
35
38
  const command = new InvokeCommand(params)
36
- this.client.send(command).then(response => {
37
- response.Payload = toUtf8(response.Payload)
38
- resolve(response)
39
- }).catch(err => {
40
- resolve(err)
41
- })
42
- }).then(result => {
43
- if (callback && typeof callback === 'function') {
44
- callback(null, result)
45
- }
39
+ const result = await this.client.send(command)
40
+ result.Payload = toUtf8(result.Payload)
41
+ if (typeof callback === 'function') callback(null, result)
46
42
  return result
47
- }).catch(error => {
48
- if (callback && typeof callback === 'function') {
49
- callback(error, null)
50
- }
51
- return Promise.reject(error)
52
- })
43
+ } catch (error) {
44
+ if (typeof callback === 'function') callback(error, null)
45
+ throw error
46
+ }
53
47
  }
54
48
  }
55
49
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aws-v3-sdk",
3
- "version": "1.0.34",
3
+ "version": "1.0.40",
4
4
  "description": "AWS v3 SDK Utils",
5
5
  "main": "index.js",
6
6
  "scripts": {