@middy/s3-object-response 3.6.2 → 4.0.0-alpha.1

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
@@ -46,27 +46,30 @@ To install this middleware you can use NPM:
46
46
  npm install --save @middy/s3-object-response
47
47
  ```
48
48
 
49
-
50
49
  ## Options
50
+
51
51
  - `bodyType` (string) (required): How to pass in the s3 object through the handler. Can be `stream` or `promise`.
52
- - `AwsClient` (object) (default `AWS.S3`): AWS.S3 class constructor (e.g. that has been instrumented with AWS XRay). Must be from `aws-sdk` v2.
53
- - `awsClientOptions` (object) (default `undefined`): Options to pass to AWS.STS class constructor.
52
+ - `AwsClient` (object) (default `S3Client`): S3Client class constructor (i.e. that has been instrumented with AWS XRay). Must be from `@aws-sdk/client-s3`.
53
+ - `awsClientOptions` (object) (default `undefined`): Options to pass to S3Client class constructor.
54
54
  - `awsClientAssumeRole` (string) (default `undfined`): Internal key where secrets are stored. See [@middy/sts](/packages/sts/README.md) on to set this.
55
55
  - `awsClientCapture` (function) (default `undefined`): Enable XRay by passing `captureAWSClient` from `aws-xray-sdk` in.
56
56
  - `httpsCapture` (function) (default `undefined`): Enable XRay by passing `captureHTTPsGlobal` from `aws-xray-sdk` in.
57
57
  - `disablePrefetch` (boolean) (default `false`): On cold start requests will trigger early if they can. Setting `awsClientAssumeRole` disables prefetch.
58
58
 
59
59
  NOTES:
60
+
60
61
  - The response from the handler must match the allowed parameters for [`S3.writeGetObjectResponse`](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#writeGetObjectResponse-property), excluding `RequestRoute` and `RequestToken`.
61
62
  - Lambda is required to have IAM permission for `s3-object-lambda:WriteGetObjectResponse`
62
63
 
63
64
  ## Sample usage
65
+
64
66
  ### Stream
67
+
65
68
  ```javascript
66
69
  import zlib from 'zlib'
67
70
  import middy from '@middy/core'
68
71
  import s3ObjectResponse from '@middy/s3-object-response'
69
- import {captureAWSClient, captureHTTPsGlobal} from 'aws-xray-sdk-core'
72
+ import { captureAWSClient, captureHTTPsGlobal } from 'aws-xray-sdk-core'
70
73
 
