Skip to content
This repository was archived by the owner on Jun 28, 2023. It is now read-only.

Commit 1ea1a4c

Browse files
committed
Periodic update - 2023-03-06
1 parent 278d5f8 commit 1ea1a4c

File tree

116 files changed

+2115
-1982
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

116 files changed

+2115
-1982
lines changed

doc_source/DeletingObjects.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,28 @@ You can delete one or more objects directly from Amazon S3 using the Amazon S3 c
55
For information about Amazon S3 features and pricing, see [Amazon S3 pricing](http://aws.amazon.com/s3/pricing)\.
66

77
You have the following API options when deleting an object:
8-
+ **Delete a single object** Amazon S3 provides the DELETE API that you can use to delete one object in a single HTTP request\.
9-
+ **Delete multiple objects** Amazon S3 provides the Multi\-Object Delete API that you can use to delete up to 1,000 objects in a single HTTP request\.
8+
+ **Delete a single object** Amazon S3 provides the `DELETE` \(`DeleteObject`\) API operation that you can use to delete one object in a single HTTP request\.
9+
+ **Delete multiple objects** Amazon S3 provides the Multi\-Object Delete \(`DeleteObjects`\) API operation that you can use to delete up to 1,000 objects in a single HTTP request\.
1010

1111
When deleting objects from a bucket that is not version\-enabled, you provide only the object key name\. However, when deleting objects from a version\-enabled bucket, you can optionally provide the version ID of the object to delete a specific version of the object\.
1212

1313
## Programmatically deleting objects from a version\-enabled bucket<a name="DeletingObjectsfromaVersion-EnabledBucket"></a>
1414

15-
If your bucket is version\-enabled, multiple versions of the same object can exist in the bucket\. When working with version\-enabled buckets, the delete API enables the following options:
16-
+ **Specify a non\-versioned delete request** Specify only the object's key, and not the version ID\. In this case, Amazon S3 creates a delete marker and returns its version ID in the response\. This makes your object disappear from the bucket\. For information about object versioning and the delete marker concept, see [Using versioning in S3 buckets](Versioning.md)\.
17-
+ **Specify a versioned delete request** Specify both the key and also a version ID\. In this case the following two outcomes are possible:
15+
If your bucket is version\-enabled, multiple versions of the same object can exist in the bucket\. When working with version\-enabled buckets, the delete API operations enable the following options:
16+
+ **Specify a non\-versioned delete request** Specify only the object's key, and not the version ID\. In this case, Amazon S3 creates a delete marker and returns its version ID in the response\. This makes your object disappear from the bucket\. For information about object versioning and the delete marker concept, see [Using versioning in S3 buckets](Versioning.md)\.
17+
+ **Specify a versioned delete request** Specify both the key and also a version ID\. In this case the following two outcomes are possible:
1818
+ If the version ID maps to a specific object version, Amazon S3 deletes the specific version of the object\.
1919
+ If the version ID maps to the delete marker of that object, Amazon S3 deletes the delete marker\. This makes the object reappear in your bucket\.
2020

2121
## Deleting objects from an MFA\-enabled bucket<a name="DeletingObjectsfromanMFA-EnabledBucket"></a>
2222

2323
When deleting objects from a multi\-factor authentication \(MFA\)\-enabled bucket, note the following:
24-
+ If you provide an invalid MFA token, the request always fails\.
25-
+ If you have an MFA\-enabled bucket, and you make a versioned delete request \(you provide an object key and version ID\), the request fails if you don't provide a valid MFA token\. In addition, when using the Multi\-Object Delete API on an MFA\-enabled bucket, if any of the deletes are a versioned delete request \(that is, you specify object key and version ID\), the entire request fails if you don't provide an MFA token\.
24+
+ If you provide an MFA token that isn't valid, the request always fails\.
25+
+ If you have an MFA\-enabled bucket and you make a versioned delete request \(you provide an object key and version ID\), the request fails if you don't provide a valid MFA token\. In addition, when using the Multi\-Object Delete API operation on an MFA\-enabled bucket, if any of the deletes are a versioned delete request \(that is, you specify an object key and version ID\), the entire request fails if you don't provide an MFA token\.
2626

27-
However, in the following cases the request succeeds:
28-
+ If you have an MFA\-enabled bucket, and you make a non\-versioned delete request \(you are not deleting a versioned object\), and you don't provide an MFA token, the delete succeeds\.
29-
+ If you have a Multi\-Object Delete request specifying only non\-versioned objects to delete from an MFA\-enabled bucket, and you don't provide an MFA token, the deletions succeed\.
27+
However, in the following cases, the request succeeds:
28+
+ If you have an MFA\-enabled bucket and you make a non\-versioned delete request \(you are not deleting a versioned object\), and you don't provide an MFA token, the delete succeeds\.
29+
+ If you have a Multi\-Object Delete request that specifies only non\-versioned objects to delete from an MFA\-enabled bucket and you don't provide an MFA token, the deletions succeed\.
3030

3131
For information about MFA delete, see [Configuring MFA delete](MultiFactorAuthenticationDelete.md)\.
3232

doc_source/ListingKeysUsingAPIs.md

Lines changed: 30 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -263,79 +263,46 @@ List objects using pagination\.
263263
------
264264
#### [ JavaScript ]
265265

266-
**SDK for JavaScript V3**
266+
**SDK for JavaScript \(v3\)**
267267
There's more on GitHub\. Find the complete example and learn how to set up and run in the [AWS Code Examples Repository](https://github.com/awsdocs/aws-doc-sdk-examples/tree/main/javascriptv3/example_code/s3#code-examples)\.
268-
Create the client\.
268+
List all of the objects in your bucket\. If there is more than one object, IsTruncated and NextContinuationToken will be used to iterate over the full list\.
269269

270270
```
271-
// Create service client module using ES6 syntax.
272-
import { S3Client } from "@aws-sdk/client-s3";
273-
// Set the AWS Region.
274-
const REGION = "us-east-1";
275-
// Create an Amazon S3 service client object.
276-
const s3Client = new S3Client({ region: REGION });
277-
export { s3Client };
278-
```
279-
List the objects\.
271+
import {
272+
S3Client,
273+
// This command supersedes the ListObjectsCommand and is the recommended way to list objects.
274+
ListObjectsV2Command,
275+
} from "@aws-sdk/client-s3";
280276
281-
```
282-
// Import required AWS SDK clients and commands for Node.js.
283-
import { ListObjectsCommand } from "@aws-sdk/client-s3";
284-
import { s3Client } from "./libs/s3Client.js"; // Helper function that creates an Amazon S3 service client module.
277+
const client = new S3Client({});
285278
286-
// Create the parameters for the bucket
287-
export const bucketParams = { Bucket: "BUCKET_NAME" };
279+
export const main = async () => {
280+
const command = new ListObjectsV2Command({
281+
Bucket: "my-bucket",
282+
// The default and maximum number of keys returned is 1000. This limits it to
283+
// one for demonstration purposes.
284+
MaxKeys: 1,
285+
});
288286
289-
export const run = async () => {
290287
try {
291-
const data = await s3Client.send(new ListObjectsCommand(bucketParams));
292-
console.log("Success", data);
293-
return data; // For unit tests.
294-
} catch (err) {
295-
console.log("Error", err);
296-
}
297-
};
298-
run();
299-
```
300-
List 1000 or more objects\.
288+
let isTruncated = true;
301289
302-
```
303-
// Import required AWS SDK clients and commands for Node.js.
304-
import { ListObjectsCommand } from "@aws-sdk/client-s3";
305-
import { s3Client } from "./libs/s3Client.js"; // Helper function that creates an Amazon S3 service client module.
306-
307-
// Create the parameters for the bucket
308-
export const bucketParams = { Bucket: "BUCKET_NAME" };
309-
310-
export async function run() {
311-
// Declare truncated as a flag that the while loop is based on.
312-
let truncated = true;
313-
// Declare a variable to which the key of the last element is assigned to in the response.
314-
let pageMarker;
315-
// while loop that runs until 'response.truncated' is false.
316-
while (truncated) {
317-
try {
318-
const response = await s3Client.send(new ListObjectsCommand(bucketParams));
319-
// return response; //For unit tests
320-
response.Contents.forEach((item) => {
321-
console.log(item.Key);
322-
});
323-
// Log the key of every item in the response to standard output.
324-
truncated = response.IsTruncated;
325-
// If truncated is true, assign the key of the last element in the response to the pageMarker variable.
326-
if (truncated) {
327-
pageMarker = response.Contents.slice(-1)[0].Key;
328-
// Assign the pageMarker value to bucketParams so that the next iteration starts from the new pageMarker.
329-
bucketParams.Marker = pageMarker;
330-
}
331-
// At end of the list, response.truncated is false, and the function exits the while loop.
332-
} catch (err) {
333-
console.log("Error", err);
334-
truncated = false;
290+
console.log("Your bucket contains the following objects:\n")
291+
let contents = "";
292+
293+
while (isTruncated) {
294+
const { Contents, IsTruncated, NextContinuationToken } = await client.send(command);
295+
const contentsList = Contents.map((c) => ` • ${c.Key}`).join("\n");
296+
contents += contentsList + "\n";
297+
isTruncated = IsTruncated;
298+
command.input.ContinuationToken = NextContinuationToken;
335299
}
300+
console.log(contents);
301+
302+
} catch (err) {
303+
console.error(err);
336304
}
337-
}
338-
run();
305+
};
339306
```
340307
+ For API details, see [ListObjects](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/clients/client-s3/classes/listobjectscommand.html) in *AWS SDK for JavaScript API Reference*\.
341308

doc_source/ManagingDelMarkers.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## Configuring lifecycle to clean up expired delete markers automatically<a name="LifecycleDelMarker"></a>
44

5-
An expired object delete marker is one where all object versions are deleted and only a single delete marker remains\. If the lifecycle policy is set to delete current versions, or the `ExpiredObjectDeleteMarker` action is explicitly set, Amazon S3 removes the expired object’s delete marker\. For an example, see [Example 7: Removing expired object delete markers](lifecycle-configuration-examples.md#lifecycle-config-conceptual-ex7)\.
5+
An expired object delete marker is one where all object versions are deleted and only a single delete marker remains\. If the lifecycle configuration is set to delete current versions, or the `ExpiredObjectDeleteMarker` action is explicitly set, Amazon S3 removes the expired object’s delete marker\. For an example, see [Example 7: Removing expired object delete markers](lifecycle-configuration-examples.md#lifecycle-config-conceptual-ex7)\.
66

77
## Removing delete markers to make an older version current<a name="RemDelMarker"></a>
88

doc_source/OrderOutposts.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Setting up your Outpost<a name="OrderOutposts"></a>
22

3-
To get started with Amazon S3 on Outposts, you will need an Outpost with Amazon S3 capacity deployed at your facility\. For information about options for ordering an Outpost and S3 capacity, see [AWS Outposts](http://aws.amazon.com/outposts)\. For specifications and to see how S3 on Outposts is different than Amazon S3, see [How is Amazon S3 on Outposts different from Amazon S3?](S3OnOutpostsRestrictionsLimitations.md)
3+
To get started with Amazon S3 on Outposts, you will need an Outpost with Amazon S3 capacity deployed at your facility\. For information about options for ordering an Outpost and S3 capacity, see [AWS Outposts](http://aws.amazon.com/outposts)\. To check if your Outposts has S3 capacity on it, you can use the [ListOutpostsWithS3](https://docs.aws.amazon.com/AmazonS3/latest/API/API_s3outposts_ListOutpostsWithS3.html) API call\. For specifications and to see how S3 on Outposts is different than Amazon S3, see [How is Amazon S3 on Outposts different from Amazon S3?](S3OnOutpostsRestrictionsLimitations.md)
44

55
For more information, see the following topics\.
66

doc_source/PresignedUrlDelete.md

Lines changed: 81 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -5,69 +5,93 @@ The following AWS SDK for JavaScript example uses a presigned URL to delete an o
55
For more information about using presigned URLs, see [Using presigned URLs](using-presigned-url.md)\.
66

77
```
8-
// Import the required AWS SDK clients and commands for Node.js
8+
import https from "https";
9+
import { PutObjectCommand, S3Client } from "@aws-sdk/client-s3";
10+
import { fromIni } from "@aws-sdk/credential-providers";
11+
import { HttpRequest } from "@aws-sdk/protocol-http";
912
import {
10-
CreateBucketCommand,
11-
DeleteObjectCommand,
12-
PutObjectCommand,
13-
DeleteBucketCommand }
14-
from "@aws-sdk/client-s3";
15-
import { s3Client } from "./libs/s3Client.js"; // Helper function that creates an Amazon S3 service client module.
16-
import { getSignedUrl } from "@aws-sdk/s3-request-presigner";
17-
import fetch from "node-fetch";
13+
getSignedUrl,
14+
S3RequestPresigner,
15+
} from "@aws-sdk/s3-request-presigner";
16+
import { parseUrl } from "@aws-sdk/url-parser";
17+
import { formatUrl } from "@aws-sdk/util-format-url";
18+
import { Hash } from "@aws-sdk/hash-node";
1819
19-
// Set parameters
20-
// Create a random name for the Amazon Simple Storage Service (Amazon S3) bucket and key
21-
export const bucketParams = {
22-
Bucket: `test-bucket-${Math.ceil(Math.random() * 10 ** 10)}`,
23-
Key: `test-object-${Math.ceil(Math.random() * 10 ** 10)}`,
24-
Body: "BODY"
20+
const createPresignedUrlWithoutClient = async ({ region, bucket, key }) => {
21+
const url = parseUrl(`https://${bucket}.s3.${region}.amazonaws.com/${key}`);
22+
const presigner = new S3RequestPresigner({
23+
credentials: fromIni(),
24+
region,
25+
sha256: Hash.bind(null, "sha256"),
26+
});
27+
28+
const signedUrlObject = await presigner.presign(
29+
new HttpRequest({ ...url, method: "PUT" })
30+
);
31+
return formatUrl(signedUrlObject);
2532
};
26-
export const run = async () => {
27-
try {
28-
// Create an S3 bucket.
29-
console.log(`Creating bucket ${bucketParams.Bucket}`);
30-
await s3Client.send(new CreateBucketCommand({ Bucket: bucketParams.Bucket }));
31-
console.log(`Waiting for "${bucketParams.Bucket}" bucket creation...`);
32-
} catch (err) {
33-
console.log("Error creating bucket", err);
34-
}
35-
try {
36-
// Create a command to put the object in the S3 bucket.
37-
const command = new PutObjectCommand(bucketParams);
38-
// Create the presigned URL.
39-
const signedUrl = await getSignedUrl(s3Client, command, {
40-
expiresIn: 3600,
41-
});
42-
console.log(
43-
`\nPutting "${bucketParams.Key}" using signedUrl with body "${bucketParams.Body}" in v3`
44-
);
45-
console.log(signedUrl);
46-
const response = await fetch(signedUrl, {method: 'PUT', body: bucketParams.Body});
47-
console.log(
48-
`\nResponse returned by signed URL: ${await response.text()}\n`
49-
);
50-
} catch (err) {
51-
console.log("Error creating presigned URL", err);
52-
}
53-
try {
54-
// Delete the object.
55-
console.log(`\nDeleting object "${bucketParams.Key}"} from bucket`);
56-
await s3Client.send(
57-
new DeleteObjectCommand({ Bucket: bucketParams.Bucket, Key: bucketParams.Key })
33+
34+
const createPresignedUrlWithClient = async ({ region, bucket, key }) => {
35+
const client = new S3Client({ region });
36+
const command = new PutObjectCommand({ Bucket: bucket, Key: key });
37+
return getSignedUrl(client, command, { expiresIn: 3600 });
38+
};
39+
40+
function put(url, data) {
41+
return new Promise((resolve, reject) => {
42+
const req = https.request(
43+
url,
44+
{ method: "PUT", headers: { "Content-Length": new Blob([data]).size } },
45+
(res) => {
46+
let responseBody = "";
47+
res.on("data", (chunk) => {
48+
responseBody += chunk;
49+
});
50+
res.on("end", () => {
51+
resolve(responseBody);
52+
});
53+
}
5854
);
59-
} catch (err) {
60-
console.log("Error deleting object", err);
61-
}
55+
req.on("error", (err) => {
56+
reject(err);
57+
});
58+
req.write(data);
59+
req.end();
60+
});
61+
}
62+
63+
export const main = async () => {
64+
const REGION = "us-east-1";
65+
const BUCKET = "coreys-default-bucket";
66+
const KEY = "corey_test.txt";
67+
68+
// There are two ways to generate a presigned URL.
69+
// 1. Use createPresignedUrl without the S3 client.
70+
// 2. Use getSignedUrl in conjunction with the S3 client and GetObjectCommand.
6271
try {
63-
// Delete the S3 bucket.
64-
console.log(`\nDeleting bucket ${bucketParams.Bucket}`);
65-
await s3Client.send(
66-
new DeleteBucketCommand({ Bucket: bucketParams.Bucket })
67-
);
72+
const noClientUrl = await createPresignedUrlWithoutClient({
73+
region: REGION,
74+
bucket: BUCKET,
75+
key: KEY,
76+
});
77+
78+
const clientUrl = await createPresignedUrlWithClient({
79+
region: REGION,
80+
bucket: BUCKET,
81+
key: KEY,
82+
});
83+
84+
// After you get the presigned URL, you can provide your own file
85+
// data. Refer to put() above.
86+
console.log("Calling PUT using presigned URL without client");
87+
await put(noClientUrl, "Hello World");
88+
89+
console.log("Calling PUT using presigned URL with client");
90+
await put(clientUrl, "Hello World");
91+
92+
console.log("\nDone. Check your S3 console.");
6893
} catch (err) {
69-
console.log("Error deleting bucket", err);
94+
console.error(err);
7095
}
7196
};
72-
run();
7397
```

0 commit comments

Comments
 (0)