Skip to content

Commit 9d1011c

Browse files
authored
S3 Cleanup (#4475)
* move and rename s3 files * refactor copy-object example, add tests, clean up metadata * refactor create-bucket example, add tests, clean up metadata * refactor delete-bucket-policy example, add tests, clean up metadata * refactor put-bucket-website example, add tests, clean up metadata * refactor delete-bucket-website example, add tests, clean up metadata * refactor delete-bucket example, add tests, clean up metadata * refactor put-object example, add tests, clean up metadata * refactor delete-object example, add tests, clean up metadata * refactor put-bucket-policy example, add tests, clean up metadata * refactor put-bucket-cors example, add tests, clean up metadata * refactor get-bucket-cors example, add tests, clean up metadata * refactor get-bucket-policy example, add tests, clean up metadata * refactor put-bucket-acl, add test, update metadata * refactor list-objects, add test, update metadata * refactor list-buckets, add test, update metadata * refactor get-object, add test, update metadata * refactor get-bucket-website, add test, update metadata * refactor delete-objects, add test, update metadata * start basic scenario * add upload, list, copy, delete, and empty steps to s3 example * add upload, list, copy, delete, and empty steps to s3 example * finish basic scenario * fix malformed snippets * clean up some excerpt descriptions * update multipart and create/list/delete scenarios * update presigned url examples * update README * update list-objects to handle over 1000 objects * add web-example and test out deprecating snippets * add readme reference to new media items * copy editing
1 parent 4201ec6 commit 9d1011c

File tree

142 files changed

+28878
-28922
lines changed

Some content is hidden

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

142 files changed

+28878
-28922
lines changed

.doc_gen/metadata/s3_metadata.yaml

+80-74
Large diffs are not rendered by default.

.doc_gen/metadata/sdks.yaml

+8-8
Original file line numberDiff line numberDiff line change
@@ -83,21 +83,21 @@ JavaScript:
8383
property: javascript
8484
sdk:
8585
2:
86-
long: "&JSBlong; V2"
87-
short: "&JSB; V2"
86+
long: "&JSBlong; (v2)"
87+
short: "&JSB; (v2)"
8888
expanded:
89-
long: "AWS SDK for JavaScript V2"
90-
short: "SDK for JavaScript V2"
89+
long: "AWS SDK for JavaScript (v2)"
90+
short: "SDK for JavaScript (v2)"
9191
guide: "sdk-for-javascript/v2/developer-guide/welcome.html"
9292
api_ref:
9393
uid: "AWSJavaScriptSDK"
9494
name: "&guide-jsb-api;"
9595
3:
96-
long: "&JSBlong; V3"
97-
short: "&JSB; V3"
96+
long: "&JSBlong; (v3)"
97+
short: "&JSB; (v3)"
9898
expanded:
99-
long: "AWS SDK for JavaScript V3"
100-
short: "SDK for JavaScript V3"
99+
long: "AWS SDK for JavaScript (v3)"
100+
short: "SDK for JavaScript (v3)"
101101
guide: "sdk-for-javascript/v3/developer-guide/welcome.html"
102102
api_ref:
103103
uid: "AWSJavaScriptSDKV3"

.doc_gen/readmes/includes/overview.jinja2

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
## Overview
22

3-
Shows how to use the {{sdk['long']}} to work with {{service['long']}}.
3+
Shows how to use the {{sdk['long']}} to work with {{service['long']}} ({{service['short']}}).
44

55
<!--custom.overview.start-->
66
{{ customs['overview'] -}}

.doc_gen/readmes/includes/run_instructions.jinja2

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ node ./actions/<fileName>
1111
```
1212

1313
**Run a scenario**
14-
14+
Most scenarios can be run with the following command:
1515
```bash
1616
node ./scenarios/<fileName>
1717
```

.github/pre_validate/pre_validate.py

+2
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@
6666
'movies.json',
6767
'speech_sample.mp3',
6868
'chat_sfn_state_machine.json',
69+
'market_2.jpg',
70+
'spheres_2.jpg',
6971
}
7072

7173
# media file types

javascriptv3/example_code/ec2/scenarios/basic.js

+5-44
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ import {
3838
} from "@aws-sdk/client-ec2";
3939
import { paginateGetParametersByPath, SSMClient } from "@aws-sdk/client-ssm";
4040

41+
import { promptToSelect, promptToContinue } from "libs/utils/util-io.js";
42+
import { wrapText } from "libs/utils/util-string.js";
43+
4144
const ec2Client = new EC2Client();
4245
const ssmClient = new SSMClient();
4346

@@ -147,7 +150,7 @@ const getAmznLinux2AMIs = async () => {
147150
const options = imageDetails.map(
148151
(image) => `${image.ImageId} - ${image.Description}`
149152
);
150-
const [selectedIndex] = await promptWithOptions(options);
153+
const [selectedIndex] = await promptToSelect(options);
151154

152155
return imageDetails[selectedIndex];
153156
};
@@ -178,7 +181,7 @@ const getCompatibleInstanceTypes = async (imageDetails) => {
178181
(type) => `${type.InstanceType} - Memory:${type.MemoryInfo.SizeInMiB}`
179182
);
180183

181-
const [selectedIndex] = await promptWithOptions(
184+
const [selectedIndex] = await promptToSelect(
182185
instanceTypeList,
183186
"Select an instance type."
184187
);
@@ -331,48 +334,6 @@ const deleteTemporaryDirectory = () => {
331334
}
332335
};
333336

334-
const wrapText = (text, char = "=") => {
335-
const rule = char.repeat(80);
336-
return `${rule}\n ${text}\n${rule}\n`;
337-
};
338-
339-
const promptToContinue = (prefix) => {
340-
const rl = createInterface({
341-
input: process.stdin,
342-
output: process.stdout,
343-
});
344-
345-
return new Promise((resolve) => {
346-
rl.question(`\nPress enter to continue.\n`, () => {
347-
rl.close();
348-
resolve();
349-
});
350-
});
351-
};
352-
353-
const promptWithOptions = (options, question = "") => {
354-
const rl = createInterface({
355-
input: process.stdin,
356-
output: process.stdout,
357-
});
358-
const optionsList = options.map((opt, i) => `${i + 1}) ${opt}`).join("\n");
359-
360-
return new Promise((resolve) => {
361-
rl.question(`${question}\n${optionsList}\n-> `, (answer) => {
362-
rl.close();
363-
const selected = parseInt(answer);
364-
if (isNaN(selected) || selected < 1 || selected > options.length) {
365-
console.log(
366-
`Invalid option. Select a number between 1 and ${options.length}`
367-
);
368-
resolve(promptWithOptions(options));
369-
} else {
370-
resolve([selected - 1, options[selected - 1]]);
371-
}
372-
});
373-
});
374-
};
375-
376337
export const main = async () => {
377338
const keyPairName = "ec2-scenario-key-pair";
378339
const securityGroupName = "ec2-scenario-security-group";
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { describe, it, expect } from "vitest";
2+
3+
import { promptToSelect } from '../utils/util-io.js'
4+
5+
describe("promptToSelect", () => {
6+
it("should resolve with autoSelected option if it's valid", async () => {
7+
const [selected, option] = await promptToSelect(["foo", "bar"], "", 1);
8+
expect(selected).toEqual(0);
9+
expect(option).toEqual("foo");
10+
});
11+
});

javascriptv3/example_code/libs/utils/util-fs.js

+20-27
Original file line numberDiff line numberDiff line change
@@ -32,53 +32,59 @@ import { fileURLToPath } from "url";
3232
import { log } from "./util-log.js";
3333
import { promiseAll, splitMapTrim } from "../ext-ramda.js";
3434

35-
const deleteFiles = compose(promiseAll, map(unlink));
35+
export const deleteFiles = compose(promiseAll, map(unlink));
3636

37-
const dirnameFromMetaUrl = (metaUrl) => {
37+
// snippet-start:[javascript.v3.utils.dirnameFromMetaUrl]
38+
export const dirnameFromMetaUrl = (metaUrl) => {
3839
return fileURLToPath(new URL(".", metaUrl));
3940
};
41+
// snippet-end:[javascript.v3.utils.dirnameFromMetaUrl]
4042

41-
const getDelimitedEntries = curry((delimiter, str) =>
43+
export const getDelimitedEntries = curry((delimiter, str) =>
4244
pipe(getTmp, defaultTo(""), splitMapTrim(delimiter))(str)
4345
);
4446

45-
const getNewLineDelimitedEntries = getDelimitedEntries("\n");
47+
export const getNewLineDelimitedEntries = getDelimitedEntries("\n");
4648

47-
const getTmp = tryCatch(
49+
export const getTmp = tryCatch(
4850
(name) => readFileSync(`./${name}.tmp`, { encoding: "utf-8" }),
4951
always(null)
5052
);
5153

52-
const setTmp = (name, data) =>
54+
export const setTmp = (name, data) =>
5355
writeFileSync(`./${name}.tmp`, data, { encoding: "utf-8" });
5456

55-
const handleZipWarning = (resolve) => (w) => {
57+
export const handleZipWarning = (resolve) => (w) => {
5658
log(w);
5759
resolve();
5860
};
5961

60-
const handleZipEnd = (resolve, path) => async () => {
62+
export const handleZipEnd = (resolve, path) => async () => {
6163
log(`Zipped successfully.`);
6264
const buffer = await readFile(path);
6365
resolve(buffer);
6466
};
6567

66-
const makeDir = ifElse(existsSync, identity, tap(mkdirSync));
68+
export const makeDir = ifElse(existsSync, identity, tap(mkdirSync));
6769

68-
const readLines = pipe(readFileSync, invoker(0, "toString"), split("\n"));
70+
export const readLines = pipe(
71+
readFileSync,
72+
invoker(0, "toString"),
73+
split("\n")
74+
);
6975

70-
const readSubdirSync = pipe(
76+
export const readSubdirSync = pipe(
7177
readdirSync,
7278
filter(invoker(0, "isDirectory")),
7379
map(prop("name"))
7480
);
7581

7682
/**
77-
*
78-
* @param {string} inputPath
83+
*
84+
* @param {string} inputPath
7985
* @returns {Promise<Buffer>}
8086
*/
81-
const zip = (inputPath) =>
87+
export const zip = (inputPath) =>
8288
new Promise((resolve, reject) => {
8389
try {
8490
readdirSync(inputPath);
@@ -102,16 +108,3 @@ const zip = (inputPath) =>
102108
archive.directory(inputPath, false);
103109
archive.finalize();
104110
});
105-
106-
export {
107-
deleteFiles,
108-
dirnameFromMetaUrl,
109-
getTmp,
110-
makeDir,
111-
readLines,
112-
readSubdirSync,
113-
getDelimitedEntries,
114-
getNewLineDelimitedEntries,
115-
setTmp,
116-
zip,
117-
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
import { createInterface } from "readline";
7+
8+
// snippet-start:[javascript.v3.utils.promptToSelect]
9+
export const promptToSelect = (options, question = "", autoSelect) => {
10+
const rl = createInterface({
11+
input: process.stdin,
12+
output: process.stdout,
13+
});
14+
const selectionInvalid = (selected) =>
15+
isNaN(selected) || selected < 1 || selected > options.length;
16+
const optionsList = options.map((opt, i) => `${i + 1}) ${opt}`).join("\n");
17+
const prompt = `${question}\n${optionsList}\n-> `;
18+
19+
return new Promise((resolve) => {
20+
if (!selectionInvalid(autoSelect)) {
21+
resolve([autoSelect - 1, options[autoSelect - 1]]);
22+
return;
23+
}
24+
25+
rl.question(prompt, (answer) => {
26+
rl.close();
27+
const selected = parseInt(answer);
28+
if (selectionInvalid(selected)) {
29+
console.log(
30+
`Invalid option. Select a number between 1 and ${options.length}`
31+
);
32+
resolve(promptToSelect(options));
33+
} else {
34+
resolve([selected - 1, options[selected - 1]]);
35+
}
36+
});
37+
});
38+
};
39+
// snippet-end:[javascript.v3.utils.promptToSelect]
40+
41+
// snippet-start:[javascript.v3.utils.promptToContinue]
42+
export const promptToContinue = () => {
43+
const rl = createInterface({
44+
input: process.stdin,
45+
output: process.stdout,
46+
});
47+
48+
return new Promise((resolve) => {
49+
rl.question(`\nPress enter to continue.\n`, () => {
50+
rl.close();
51+
resolve();
52+
});
53+
});
54+
};
55+
// snippet-end:[javascript.v3.utils.promptToContinue]
56+
57+
// snippet-start:[javascript.v3.utils.promptForText]
58+
export const promptForText = (question) => {
59+
const rl = createInterface({
60+
input: process.stdin,
61+
output: process.stdout,
62+
});
63+
64+
return new Promise((resolve) => {
65+
rl.question(`${question}\n-> `, (answer) => {
66+
rl.close();
67+
resolve(answer);
68+
});
69+
});
70+
};
71+
// snippet-end:[javascript.v3.utils.promptForText]

javascriptv3/example_code/libs/utils/util-string.js

+13-17
Original file line numberDiff line numberDiff line change
@@ -6,35 +6,31 @@ import { pipe, adjust, join, split, toLower, map, toUpper } from "ramda";
66

77
import { v4 as uuidv4 } from "uuid";
88

9-
const getUniqueName = (name) => `${uuidv4()}-${name.toLowerCase()}`;
9+
export const getUniqueName = (name) => `${uuidv4()}-${name.toLowerCase()}`;
1010

11-
const postfix = (source, str) => {
11+
export const postfix = (source, str) => {
1212
if (typeof str !== "string") {
1313
throw new Error("Cannot postfix a non-string value.");
1414
}
1515

1616
return `${source}${str}`;
1717
};
1818

19-
const downcaseSplit = pipe(toLower, split("-"));
19+
export const downcaseSplit = pipe(toLower, split("-"));
2020

21-
const capitalize = pipe(Array.from, adjust(0, toUpper), join(""));
21+
export const capitalize = pipe(Array.from, adjust(0, toUpper), join(""));
2222

23-
const kebabCase = pipe(downcaseSplit, join("-"));
23+
export const kebabCase = pipe(downcaseSplit, join("-"));
2424

25-
const pascalCase = pipe(downcaseSplit, map(capitalize), join(""));
25+
export const pascalCase = pipe(downcaseSplit, map(capitalize), join(""));
2626

27-
const snakeCase = pipe(downcaseSplit, join("_"));
27+
export const snakeCase = pipe(downcaseSplit, join("_"));
2828

29-
const titleCase = pipe(downcaseSplit, map(capitalize), join(" "));
29+
export const titleCase = pipe(downcaseSplit, map(capitalize), join(" "));
3030

31-
export {
32-
capitalize,
33-
downcaseSplit,
34-
getUniqueName,
35-
kebabCase,
36-
pascalCase,
37-
postfix,
38-
snakeCase,
39-
titleCase
31+
// snippet-start:[javascript.v3.utils.wrapText]
32+
export const wrapText = (text, char = "=") => {
33+
const rule = char.repeat(80);
34+
return `${rule}\n ${text}\n${rule}\n`;
4035
};
36+
// snippet-end:[javascript.v3.utils.wrapText]

0 commit comments

Comments
 (0)