@middy/s3-object-response 4.0.0 → 4.0.2
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 +0 -85
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -36,91 +36,6 @@
|
|
|
36
36
|
<p>You can read the documentation at: <a href="https://middy.js.org/docs/middlewares/s3-object-response">https://middy.js.org/docs/middlewares/s3-object-response</a></p>
|
|
37
37
|
</div>
|
|
38
38
|
|
|
39
|
-
Fetches S3 object as a stream and writes back to s3 object response.
|
|
40
|
-
|
|
41
|
-
## Install
|
|
42
|
-
|
|
43
|
-
To install this middleware you can use NPM:
|
|
44
|
-
|
|
45
|
-
```bash
|
|
46
|
-
npm install --save @middy/s3-object-response
|
|
47
|
-
```
|
|
48
|
-
|
|
49
|
-
## Options
|
|
50
|
-
|
|
51
|
-
- `bodyType` (string) (required): How to pass in the s3 object through the handler. Can be `stream` or `promise`.
|
|
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
|
-
- `awsClientAssumeRole` (string) (default `undfined`): Internal key where secrets are stored. See [@middy/sts](/packages/sts/README.md) on to set this.
|
|
55
|
-
- `awsClientCapture` (function) (default `undefined`): Enable XRay by passing `captureAWSClient` from `aws-xray-sdk` in.
|
|
56
|
-
- `httpsCapture` (function) (default `undefined`): Enable XRay by passing `captureHTTPsGlobal` from `aws-xray-sdk` in.
|
|
57
|
-
- `disablePrefetch` (boolean) (default `false`): On cold start requests will trigger early if they can. Setting `awsClientAssumeRole` disables prefetch.
|
|
58
|
-
|
|
59
|
-
NOTES:
|
|
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`.
|
|
62
|
-
- Lambda is required to have IAM permission for `s3-object-lambda:WriteGetObjectResponse`
|
|
63
|
-
|
|
64
|
-
## Sample usage
|
|
65
|
-
|
|
66
|
-
### Stream
|
|
67
|
-
|
|
68
|
-
```javascript
|
|
69
|
-
import zlib from 'zlib'
|
|
70
|
-
import middy from '@middy/core'
|
|
71
|
-
import s3ObjectResponse from '@middy/s3-object-response'
|
|
72
|
-
import { captureAWSClient, captureHTTPsGlobal } from 'aws-xray-sdk-core'
|
|
73
|
-
|
|
74
|
-
const handler = middy((event, context) => {
|
|
75
|
-
const readStream = context.s3Object
|
|
76
|
-
const transformStream = zlib.createBrotliCompress()
|
|
77
|
-
return {
|
|
78
|
-
Body: readStream.pipe(transformStream)
|
|
79
|
-
}
|
|
80
|
-
})
|
|
81
|
-
|
|
82
|
-
handler.use(
|
|
83
|
-
s3ObjectResponse({
|
|
84
|
-
awsClientCapture: captureAWSClient,
|
|
85
|
-
httpsCapture: captureHTTPsGlobal,
|
|
86
|
-
bodyType: 'stream'
|
|
87
|
-
})
|
|
88
|
-
)
|
|
89
|
-
```
|
|
90
|
-
|
|
91
|
-
### Promise
|
|
92
|
-
|
|
93
|
-
```javascript
|
|
94
|
-
import zlib from 'zlib'
|
|
95
|
-
import middy from '@middy/core'
|
|
96
|
-
import s3ObjectResponse from '@middy/s3-object-response'
|
|
97
|
-
import { captureAWSClient, captureHTTPsGlobal } from 'aws-xray-sdk-core'
|
|
98
|
-
|
|
99
|
-
const handler = middy(async (event, context) => {
|
|
100
|
-
let body = await context.s3Object
|
|
101
|
-
// change body
|
|
102
|
-
return {
|
|
103
|
-
Body: JSON.stringify(body)
|
|
104
|
-
}
|
|
105
|
-
})
|
|
106
|
-
|
|
107
|
-
handler.use(
|
|
108
|
-
s3ObjectResponse({
|
|
109
|
-
awsClientCapture: captureAWSClient,
|
|
110
|
-
httpsCapture: captureHTTPsGlobal,
|
|
111
|
-
bodyType: 'promise'
|
|
112
|
-
})
|
|
113
|
-
)
|
|
114
|
-
```
|
|
115
|
-
|
|
116
|
-
## Middy documentation and examples
|
|
117
|
-
|
|
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).
|
|
119
|
-
|
|
120
|
-
## Contributing
|
|
121
|
-
|
|
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).
|
|
123
|
-
|
|
124
39
|
## License
|
|
125
40
|
|
|
126
41
|
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@middy/s3-object-response",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.2",
|
|
4
4
|
"description": "S3 object response handling middleware for the middy framework",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -62,13 +62,13 @@
|
|
|
62
62
|
},
|
|
63
63
|
"homepage": "https://middy.js.org",
|
|
64
64
|
"dependencies": {
|
|
65
|
-
"@middy/util": "4.0.
|
|
65
|
+
"@middy/util": "4.0.2"
|
|
66
66
|
},
|
|
67
67
|
"devDependencies": {
|
|
68
68
|
"@aws-sdk/client-s3": "^3.186.0",
|
|
69
|
-
"@middy/core": "4.0.
|
|
69
|
+
"@middy/core": "4.0.2",
|
|
70
70
|
"@types/aws-lambda": "^8.10.101",
|
|
71
71
|
"aws-xray-sdk": "^3.3.3"
|
|
72
72
|
},
|
|
73
|
-
"gitHead": "
|
|
73
|
+
"gitHead": "c77c9413ecb80999a71b67ff97edac1fed2ca754"
|
|
74
74
|
}
|