@@ -10,18 +10,6 @@ generate signed url for S3.
10
10
11
11
You can generated presigned url from S3 client and command. Here's the example:
12
12
13
- JavaScript Example:
14
-
15
- ``` javascript
16
- const { getSignedUrl } = require (" @aws-sdk/s3-request-presigner" );
17
- const { S3Client , GetObjectCommand } = require (" @aws-sdk/client-s3" );
18
- const client = new S3Client (clientParams);
19
- const command = new GetObjectCommand (getObjectParams);
20
- const url = await getSignedUrl (client, command, { expiresIn: 3600 });
21
- ```
22
-
23
- ES6 Example
24
-
25
13
``` javascript
26
14
import { getSignedUrl } from " @aws-sdk/s3-request-presigner" ;
27
15
import { S3Client , GetObjectCommand } from " @aws-sdk/client-s3" ;
@@ -34,32 +22,11 @@ You can get signed URL for other S3 operations too, like `PutObjectCommand`.
34
22
` expiresIn ` config from the examples above is optional. If not set, it's default
35
23
at ` 900 ` .
36
24
37
- If your request contains server-side encryption(` SSE* ` ) configurations, because
38
- of S3 limitation, you need to send corresponding headers along with the
39
- presigned url. For more information, please go to [ S3 SSE reference] ( https://docs.aws.amazon.com/AmazonS3/latest/dev/KMSUsingRESTAPI.html )
40
-
41
25
If you already have a request, you can pre-sign the request following the
42
26
section bellow.
43
27
44
28
### Get Presigned URL from an Existing Request
45
29
46
- JavaScript Example:
47
-
48
- ``` javascript
49
- const { S3RequestPresigner } = require (" @aws-sdk/s3-request-presigner" );
50
- const { Sha256 } = require (" @aws-crypto/sha256-browser" );
51
- const { Hash } = require (" @smithy/hash-node" );
52
- const signer = new S3RequestPresigner ({
53
- region: regionProvider,
54
- credentials: credentialsProvider,
55
- sha256: Hash .bind (null , " sha256" ), // In Node.js
56
- // sha256: Sha256 // In browsers
57
- });
58
- const presigned = await signer .presign (request);
59
- ```
60
-
61
- ES6 Example:
62
-
63
30
``` javascript
64
31
import { S3RequestPresigner } from " @aws-sdk/s3-request-presigner" ;
65
32
import { Sha256 } from " @aws-crypto/sha256-browser" ;
@@ -84,13 +51,6 @@ const signer = new S3RequestPresigner({
84
51
});
85
52
```
86
53
87
- If your request contains server-side encryption(` x-amz-server-side-encryption* ` )
88
- headers, because of S3 limitation, you need to send these headers along
89
- with the presigned url. That is to say, the url only from calling ` formatUrl() `
90
- to ` presigned ` is not sufficient to make a request. You need to send the
91
- server-side encryption headers along with the url. These headers remain in the
92
- ` presigned.headers `
93
-
94
54
### Get Presigned URL with headers that cannot be signed
95
55
96
56
By using the ` getSignedUrl ` with a ` S3Client ` you are able to sign your
@@ -140,4 +100,26 @@ const presigned = getSignedUrl(s3Client, command, {
140
100
});
141
101
```
142
102
143
- For more information, please go to [ S3 SSE reference] ( https://docs.aws.amazon.com/AmazonS3/latest/dev/KMSUsingRESTAPI.html )
103
+ ### PutObject with use of ` hoistableHeaders `
104
+
105
+ ` hoistableHeaders ` overrides the default behavior of not hoisting
106
+ any headers that begin with ` x-amz-* ` .
107
+
108
+ ``` js
109
+ // example: Server Side Encryption headers
110
+ import { getSignedUrl } from " @aws-sdk/s3-request-presigner" ;
111
+ import { S3Client , PutObjectCommand } from " @aws-sdk/client-s3" ;
112
+
113
+ const params = {
114
+ Key: " ..." ,
115
+ Bucket: " ..." ,
116
+ ServerSideEncryption: " aws:kms" ,
117
+ SSEKMSKeyId: " arn:aws:kms:us-west-2:0000:key/abcd-1234-abcd" ,
118
+ };
119
+ const s3Client = new S3Client ();
120
+ const command = new PutObjectCommand (params);
121
+
122
+ const preSignedUrl = await getSignedUrl (s3Client, command, {
123
+ hoistableHeaders: new Set ([" x-amz-server-side-encryption" , " x-amz-server-side-encryption-aws-kms-key-id" ]),
124
+ });
125
+ ```
0 commit comments