Skip to content

Commit 59bc844

Browse files
committed
JavaScript (v3): EC2 - Update basics example to match team accessibility guidelines.
1 parent 1cdbf51 commit 59bc844

File tree

10 files changed

+94
-95
lines changed

10 files changed

+94
-95
lines changed

javascriptv3/example_code/bedrock-runtime/scenarios/cli_text_playground.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ const printDetails = new ScenarioOutput(
4242
* @param {{ model: ModelConfig, prompt: string }} c
4343
*/
4444
(c) => console.log(`Invoking ${c.model.modelName} with '${c.prompt}'...`),
45-
{ slow: false },
4645
);
4746

4847
const invokeModel = new ScenarioAction(
@@ -63,7 +62,6 @@ const printResponse = new ScenarioOutput(
6362
* @param {{ response: string }} c
6463
*/
6564
(c) => c.response,
66-
{ slow: false },
6765
);
6866

6967
const scenario = new Scenario("Amazon Bedrock Runtime Demo", [

javascriptv3/example_code/cross-services/wkflw-topics-queues/README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@ The sample code builds a command line application that asks you for input. This
3434
1. Install dependencies. `npm i`
3535
2. Run the example. `node index.js`
3636

37-
**Note**: By default the prompts in the example will print slowly for readability. To disable this, pass the `--no-logger-delay` option.
38-
3937
## Tests
4038

4139
⚠ Running tests might result in charges to your AWS account.

javascriptv3/example_code/cross-services/wkflw-topics-queues/index.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,12 @@ import { SQSClient } from "@aws-sdk/client-sqs";
99

1010
import { TopicsQueuesWkflw } from "./TopicsQueuesWkflw.js";
1111
import { Prompter } from "@aws-doc-sdk-examples/lib/prompter.js";
12-
import { SlowLogger } from "@aws-doc-sdk-examples/lib/slow-logger.js";
1312

1413
export const startSnsWorkflow = () => {
15-
const noLoggerDelay = process.argv.find((arg) => arg === "--no-logger-delay");
1614
const snsClient = new SNSClient({});
1715
const sqsClient = new SQSClient({});
1816
const prompter = new Prompter();
19-
const logger = noLoggerDelay ? console : new SlowLogger(25);
17+
const logger = console
2018

2119
const wkflw = new TopicsQueuesWkflw(snsClient, sqsClient, prompter, logger);
2220

javascriptv3/example_code/ec2/scenarios/basic.js

Lines changed: 42 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -120,23 +120,51 @@ export const ec2Scenario = new Scenario(
120120
/**
121121
* Run the EC2 introductory scenario. This will make changes
122122
* in your AWS account.
123-
* @param {{ confirmAll: boolean, verbose: boolean }} options
123+
* @param {{ confirmAll: boolean, verbose: boolean, noArt: boolean }} options
124124
*/
125-
export const main = async ({ confirmAll, verbose }) => {
126-
await ec2Scenario.run({ confirmAll, verbose });
125+
export const main = async ({ confirmAll, verbose, noArt }) => {
126+
await ec2Scenario.run({ confirmAll, verbose, noArt });
127127
};
128128

129-
// Call function if run directly.
130-
import { fileURLToPath } from "node:url";
129+
// Call function if run directly
131130
import { parseArgs } from "node:util";
132-
if (process.argv[1] === fileURLToPath(import.meta.url)) {
133-
const { values } = parseArgs({
134-
options: {
135-
yes: {
136-
type: "boolean",
137-
short: "y",
138-
},
131+
import {
132+
isMain,
133+
validateArgs,
134+
printManPage,
135+
} from "@aws-doc-sdk-examples/lib/utils/util-node.js";
136+
137+
const loadArgs = () => {
138+
const options = {
139+
help: {
140+
type: "boolean",
141+
},
142+
confirmAll: {
143+
type: "boolean",
144+
description: "Skip user input.",
139145
},
140-
});
141-
main({ confirmAll: values.yes });
146+
noArt: {
147+
type: "boolean",
148+
description: "Do not display ASCII art or text decorations.",
149+
},
150+
};
151+
const results = parseArgs({ options });
152+
const { errors } = validateArgs({ options }, results);
153+
if (results.values.help) {
154+
printManPage(options, {
155+
name: "EC2 Basics",
156+
description: "Learn the basic SDK commands for Amazon EC2.",
157+
synopsis: "node basics.js [OPTIONS]",
158+
});
159+
}
160+
return { errors, results };
161+
};
162+
163+
if (isMain(import.meta.url)) {
164+
const { errors, results } = loadArgs();
165+
if (errors) {
166+
console.error(errors.join("\n"));
167+
} else if (!results.values.help) {
168+
main(results.values);
169+
}
142170
}

javascriptv3/example_code/ec2/scenarios/steps.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,16 @@ export const exitOnNoConfirm = new ScenarioAction(
8282

8383
export const greeting = new ScenarioOutput(
8484
"greeting",
85-
`Welcome to the Amazon EC2 basic usage scenario.
85+
`
86+
87+
Welcome to the Amazon EC2 basic usage scenario.
88+
8689
Before you launch an instances, you'll need to provide a few things:
87-
A key pair - This is for SSH access to your EC2 instance. You only need to provide the name.
88-
A security group - This is used for configuring access to your instance. Again, only the name is needed.
89-
An IP address - Your public IP address will be fetched.
90-
An Amazon Machine Image (AMI)
91-
A compatible instance type`,
90+
- A key pair - This is for SSH access to your EC2 instance. You only need to provide the name.
91+
- A security group - This is used for configuring access to your instance. Again, only the name is needed.
92+
- An IP address - Your public IP address will be fetched.
93+
- An Amazon Machine Image (AMI)
94+
- A compatible instance type`,
9295
{ header: true, preformatted: true, skipWhen: skipWhenErrors },
9396
);
9497

@@ -376,7 +379,7 @@ export const provideImage = new ScenarioInput(
376379
type: "select",
377380
choices: (/** @type { State } */ state) =>
378381
state.images.map((image) => ({
379-
name: `${image.ImageId} - ${image.Description}`,
382+
name: `${image.Description}`,
380383
value: image,
381384
})),
382385
default: (/** @type { State } */ state) => state.images[0],
@@ -804,7 +807,7 @@ export const logErrors = new ScenarioOutput(
804807
"logErrors",
805808
(/** @type {State}*/ state) => {
806809
const errorList = state.errors
807-
.map((err) => ` ${err.name}: ${err.message}`)
810+
.map((err) => ` - ${err.name}: ${err.message}`)
808811
.join("\n");
809812
return `Scenario errors found:\n${errorList}`;
810813
},

javascriptv3/example_code/libs/scenario/scenario.js

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@
33

44
import { Prompter } from "../prompter.js";
55
import { Logger } from "../logger.js";
6-
import { SlowLogger } from "../slow-logger.js";
76

87
/**
9-
* @typedef {{ confirmAll: boolean, verbose: boolean }} StepHandlerOptions
8+
* @typedef {{ confirmAll: boolean, verbose: boolean, noArt: boolean }} StepHandlerOptions
109
*/
1110

1211
/**
@@ -56,7 +55,7 @@ export class Step {
5655
}
5756

5857
/**
59-
* @typedef {{ slow: boolean, header: boolean, preformatted: boolean }} ScenarioOutputOptions
58+
* @typedef {{ header: boolean, preformatted: boolean }} ScenarioOutputOptions
6059
*/
6160

6261
/**
@@ -68,10 +67,9 @@ export class ScenarioOutput extends Step {
6867
* @param {string | (state: Record<string, any>) => string | false} value
6968
* @param {Step<ScenarioOutputOptions>['stepOptions']} [scenarioOutputOptions]
7069
*/
71-
constructor(name, value, scenarioOutputOptions = { slow: true }) {
70+
constructor(name, value, scenarioOutputOptions = {}) {
7271
super(name, scenarioOutputOptions);
7372
this.value = value;
74-
this.slowLogger = new SlowLogger(20);
7573
this.logger = new Logger();
7674
}
7775

@@ -95,14 +93,15 @@ export class ScenarioOutput extends Step {
9593
}
9694
const paddingTop = "\n";
9795
const paddingBottom = "\n";
98-
const logger =
99-
this.stepOptions?.slow && !stepHandlerOptions?.confirmAll
100-
? this.slowLogger
101-
: this.logger;
96+
const logger = this.logger
10297
const message = paddingTop + output + paddingBottom;
10398

10499
if (this.stepOptions?.header) {
105-
await this.logger.log(this.logger.box(message));
100+
if (stepHandlerOptions.noArt === true) {
101+
await this.logger.log(message)
102+
} else {
103+
await this.logger.log(this.logger.box(message));
104+
}
106105
} else {
107106
await logger.log(message, this.stepOptions?.preformatted);
108107
}

javascriptv3/example_code/libs/slow-logger.js

Lines changed: 0 additions & 53 deletions
This file was deleted.

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,33 @@ export const validateArgs = (config, results) => {
4141

4242
return { errors };
4343
};
44+
45+
/**
46+
* Take a list of options and program info and print a man page.
47+
* @param {Record<string, {} extends { required?: boolean, description?: string }>} options
48+
* @param {{ name: string, synopsis: string, description: string }} programInfo
49+
*/
50+
export const printManPage = (options, programInfo) => {
51+
const { name, synopsis, description } = programInfo;
52+
53+
console.log("NAME");
54+
console.log(` ${name}`);
55+
console.log();
56+
console.log("SYNOPSIS");
57+
console.log(` ${synopsis}`);
58+
console.log();
59+
console.log("DESCRIPTION");
60+
console.log(` ${description}`);
61+
console.log();
62+
console.log("OPTIONS");
63+
64+
const optionPadding =
65+
Math.max(...Object.keys(options).map((key) => key.length)) + 4;
66+
67+
for (const [key, value] of Object.entries(options)) {
68+
const paddedKey = `--${key}`.padEnd(optionPadding);
69+
console.log(
70+
` ${paddedKey}${value.type}${(value.description ?? "") && ` - ${value.description}`}`,
71+
);
72+
}
73+
};

javascriptv3/example_code/medical-imaging/scenarios/health-image-sets/image-frame-steps.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,5 +121,4 @@ export const outputImageFrameIds = new ScenarioOutput(
121121

122122
return output;
123123
},
124-
{ slow: false },
125124
);

javascriptv3/example_code/sagemaker/scenarios/wkflw-sagemaker-geospatial-pipeline/index.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,11 @@ import { SQSClient } from "@aws-sdk/client-sqs";
1010
import { S3Client } from "@aws-sdk/client-s3";
1111

1212
import { Prompter } from "@aws-doc-sdk-examples/lib/prompter.js";
13-
import { SlowLogger } from "@aws-doc-sdk-examples/lib/slow-logger.js";
1413

1514
import { SageMakerPipelinesWkflw } from "./SageMakerPipelinesWkflw.js";
1615

1716
const prompter = new Prompter();
18-
const logger = new SlowLogger(25);
17+
const logger = console;
1918

2019
export async function main() {
2120
const pipelineWkfw = new SageMakerPipelinesWkflw(prompter, logger, {

0 commit comments

Comments
 (0)