71
74
  const handler = middy((event, context) => {
72
75
  const readStream = context.s3Object
@@ -76,20 +79,22 @@ const handler = middy((event, context) => {
76
79
  }
77
80
  })
78
81
 
79
- handler
80
- .use(s3ObjectResponse({
82
+ handler.use(
83
+ s3ObjectResponse({
81
84
  awsClientCapture: captureAWSClient,
82
- httpsCapture:captureHTTPsGlobal,
85
+ httpsCapture: captureHTTPsGlobal,
83
86
  bodyType: 'stream'
84
- }))
87
+ })
88
+ )
85
89
  ```
86
90
 
87
91
  ### Promise
92
+
88
93
  ```javascript
89
94
  import zlib from 'zlib'
90
95
  import middy from '@middy/core'
91
96
  import s3ObjectResponse from '@middy/s3-object-response'
92
- import {captureAWSClient, captureHTTPsGlobal} from 'aws-xray-sdk-core'
97
+ import { captureAWSClient, captureHTTPsGlobal } from 'aws-xray-sdk-core'
93
98
 
94
99
  const handler = middy(async (event, context) => {
95
100
  let body = await context.s3Object
@@ -99,25 +104,23 @@ const handler = middy(async (event, context) => {
99
104
  }
100
105
  })
101
106
 
102
- handler
103
- .use(s3ObjectResponse({
107
+ handler.use(
108
+ s3ObjectResponse({
104
109
  awsClientCapture: captureAWSClient,
105
- httpsCapture:captureHTTPsGlobal,
110
+ httpsCapture: captureHTTPsGlobal,
106
111
  bodyType: 'promise'
107
- }))
112
+ })
113
+ )
108
114
  ```
109
115
 
110
-
111
116
  ## Middy documentation and examples
112
117
 
113
118
  For more documentation and examples, refers to the main [Middy monorepo on GitHub](https://github.com/middyjs/middy) or [Middy official website](https://middy.js.org).
114
119
 
115
-
116
120
  ## Contributing
117
121
 
118
122
  Everyone is very welcome to contribute to this repository. Feel free to [raise issues](https://github.com/middyjs/middy/issues) or to [submit Pull Requests](https://github.com/middyjs/middy/pulls).
119
123
 
120
-
121
124
  ## License
122
125
 
123
126
  Licensed under [MIT License](LICENSE). Copyright (c) 2017-2022 [Luciano Mammino](https://github.com/lmammino), [will Farrell](https://github.com/willfarrell), and the [Middy team](https://github.com/middyjs/middy/graphs/contributors).
package/index.cjs CHANGED
@@ -9,15 +9,14 @@ Object.defineProperty(module, "exports", {
9
9
  const _https = _interopRequireDefault(require("https"));
10
10
  const _url = require("url");
11
11
  const _util = require("@middy/util");
12
- const _s3Js = _interopRequireDefault(require("aws-sdk/clients/s3.js"));
12
+ const _clientS3 = require("@aws-sdk/client-s3");
13
13
  function _interopRequireDefault(obj) {
14
14
  return obj && obj.__esModule ? obj : {
15
15
  default: obj
16
16
  };
17
17
  }
18
- var _response;
19
18
  const defaults = {
20
- AwsClient: _s3Js.default,
19
+ AwsClient: _clientS3.S3Client,
21
20
  awsClientOptions: {},
22
21
  awsClientAssumeRole: undefined,
23
22
  awsClientCapture: undefined,
@@ -63,12 +62,12 @@ const s3ObjectResponseMiddleware = (opts = {})=>{
63
62
  if (!client) {
64
63
  client = await (0, _util.createClient)(options, request);
65
64
  }
66
- (_response = request.response).Body ?? (_response.Body = request.response.body);
65
+ request.response.Body ??= request.response.body;
67
66
  delete request.response.body;
68
- await client.writeGetObjectResponse({
67
+ await client.send(new _clientS3.WriteGetObjectResponseCommand({
69
68
  ...request.response,
70
69
  ...request.internal.s3ObjectResponse
71
- }).promise();
70
+ }));
72
71
  return {
73
72
  statusCode: 200
74
73
  };
package/index.d.ts CHANGED
@@ -1,12 +1,12 @@
1
1
  import middy from '@middy/core'
2
2
  import { Options as MiddyOptions } from '@middy/util'
3
3
  import { Context as LambdaContext } from 'aws-lambda'
4
- import S3 from 'aws-sdk/clients/s3'
4
+ import { S3Client, S3ClientConfig } from '@aws-sdk/client-s3'
5
5
  import { ClientRequest } from 'http'
6
6
 
7
- interface Options<S = S3>
7
+ interface Options<AwsS3Client = S3Client>
8
8
  extends Pick<
9
- MiddyOptions<S, S3.Types.ClientConfiguration>,
9
+ MiddyOptions<AwsS3Client, S3ClientConfig>,
10
10
  | 'AwsClient'
11
11
  | 'awsClientOptions'
12
12
  | 'awsClientAssumeRole'
package/index.js CHANGED
@@ -1,10 +1,9 @@
1
- var _response;
2
1
  import __https from 'https';
3
2
  import { URL } from 'url';
4
3
  import { canPrefetch, createPrefetchClient, createClient } from '@middy/util';
5
- import S3 from 'aws-sdk/clients/s3.js';
4
+ import { S3Client, WriteGetObjectResponseCommand } from '@aws-sdk/client-s3';
6
5
  const defaults = {
7
- AwsClient: S3,
6
+ AwsClient: S3Client,
8
7
  awsClientOptions: {},
9
8
  awsClientAssumeRole: undefined,
10
9
  awsClientCapture: undefined,
@@ -50,12 +49,12 @@ const s3ObjectResponseMiddleware = (opts = {})=>{
50
49
  if (!client) {
51
50
  client = await createClient(options, request);
52
51
  }
53
- (_response = request.response).Body ?? (_response.Body = request.response.body);
52
+ request.response.Body ??= request.response.body;
54
53
  delete request.response.body;
55
- await client.writeGetObjectResponse({
54
+ await client.send(new WriteGetObjectResponseCommand({
56
55
  ...request.response,
57
56
  ...request.internal.s3ObjectResponse
58
- }).promise();
57
+ }));
59
58
  return {
60
59
  statusCode: 200
61
60
  };
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@middy/s3-object-response",
3
- "version": "3.6.2",
3
+ "version": "4.0.0-alpha.1",
4
4
  "description": "S3 object response handling middleware for the middy framework",
5
5
  "type": "module",
6
6
  "engines": {
7
- "node": ">=14"
7
+ "node": ">=16"
8
8
  },
9
9
  "engineStrict": true,
10
10
  "publishConfig": {
@@ -62,13 +62,13 @@
62
62
  },
63
63
  "homepage": "https://middy.js.org",
64
64
  "dependencies": {
65
- "@middy/util": "3.6.2"
65
+ "@middy/util": "4.0.0-alpha.1"
66
66
  },
67
67
  "devDependencies": {
68
- "@middy/core": "3.6.2",
68
+ "@aws-sdk/client-s3": "^3.186.0",
69
+ "@middy/core": "4.0.0-alpha.1",
69
70
  "@types/aws-lambda": "^8.10.101",
70
- "aws-sdk": "^2.939.0",
71
71
  "aws-xray-sdk": "^3.3.3"
72
72
  },
73
- "gitHead": "4c5d64c72dd4bfde0d3b828a0082c99f688c759c"
73
+ "gitHead": "b531f61dac3a5268728a21fc4b2b32054b170f88"
74
74
  }