Skip to content

Commit 73e48c8

Browse files
committed
Merge branch 'dotnet-dynamodb-updates' of github.com:rlhagerm/aws-doc-sdk-examples into dotnet-dynamodb-updates
2 parents 0bf4cbf + 68e28aa commit 73e48c8

File tree

28 files changed

+1348
-24
lines changed

28 files changed

+1348
-24
lines changed

.doc_gen/metadata/bedrock-runtime_metadata.yaml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,14 @@ bedrock-runtime_Converse_AmazonNovaText:
100100
- description: Send a text message to Amazon Nova, using Bedrock's Converse API.
101101
snippet_tags:
102102
- bedrock-runtime.java2.Converse_AmazonNovaText
103+
JavaScript:
104+
versions:
105+
- sdk_version: 3
106+
github: javascriptv3/example_code/bedrock-runtime
107+
excerpts:
108+
- description: Send a text message to Amazon Nova, using Bedrock's Converse API.
109+
snippet_tags:
110+
- javascript.v3.bedrock-runtime.Converse_AmazonTitanText
103111
.NET:
104112
versions:
105113
- sdk_version: 3
@@ -423,6 +431,14 @@ bedrock-runtime_ConverseStream_AmazonNovaText:
423431
- description: Send a text message to Amazon Nova using Bedrock's Converse API and process the response stream in real-time.
424432
snippet_tags:
425433
- bedrock-runtime.java2.ConverseStream_AmazonNovaText
434+
JavaScript:
435+
versions:
436+
- sdk_version: 3
437+
github: javascriptv3/example_code/bedrock-runtime
438+
excerpts:
439+
- description: Send a text message to Amazon Nova using Bedrock's Converse API and process the response stream in real-time.
440+
snippet_tags:
441+
- javascript.v3.bedrock-runtime.Converse_Mistral
426442
.NET:
427443
versions:
428444
- sdk_version: 3
@@ -1235,6 +1251,14 @@ bedrock-runtime_InvokeModel_AmazonNovaImageGeneration:
12351251
- description: Create an image with Amazon Nova Canvas.
12361252
snippet_tags:
12371253
- bedrock-runtime.java2.InvokeModel_AmazonNovaImageGeneration
1254+
JavaScript:
1255+
versions:
1256+
- sdk_version: 3
1257+
github: javascriptv3/example_code/bedrock-runtime
1258+
excerpts:
1259+
- description: Create an image with Amazon Nova Canvas.
1260+
snippet_tags:
1261+
- javascript.v3.bedrock-runtime.InvokeModel_AmazonNovaImageGeneration
12381262
.NET:
12391263
versions:
12401264
- sdk_version: 3

