You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- Modified the content of Index.razor to enhance functionality.
- Improved integration with AWS SDK for Bedrock services.
- Ensured compatibility with existing components and services.
Generated by Copilot
This is the <b>recommended approach for production applications running on EC2</b>. The SDK automatically retrieves credentials from the instance metadata without any code changes.
117
+
The most convenient approach for <b>local development</b> is the AWS shared credentials file. When you run <code>aws configure</code>, the CLI writes your credentials to <code>~/.aws/credentials</code>. The AWS SDK for .NET automatically reads from this file through its default credential resolution chain—no extra code required.
118
118
</p>
119
-
<CodeSnippetLanguage="csharp"Number="4">
120
-
// No credentials needed! The SDK automatically uses the EC2 instance role.
<CalloutBoxType="tip"Title="Set Up in One Command">
143
+
<p>Run <code>aws configure</code> (or <code>aws configure --profile bedrock-dev</code> for a named profile) and answer the prompts. The CLI writes the credentials file for you.</p>
144
+
</CalloutBox>
124
145
</Section>
125
146
126
-
<SectionHeading="Method 4: ECS Task Role (Production on ECS/Fargate)"Level="6">
127
-
<p>For containerized applications running on ECS or Fargate, use an ECS task execution role.</p>
128
-
<CodeSnippetLanguage="csharp"Number="6">
129
-
// No credentials code needed! ECS automatically injects AWS_CONTAINER_CREDENTIALS_RELATIVE_URI
147
+
<SectionHeading="Method 4: EC2 Instance Profile Role (Production on EC2)"Level="6">
148
+
<p>
149
+
This is the <b>recommended approach for production applications running on EC2</b>. The SDK automatically retrieves credentials from the instance metadata without any code changes.
150
+
</p>
151
+
<CodeSnippetLanguage="csharp"Number="4">
152
+
// No credentials needed! The SDK automatically uses the EC2 instance role.
130
153
var bedrockClient = new AmazonBedrockClient(RegionEndpoint.USEast1);
154
+
var runtimeClient = new AmazonBedrockRuntimeClient(RegionEndpoint.USEast1);
131
155
</CodeSnippet>
132
-
<p>The IAM permissions are the same as EC2 Instance Profile. Configure the task role in your ECS task definition.</p>
133
156
</Section>
134
157
135
158
<SectionHeading="Creating the EC2 Instance Profile Role"Level="6">
<SectionHeading="5. Invoking a Model (Anthropic Claude)"Level="5">
242
+
<p>The <code>BedrockService</code> class in the <b>AwsBedrockExamples</b> project wraps the Invoke API to query movie details. Here is the core invocation logic from <ahref="https://github.com/ajaysskumar/ai-playground/blob/main/AwsBedrockExamples/Services/BedrockService.cs"target="_blank">BedrockService.cs</a>:</p>
219
243
<CodeSnippetLanguage="csharp"Number="4">
220
-
var invokeRequest = new InvokeModelRequest
244
+
public async Task<string> GetMovieDetails(string movieQuery)
using var reader = new System.IO.StreamReader(invokeResponse.Body);
242
-
var responseText = await reader.ReadToEndAsync();
276
+
<SectionHeading="6. Putting It All Together"Level="5">
277
+
<p>Here's how you'd use <code>BedrockService</code> from the <b>AwsBedrockExamples</b> solution to query movie details end-to-end. For the full source, see <ahref="https://github.com/ajaysskumar/ai-playground/blob/main/AwsBedrockExamples/Services/BedrockService.cs"target="_blank">BedrockService.cs on GitHub</a>.</p>
@@ -265,26 +304,9 @@ var responseText = await reader.ReadToEndAsync();
265
304
}
266
305
]
267
306
</CodeSnippet>
268
-
</Section>
269
-
270
-
<SectionHeading="6. Putting It All Together"Level="5">
271
-
<p>Here's a minimal, complete example. For a full version, see the linked GitHub repository:</p>
272
-
<CodeSnippetLanguage="csharp"Number="6">
273
-
// ...library references and using statements...
274
-
275
-
AmazonBedrockClient bedrockClient = new AmazonBedrockClient(GetCredentials());
276
-
await ListAvailableModels(bedrockClient);
277
-
278
-
// Prepare and invoke the model
279
-
// ...invokeRequest as above...
280
-
281
-
var runtimeClient = new AmazonBedrockRuntimeClient(GetCredentials());
282
-
var invokeResponse = await runtimeClient.InvokeModelAsync(invokeRequest);
283
-
using var reader = new System.IO.StreamReader(invokeResponse.Body);
284
-
var responseText = await reader.ReadToEndAsync();
285
-
286
-
FormatAndPrintResponse(responseText);
287
-
</CodeSnippet>
307
+
<CalloutBoxType="tip"Title="Full Example on GitHub">
308
+
<p>See the complete <code>BedrockService</code> implementation including response parsing in the <ahref="https://github.com/ajaysskumar/ai-playground/blob/main/AwsBedrockExamples/Services/BedrockService.cs"target="_blank">BedrockService.cs</a> file on GitHub.</p>
<li><ahref="https://docs.aws.amazon.com/sdk-for-net/v3/developer-guide/"target="_blank">AWS SDK for .NET</a></li>
306
-
<li><ahref="https://github.com/ajaysskumar/dev-arena/blob/main/reference/notebooks/aws-bedrock-demo.ipynb"target="_blank">Complete working example on GitHub</a></li>
328
+
<li><ahref="https://github.com/ajaysskumar/ai-playground/blob/main/AwsBedrockExamples/Services/BedrockService.cs"target="_blank">BedrockService.cs on GitHub</a></li>
0 commit comments