File tree Expand file tree Collapse file tree 4 files changed +1235
-25
lines changed
packages/large-response-middleware Expand file tree Collapse file tree 4 files changed +1235
-25
lines changed Original file line number Diff line number Diff line change 40
40
}
41
41
],
42
42
"devDependencies" : {
43
+ "@aws-sdk/client-s3" : " 3.782.0" ,
44
+ "@aws-sdk/s3-request-presigner" : " 3.782.0" ,
43
45
"@babel/cli" : " ^7.23.4" ,
44
46
"@babel/core" : " ^7.25.2" ,
45
47
"@babel/preset-env" : " ^7.25.4" ,
55
57
"@types/aws-lambda" : " ^8.10.130" ,
56
58
"@types/node" : " ^20.10.5" ,
57
59
"aws-lambda" : " ^1.0.7" ,
58
- "aws-sdk" : " ^2.816.0" ,
59
60
"cross-env" : " ^7.0.3" ,
60
61
"npm-run-all" : " ^4.1.5" ,
61
62
"rollup" : " ^4.9.1" ,
68
69
"vitest" : " 3.0.5"
69
70
},
70
71
"peerDependencies" : {
72
+ "@aws-sdk/client-s3" : " ^3.x" ,
73
+ "@aws-sdk/s3-request-presigner" : " ^3.x" ,
71
74
"@dazn/lambda-powertools-logger" : " ^1.28.1" ,
72
75
"@middy/core" : " ^2.5.7" ,
73
- "aws-lambda" : " ^1.0.7" ,
74
- "aws-sdk" : " ^2.816.0"
76
+ "aws-lambda" : " ^1.0.7"
75
77
},
76
78
"dependencies" : {
77
79
"core-js" : " ^3.34.0" ,
Original file line number Diff line number Diff line change @@ -2,6 +2,8 @@ import path from 'node:path';
2
2
3
3
import { getS3Client } from './s3/s3-client' ;
4
4
5
+ import { GetObjectCommand , PutObjectCommand } from '@aws-sdk/client-s3' ;
6
+ import { getSignedUrl } from '@aws-sdk/s3-request-presigner' ;
5
7
import type { FileUploadContext } from '.' ;
6
8
7
9
/**
@@ -15,22 +17,27 @@ export const uploadFile = async (params: FileUploadContext) => {
15
17
const date = getFormattedDate ( ) ;
16
18
const outputKey = `${ namespace } /${ date } /${ encodeURIComponent ( params . fileName ) } ` ;
17
19
18
- await client
19
- . putObject ( {
20
+ await client . send (
21
+ new PutObjectCommand ( {
20
22
Bucket : params . bucket ,
21
23
Key : outputKey ,
22
24
ContentType : params . contentType || 'text/plain' ,
23
25
Body : JSON . stringify ( params . content || { } ) ,
24
26
ACL : 'private' ,
25
- } )
26
- . promise ( ) ;
27
-
28
- const url = await client . getSignedUrl ( 'getObject' , {
29
- Expires : 3600 ,
30
- Bucket : params . bucket ,
31
- Key : outputKey ,
32
- ResponseContentDisposition : `inline;filename=${ path . basename ( outputKey ) } ` ,
33
- } ) ;
27
+ } ) ,
28
+ ) ;
29
+
30
+ const url = await getSignedUrl (
31
+ client ,
32
+ new GetObjectCommand ( {
33
+ Bucket : params . bucket ,
34
+ Key : outputKey ,
35
+ ResponseContentDisposition : `inline;filename=${ path . basename ( outputKey ) } ` ,
36
+ } ) ,
37
+ {
38
+ expiresIn : 3600 ,
39
+ } ,
40
+ ) ;
34
41
35
42
return { url, filename : outputKey } ;
36
43
} ;
Original file line number Diff line number Diff line change
1
+ import { S3Client , type S3ClientConfig } from '@aws-sdk/client-s3' ;
1
2
import Log from '@dazn/lambda-powertools-logger' ;
2
- import { S3 } from 'aws-sdk' ;
3
3
4
4
const AWS_ENDPOINT =
5
5
process . env . AWS_ENDPOINT ||
6
6
( process . env . STAGE === 'local' || process . env . NODE_ENV === 'local' ? 'http://host.docker.internal:4566' : undefined ) ;
7
7
8
- export const getS3Client = async ( options ?: S3 . Types . ClientConfiguration ) => {
8
+ export const getS3Client = async ( options ?: S3ClientConfig ) => {
9
9
try {
10
- const client = new S3 ( {
10
+ const client = new S3Client ( {
11
11
endpoint : AWS_ENDPOINT ,
12
- s3ForcePathStyle : Boolean ( AWS_ENDPOINT ) ,
13
- httpOptions : {
14
- timeout : 60_000 ,
15
- ...options ?. httpOptions ,
16
- } ,
12
+ forcePathStyle : Boolean ( AWS_ENDPOINT ) ,
17
13
...options ,
18
14
} ) ;
19
15
You can’t perform that action at this time.
0 commit comments