aws-v3-sdk 1.0.40 → 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.
@@ -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
@@ -24,7 +24,9 @@ class Lambda {
24
24
  try {
25
25
  const command = new InvokeCommand(params)
26
26
  const result = await this.client.send(command)
27
- result.Payload = toUtf8(result.Payload)
27
+ if (result.Payload) {
28
+ result.Payload = toUtf8(result.Payload)
29
+ }
28
30
  if (typeof callback === 'function') callback(null, result)
29
31
  return result
30
32
  } catch (error) {
@@ -37,7 +39,9 @@ class Lambda {
37
39
  try {
38
40
  const command = new InvokeCommand(params)
39
41
  const result = await this.client.send(command)
40
- result.Payload = toUtf8(result.Payload)
42
+ if (result.Payload) {
43
+ result.Payload = toUtf8(result.Payload)
44
+ }
41
45
  if (typeof callback === 'function') callback(null, result)
42
46
  return result
43
47
  } catch (error) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aws-v3-sdk",
3
- "version": "1.0.40",
3
+ "version": "1.0.41",
4
4
  "description": "AWS v3 SDK Utils",
5
5
  "main": "index.js",
6
6
  "scripts": {