.doc_gen/metadata/sqs_metadata.yaml

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,18 @@ sqs_Hello:
5858
- description: Initialize an &SQS; client and list queues.
5959
snippet_tags:
6060
- javascript.v3.sqs.hello
61+
Swift:
62+
versions:
63+
- sdk_version: 1
64+
github: swift/example_code/sqs
65+
sdkguide:
66+
excerpts:
67+
- description: The <code>Package.swift</code> file.
68+
snippet_tags:
69+
- swift.sqs.basics.package
70+
- description: The Swift source code, <code>entry.swift</code>.
71+
snippet_tags:
72+
- swift.sqs.basics
6173
services:
6274
sqs: {ListQueues}
6375
sqs_CreateQueue:
@@ -163,6 +175,15 @@ sqs_CreateQueue:
163175
snippet_tags:
164176
- cpp.example_code.sqs.CreateQueue.config
165177
- cpp.example_code.sqs.CreateQueue
178+
Swift:
179+
versions:
180+
- sdk_version: 1
181+
github: swift/example_code/sqs
182+
sdkguide:
183+
excerpts:
184+
- description:
185+
snippet_tags:
186+
- swift.sqs.CreateQueue
166187
services:
167188
sqs: {CreateQueue}
168189
sqs_GetQueueUrl:
@@ -320,6 +341,15 @@ sqs_ListQueues:
320341
snippet_tags:
321342
- cpp.example_code.sqs.ListQueues.config
322343
- cpp.example_code.sqs.ListQueues
344+
Swift:
345+
versions:
346+
- sdk_version: 1
347+
github: swift/example_code/sqs
348+
sdkguide:
349+
excerpts:
350+
- description:
351+
snippet_tags:
352+
- swift.sqs.ListQueues
323353
services:
324354
sqs: {ListQueues}
325355
sqs_DeleteQueue:
@@ -414,6 +444,15 @@ sqs_DeleteQueue:
414444
snippet_tags:
415445
- cpp.example_code.sqs.DeleteQueue.config
416446
- cpp.example_code.sqs.DeleteQueue
447+
Swift:
448+
versions:
449+
- sdk_version: 1
450+
github: swift/example_code/sqs
451+
sdkguide:
452+
excerpts:
453+
- description:
454+
snippet_tags:
455+
- swift.sqs.DeleteQueue
417456
services:
418457
sqs: {DeleteQueue}
419458
sqs_SendMessage:
@@ -649,6 +688,15 @@ sqs_ReceiveMessage:
649688
snippet_tags:
650689
- cpp.example_code.sqs.ReceiveMessage.config
651690
- cpp.example_code.sqs.ReceiveMessage
691+
Swift:
692+
versions:
693+
- sdk_version: 1
694+
github: swift/example_code/sqs
695+
sdkguide:
696+
excerpts:
697+
- description:
698+
snippet_tags:
699+
- swift.sqs.ReceiveMessage
652700
services:
653701
sqs: {ReceiveMessage}
654702
sqs_DeleteMessage:
@@ -765,6 +813,15 @@ sqs_DeleteMessageBatch:
765813
- description:
766814
snippet_tags:
767815
- sqs.JavaScript.messages.receiveMessageV3
816+
Swift:
817+
versions:
818+
- sdk_version: 1
819+
github: swift/example_code/sqs
820+
sdkguide:
821+
excerpts:
822+
- description:
823+
snippet_tags:
824+
- swift.sqs.DeleteMessageBatch
768825
services:
769826
sqs: {DeleteMessageBatch}
770827
sqs_Scenario_SendReceiveBatch:
@@ -836,6 +893,15 @@ sqs_GetQueueAttributes:
836893
- description:
837894
snippet_tags:
838895
- javascript.v3.sqs.actions.GetQueueAttributes
896+
Swift:
897+
versions:
898+
- sdk_version: 1
899+
github: swift/example_code/sqs
900+
sdkguide:
901+
excerpts:
902+
- description:
903+
snippet_tags:
904+
- swift.sqs.GetQueueAttributes
839905
services:
840906
sqs: {GetQueueAttributes}
841907
sqs_ChangeMessageVisibility:
@@ -931,6 +997,15 @@ sqs_SetQueueAttributes:
931997
- description: Configure a dead-letter queue.
932998
snippet_tags:
933999
- sqs.JavaScript.deadLetter.setQueueAttributesV3
1000+
Swift:
1001+
versions:
1002+
- sdk_version: 1
1003+
github: swift/example_code/sqs
1004+
sdkguide:
1005+
excerpts:
1006+
- description:
1007+
snippet_tags:
1008+
- swift.sqs.SetQueueAttributes
9341009
services:
9351010
sqs: {SetQueueAttributes}
9361011
sqs_Scenario_TopicsAndQueues:
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
/tempx/
2+
/output/

