aws-v3-sdk 1.0.34 → 1.0.41
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 +138 -2
- package/clients/dynamo/DocumentClientAsync.js +111 -108
- package/clients/lambda copy.js +60 -0
- package/clients/lambda.js +22 -24
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,2 +1,138 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
1
|
+
# AWS SDK for JavaScript
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/aws-v3-sdk)
|
|
4
|
+
[](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 {
|
|
2
|
-
const {
|
|
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
|
-
|
|
9
|
-
const
|
|
10
|
-
documentClient.send(
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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
|
-
}
|
|
26
|
-
if (
|
|
27
|
-
|
|
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
|
-
|
|
34
|
-
|
|
35
|
-
const
|
|
36
|
-
documentClient.send(
|
|
37
|
-
|
|
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
|
-
}
|
|
48
|
-
if (
|
|
49
|
-
|
|
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
|
-
|
|
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
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
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
|
-
|
|
64
|
-
const
|
|
65
|
-
documentClient.send(
|
|
66
|
-
|
|
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
|
-
}
|
|
77
|
-
if (
|
|
78
|
-
|
|
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
|
-
|
|
85
|
-
|
|
86
|
-
const
|
|
87
|
-
|
|
88
|
-
|
|
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
|
-
}
|
|
100
|
-
if (
|
|
101
|
-
|
|
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
|
-
|
|
108
|
-
|
|
109
|
-
const
|
|
110
|
-
|
|
111
|
-
|
|
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
|
-
}
|
|
123
|
-
if (
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
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
|
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
const { LambdaClient, InvokeCommand, InvokeAsyncCommand } = require('@aws-sdk/client-lambda')
|
|
2
|
+
const { toUtf8, fromUtf8 } = require('@aws-sdk/util-utf8-node')
|
|
3
|
+
|
|
4
|
+
const { Agent } = require('https')
|
|
5
|
+
const { NodeHttpHandler } = require('@aws-sdk/node-http-handler')
|
|
6
|
+
|
|
7
|
+
const keepAliveOptions = new NodeHttpHandler({
|
|
8
|
+
httpsAgent: new Agent({
|
|
9
|
+
keepAlive: false,
|
|
10
|
+
maxSockets: 50
|
|
11
|
+
})
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
class Lambda {
|
|
15
|
+
constructor (region, session) {
|
|
16
|
+
if (region && session) {
|
|
17
|
+
this.client = new LambdaClient({ region, credentials: session, requestHandler: keepAliveOptions })
|
|
18
|
+
} else {
|
|
19
|
+
this.client = new LambdaClient({ requestHandler: keepAliveOptions })
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
async invoke (params, callback) {
|
|
24
|
+
const command = new InvokeCommand(params)
|
|
25
|
+
this.client.send(command).then(response => {
|
|
26
|
+
if (response.Payload) {
|
|
27
|
+
response.Payload = toUtf8(response.Payload)
|
|
28
|
+
}
|
|
29
|
+
callback(null, response)
|
|
30
|
+
}).catch(err => {
|
|
31
|
+
callback(err)
|
|
32
|
+
})
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
invokeAsync (params, callback) {
|
|
36
|
+
return new Promise((resolve, reject) => {
|
|
37
|
+
const command = new InvokeCommand(params)
|
|
38
|
+
this.client.send(command).then(response => {
|
|
39
|
+
if (response.Payload) {
|
|
40
|
+
response.Payload = toUtf8(response.Payload)
|
|
41
|
+
}
|
|
42
|
+
resolve(response)
|
|
43
|
+
}).catch(err => {
|
|
44
|
+
resolve(err)
|
|
45
|
+
})
|
|
46
|
+
}).then(result => {
|
|
47
|
+
if (callback && typeof callback === 'function') {
|
|
48
|
+
callback(null, result)
|
|
49
|
+
}
|
|
50
|
+
return result
|
|
51
|
+
}).catch(error => {
|
|
52
|
+
if (callback && typeof callback === 'function') {
|
|
53
|
+
callback(error, null)
|
|
54
|
+
}
|
|
55
|
+
return Promise.reject(error)
|
|
56
|
+
})
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
module.exports = Lambda
|
package/clients/lambda.js
CHANGED
|
@@ -21,35 +21,33 @@ class Lambda {
|
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
async invoke (params, callback) {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
24
|
+
try {
|
|
25
|
+
const command = new InvokeCommand(params)
|
|
26
|
+
const result = await this.client.send(command)
|
|
27
|
+
if (result.Payload) {
|
|
28
|
+
result.Payload = toUtf8(result.Payload)
|
|
29
|
+
}
|
|
30
|
+
if (typeof callback === 'function') callback(null, result)
|
|
31
|
+
return result
|
|
32
|
+
} catch (error) {
|
|
33
|
+
if (typeof callback === 'function') callback(error, null)
|
|
34
|
+
throw error
|
|
35
|
+
}
|
|
31
36
|
}
|
|
32
37
|
|
|
33
|
-
invokeAsync (params, callback) {
|
|
34
|
-
|
|
38
|
+
async invokeAsync (params, callback) {
|
|
39
|
+
try {
|
|
35
40
|
const command = new InvokeCommand(params)
|
|
36
|
-
this.client.send(command)
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}).catch(err => {
|
|
40
|
-
resolve(err)
|
|
41
|
-
})
|
|
42
|
-
}).then(result => {
|
|
43
|
-
if (callback && typeof callback === 'function') {
|
|
44
|
-
callback(null, result)
|
|
41
|
+
const result = await this.client.send(command)
|
|
42
|
+
if (result.Payload) {
|
|
43
|
+
result.Payload = toUtf8(result.Payload)
|
|
45
44
|
}
|
|
45
|
+
if (typeof callback === 'function') callback(null, result)
|
|
46
46
|
return result
|
|
47
|
-
}
|
|
48
|
-
if (
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
return Promise.reject(error)
|
|
52
|
-
})
|
|
47
|
+
} catch (error) {
|
|
48
|
+
if (typeof callback === 'function') callback(error, null)
|
|
49
|
+
throw error
|
|
50
|
+
}
|
|
53
51
|
}
|
|
54
52
|
}
|
|
55
53
|
|