javascriptv3/example_code/bedrock-runtime/README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,15 @@ functions within the same service.
5050
- [Converse](models/ai21LabsJurassic2/converse.js#L4)
5151
- [InvokeModel](models/ai21LabsJurassic2/invoke_model.js)
5252

53+
### Amazon Nova
54+
55+
- [Converse](models/amazonTitanText/converse.js#L4)
56+
- [ConverseStream](models/mistral/converse.js#L4)
57+
58+
### Amazon Nova Canvas
59+
60+
- [InvokeModel](models/amazonNovaCanvas/invokeModel.js#L4)
61+
5362
### Amazon Titan Text
5463

5564
- [Converse](models/amazonTitanText/converse.js#L4)
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
// snippet-start:[javascript.v3.bedrock-runtime.InvokeModel_AmazonNovaImageGeneration]
5+
6+
import {
7+
BedrockRuntimeClient,
8+
InvokeModelCommand,
9+
} from "@aws-sdk/client-bedrock-runtime";
10+
import { saveImage } from "../../utils/image-creation.js";
11+
import { fileURLToPath } from "node:url";
12+
13+
/**
14+
* This example demonstrates how to use Amazon Nova Canvas to generate images.
15+
* It shows how to:
16+
* - Set up the Amazon Bedrock runtime client
17+
* - Configure the image generation parameters
18+
* - Send a request to generate an image
19+
* - Process the response and handle the generated image
20+
*
21+
* @returns {Promise<string>} Base64-encoded image data
22+
*/
23+
export const invokeModel = async () => {
24+
// Step 1: Create the Amazon Bedrock runtime client
25+
// Credentials will be automatically loaded from the environment
26+
const client = new BedrockRuntimeClient({ region: "us-east-1" });
27+
28+
// Step 2: Specify which model to use
29+
// For the latest available models, see:
30+
// https://docs.aws.amazon.com/bedrock/latest/userguide/models-supported.html
31+
const modelId = "amazon.nova-canvas-v1:0";
32+
33+
// Step 3: Configure the request payload
34+
// First, set the main parameters:
35+
// - prompt: Text description of the image to generate
36+
// - seed: Random number for reproducible generation (0 to 858,993,459)
37+
const prompt = "A stylized picture of a cute old steampunk robot";
38+
const seed = Math.floor(Math.random() * 858993460);
39+
40+
// Then, create the payload using the following structure:
41+
// - taskType: TEXT_IMAGE (specifies text-to-image generation)
42+
// - textToImageParams: Contains the text prompt
43+
// - imageGenerationConfig: Contains optional generation settings (seed, quality, etc.)
44+
// For a list of available request parameters, see:
45+
// https://docs.aws.amazon.com/nova/latest/userguide/image-gen-req-resp-structure.html
46+
const payload = {
47+
taskType: "TEXT_IMAGE",
48+
textToImageParams: {
49+
text: prompt,
50+
},
51+
imageGenerationConfig: {
52+
seed,
53+
quality: "standard",
54+
},
55+
};
56+
57+
// Step 4: Send and process the request
58+
// - Embed the payload in a request object
59+
// - Send the request to the model
60+
// - Extract and return the generated image data from the response
61+
try {
62+
const request = {
63+
modelId,
64+
body: JSON.stringify(payload),
65+
};
66+
const response = await client.send(new InvokeModelCommand(request));
67+
68+
const decodedResponseBody = new TextDecoder().decode(response.body);
69+
// The response includes an array of base64-encoded PNG images
70+
/** @type {{images: string[]}} */
71+
const responseBody = JSON.parse(decodedResponseBody);
72+
return responseBody.images[0]; // Base64-encoded image data
73+
} catch (error) {
74+
console.error(`ERROR: Can't invoke '${modelId}'. Reason: ${error.message}`);
75+
throw error;
76+
}
77+
};
78+
79+
// If run directly, execute the example and save the generated image
80+
if (process.argv[1] === fileURLToPath(import.meta.url)) {
81+
console.log("Generating image. This may take a few seconds...");
82+
invokeModel()
83+
.then(async (imageData) => {
84+
const imagePath = await saveImage(imageData, "nova-canvas");
85+
// Example path: javascriptv3/example_code/bedrock-runtime/output/nova-canvas/image-01.png
86+
console.log(`Image saved to: ${imagePath}`);
87+
})
88+
.catch((error) => {
89+
console.error("Execution failed:", error);
90+
process.exitCode = 1;
91+
});
92+
}
93+
// snippet-end:[javascript.v3.bedrock-runtime.InvokeModel_AmazonNovaImageGeneration]
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
// snippet-start:[javascript.v3.bedrock-runtime.Converse_AmazonNovaText]
5+
// This example demonstrates how to use the Amazon Nova foundation models to generate text.
6+
// It shows how to:
7+
// - Set up the Amazon Bedrock runtime client
8+
// - Create a message
9+
// - Configure and send a request
10+
// - Process the response
11+
12+
import {
13+
BedrockRuntimeClient,
14+
ConversationRole,
15+
ConverseCommand,
16+
} from "@aws-sdk/client-bedrock-runtime";
17+
18+
// Step 1: Create the Amazon Bedrock runtime client
19+
// Credentials will be automatically loaded from the environment
20+
const client = new BedrockRuntimeClient({ region: "us-east-1" });
21+
22+
// Step 2: Specify which model to use:
23+
// Available Amazon Nova models and their characteristics:
24+
// - Amazon Nova Micro: Text-only model optimized for lowest latency and cost
25+
// - Amazon Nova Lite: Fast, low-cost multimodal model for image, video, and text
26+
// - Amazon Nova Pro: Advanced multimodal model balancing accuracy, speed, and cost
27+
//
28+
// For the most current model IDs, see:
29+
// https://docs.aws.amazon.com/bedrock/latest/userguide/models-supported.html
30+
const modelId = "amazon.nova-lite-v1:0";
31+
32+
// Step 3: Create the message
33+
// The message includes the text prompt and specifies that it comes from the user
34+
const inputText =
35+
"Describe the purpose of a 'hello world' program in one line.";
36+
const message = {
37+
content: [{ text: inputText }],
38+
role: ConversationRole.USER,
39+
};
40+
41+
// Step 4: Configure the request
42+
// Optional parameters to control the model's response:
43+
// - maxTokens: maximum number of tokens to generate
44+
// - temperature: randomness (max: 1.0, default: 0.7)
45+
// OR
46+
// - topP: diversity of word choice (max: 1.0, default: 0.9)
47+
// Note: Use either temperature OR topP, but not both
48+
const request = {
49+
modelId,
50+
messages: [message],
51+
inferenceConfig: {
52+
maxTokens: 500, // The maximum response length
53+
temperature: 0.5, // Using temperature for randomness control
54+
//topP: 0.9, // Alternative: use topP instead of temperature
55+
},
56+
};
57+
58+
// Step 5: Send and process the request
59+
// - Send the request to the model
60+
// - Extract and return the generated text from the response
61+
try {
62+
const response = await client.send(new ConverseCommand(request));
63+
console.log(response.output.message.content[0].text);
64+
} catch (error) {
65+
console.error(`ERROR: Can't invoke '${modelId}'. Reason: ${error.message}`);
66+
throw error;
67+
}
68+
// snippet-end:[javascript.v3.bedrock-runtime.Converse_AmazonNovaText]

0 commit comments

Comments
 (0)