steering_docs/dotnet-tech/basics_scenario.md
šØ CRITICAL - Must be completed BEFORE any code generation
# Step 1: List available knowledge bases
ListKnowledgeBases()
# Step 2: Query coding standards (REQUIRED)
QueryKnowledgeBases("coding-standards-KB", "DotNet-code-example-standards")
# Step 3: Query implementation patterns (REQUIRED)
QueryKnowledgeBases("DotNet-premium-KB", ".NET implementation patterns structure")
# Step 4: AWS service research (REQUIRED)
search_documentation("What is [AWS Service] and what are its key API operations?")
read_documentation("https://docs.aws.amazon.com/[service]/latest/[relevant-page]")
FAILURE TO COMPLETE KNOWLEDGE BASE CONSULTATION WILL RESULT IN INCORRECT CODE STRUCTURE
Generate interactive scenarios that demonstrate complete workflows using multiple service operations in a guided, educational manner. Implementation must be based on the service SPECIFICATION.md file.
scenarios/basics/{service}/SPECIFICATION.mddotnetv4/{Service}/Scenarios/{Service}_Basics/
āāā {Service}Basics.cs # Main scenario file
āāā {Service}Basics.csproj # Project file
CRITICAL: Always read scenarios/basics/{service}/SPECIFICATION.md first to understand:
From the specification, identify:
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
/// <summary>
/// Purpose
///
/// Shows how to use {AWS Service} to {scenario description}. This scenario demonstrates:
///
/// 1. {Phase 1 description}
/// 2. {Phase 2 description}
/// 3. {Phase 3 description}
/// 4. {Phase 4 description}
///
/// This example uses the AWS SDK for .NET v4 to interact with {AWS Service}.
/// </summary>
using System;
using System.Threading.Tasks;
using Amazon.{Service};
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
namespace Amazon.DocSamples.{Service}
{
public class {Service}Basics
{
private static ILogger logger = null!;
private static {Service}Wrapper wrapper = null!;
private static string? resourceId = null;
/// <summary>
/// Main entry point for the {AWS Service} basics scenario.
/// </summary>
/// <param name="args">Command line arguments.</param>
public static async Task Main(string[] args)
{
using var host = Host.CreateDefaultBuilder(args)
.ConfigureServices((_, services) =>
services.AddAWSService<IAmazon{Service}>()
.AddTransient<{Service}Wrapper>()
)
.Build();
logger = LoggerFactory.Create(builder => { builder.AddConsole(); })
.CreateLogger<{Service}Basics>();
wrapper = host.Services.GetRequiredService<{Service}Wrapper>();
await RunScenario();
}
/// <summary>
/// Runs the {AWS Service} basics scenario.
/// </summary>
public static async Task RunScenario()
{
Console.WriteLine(new string('-', 88));
Console.WriteLine("Welcome to the {AWS Service} basics scenario!");
Console.WriteLine(new string('-', 88));
Console.WriteLine("{Service description and what users will learn}");
Console.WriteLine();
try
{
await SetupPhase();
await DemonstrationPhase();
await ExaminationPhase();
}
catch (Exception ex)
{
logger.LogError("Scenario failed: {Message}", ex.Message);
Console.WriteLine($"The scenario encountered an error: {ex.Message}");
}
finally
{
await CleanupPhase();
}
}
/// <summary>
/// Setup phase: Implement based on specification's Setup section.
/// </summary>
private static async Task SetupPhase()
{
Console.WriteLine("Setting up {AWS Service}...");
Console.WriteLine();
// Example: Check for existing resources (from specification)
var existingResources = await wrapper.ListResourcesAsync();
if (existingResources.Count > 0)
{
Console.WriteLine($"Found {existingResources.Count} existing resource(s):");
foreach (var resource in existingResources)
{
Console.WriteLine($" - {resource}");
}
Console.Write("Would you like to use an existing resource? (y/n): ");
var useExisting = Console.ReadLine()?.ToLower() == "y";
if (useExisting)
{
resourceId = existingResources[0];
return;
}
}
}
/// <summary>
/// Demonstration phase: Implement operations from specification.
/// </summary>
private static async Task DemonstrationPhase()
{
Console.WriteLine("Demonstrating {AWS Service} capabilities...");
Console.WriteLine();
// Implement specific operations from specification
// Example: Generate sample data if specified
await wrapper.CreateSampleDataAsync(resourceId);
Console.WriteLine("ā Sample data created successfully");
// Wait if specified in the specification
Console.WriteLine("Waiting for data to be processed...");
await Task.Delay(5000);
}
/// <summary>
/// Examination phase: Implement data analysis from specification.
/// </summary>
private static async Task ExaminationPhase()
{
Console.WriteLine("Examining {AWS Service} data...");
Console.WriteLine();
// List and examine data as specified
var dataItems = await wrapper.ListDataAsync(resourceId);
if (dataItems.Count == 0)
{
Console.WriteLine("No data found. Data may take a few minutes to appear.");
return;
}
Console.WriteLine($"Found {dataItems.Count} data item(s)");
// Get detailed information as specified
var detailedData = await wrapper.GetDataDetailsAsync(resourceId, dataItems.Take(5).ToList());
DisplayDataSummary(detailedData);
// Show detailed view if specified
if (detailedData.Count > 0)
{
Console.Write("Would you like to see detailed information? (y/n): ");
var showDetails = Console.ReadLine()?.ToLower() == "y";
if (showDetails)
{
DisplayDataDetails(detailedData[0]);
}
}
// Filter data as specified
FilterDataByCriteria(dataItems);
}
/// <summary>
/// Cleanup phase: Implement cleanup options from specification.
/// </summary>
private static async Task CleanupPhase()
{
if (string.IsNullOrEmpty(resourceId))
return;
Console.WriteLine("Cleanup options:");
Console.WriteLine("Note: Deleting the resource will stop all monitoring/processing.");
Console.Write("Would you like to delete the resource? (y/n): ");
var deleteResource = Console.ReadLine()?.ToLower() == "y";
if (deleteResource)
{
try
{
await wrapper.DeleteResourceAsync(resourceId);
Console.WriteLine($"ā Deleted resource: {resourceId}");
}
catch (Exception ex)
{
Console.WriteLine($"Error deleting resource: {ex.Message}");
}
}
else
{
Console.WriteLine($"Resource {resourceId} will continue running.");
Console.WriteLine("You can manage it through the AWS Console or delete it later.");
}
}
}
}
# Yes/No questions
use_existing = q.ask("Use existing resource? (y/n): ", q.is_yesno)
# Text input
resource_name = q.ask("Enter resource name: ")
# Numeric input
count = q.ask("How many items? ", q.is_int)
# Progress indicators
print("ā Operation completed successfully")
print("ā Warning message")
print("ā Error occurred")
# Formatted output
print("-" * 60)
print(f"Found {len(items)} items:")
for item in items:
print(f" ⢠{item['name']}")
The specification includes an "Errors" section with specific error codes and handling:
// Example error handling based on specification
try
{
var response = await wrapper.CreateResourceAsync();
return response;
}
catch (Amazon{Service}Exception ex)
{
var errorCode = ex.ErrorCode;
if (errorCode == "BadRequestException")
{
// Handle as specified: "Validate input parameters and notify user"
Console.WriteLine("Invalid configuration. Please check your parameters.");
}
else if (errorCode == "InternalServerErrorException")
{
// Handle as specified: "Retry operation with exponential backoff"
Console.WriteLine("Service temporarily unavailable. Retrying...");
// Implement retry logic
}
else
{
Console.WriteLine($"Unexpected error: {ex.Message}");
}
throw;
}
scenarios/basics/{service}/SPECIFICATION.mdscenarios/basics/{service}/SPECIFICATION.md thoroughly.NET v4 Project Organization Standards
This section outlines the standardized project structure and organization for .NET v4 AWS SDK examples, based on the Redshift implementation.
dotnetv4/{Service}/
āāā Actions/
ā āāā Hello{Service}.cs # Hello example (with Main method)
ā āāā {Service}Wrapper.cs # Service wrapper class
ā āāā {Service}Actions.csproj # Actions project file
āāā Scenarios/
ā āāā {Service}Basics.cs # Basics scenario
ā āāā {Service}Basics.csproj # Scenarios project file
āāā Tests/
ā āāā {Service}IntegrationTests.cs # Integration tests
ā āāā {Service}Tests.csproj # Test project file
āāā {Service}Examples.sln # Service-specific solution file
RedshiftExamples.sln){Service}Examples.sln for consistency<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<LangVersion>latest</LangVersion>
<AssemblyName>{Service}Actions</AssemblyName>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="AWSSDK.Extensions.NETCore.Setup" Version="3.7.301" />
<PackageReference Include="AWSSDK.{Service}" Version="3.7.500" />
<PackageReference Include="AWSSDK.{ServiceDataAPI}" Version="3.7.500" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="9.0.0" />
</ItemGroup>
<ItemGroup>
<Content Include="settings.*.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<DependentUpon>settings.json</DependentUpon>
</Content>
</ItemGroup>
</Project>
Key Points:
<OutputType>Exe</OutputType> - Required for Hello example Main method<TargetFramework>net8.0</TargetFramework> - Use .NET 8.0<LangVersion>latest</LangVersion> - Enable latest C# features<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<LangVersion>latest</LangVersion>
<AssemblyName>{Service}Basics</AssemblyName>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="AWSSDK.{Service}" Version="3.7.500" />
<PackageReference Include="AWSSDK.{ServiceDataAPI}" Version="3.7.500" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Actions\{Service}Actions.csproj" />
</ItemGroup>
<ItemGroup>
<Content Include="settings.*.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<DependentUpon>settings.json</DependentUpon>
</Content>
</ItemGroup>
</Project>
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<IsPackable>false</IsPackable>
<Nullable>enable</Nullable>
<LangVersion>latest</LangVersion>
<AssemblyName>{Service}Tests</AssemblyName>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageReference Include="MSTest.TestAdapter" Version="3.6.3" />
<PackageReference Include="MSTest.TestFramework" Version="3.6.3" />
<PackageReference Include="coverlet.collector" Version="6.0.2" />
<PackageReference Include="AWSSDK.{Service}" Version="3.7.500" />
<PackageReference Include="AWSSDK.{ServiceDataAPI}" Version="3.7.500" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Actions\{Service}Actions.csproj" />
</ItemGroup>
<ItemGroup>
<Content Include="settings.*.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<DependentUpon>settings.json</DependentUpon>
</Content>
</ItemGroup>
</Project>
Key Points:
<OutputType> - tests are libraries# Navigate to service directory
cd dotnetv4/{Service}
# Create solution file
dotnet new sln -n {Service}Examples
# Add projects
dotnet sln {Service}Examples.sln add Actions/{Service}Actions.csproj
dotnet sln {Service}Examples.sln add Scenarios/{Service}Basics.csproj
dotnet sln {Service}Examples.sln add Tests/{Service}Tests.csproj
# Build solution
dotnet build {Service}Examples.sln
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.5.33414.496
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "{Service}Actions", "Actions\{Service}Actions.csproj", "{GUID1}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "{Service}Basics", "Scenarios\{Service}Basics.csproj", "{GUID2}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "{Service}Tests", "Tests\{Service}Tests.csproj", "{GUID3}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{GUID1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{GUID1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{GUID1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{GUID1}.Release|Any CPU.Build.0 = Release|Any CPU
{GUID2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{GUID2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{GUID2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{GUID2}.Release|Any CPU.Build.0 = Release|Any CPU
{GUID3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{GUID3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{GUID3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{GUID3}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {SOLUTION-GUID}
EndGlobalSection
EndGlobal
// ā
CORRECT - File-scoped namespace
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
using System;
using System.Threading.Tasks;
using Amazon.Redshift;
namespace RedshiftActions;
public class HelloRedshift
{
public static async Task Main(string[] args)
{
// Implementation
}
}
// ā WRONG - Traditional namespace
namespace RedshiftActions
{
public class HelloRedshift
{
public static async Task Main(string[] args)
{
// Implementation
}
}
}
CRITICAL: Use the correct snippet tag format for all code examples:
// ā
CORRECT - Service name first, then dotnetv4
// snippet-start:[{Service}.dotnetv4.CreateClusterSteering]
public async Task<Cluster> CreateClusterAsync(...)
{
// Implementation
}
// snippet-end:[{Service}.dotnetv4.CreateClusterSteering]
// ā WRONG - Old format
// snippet-start:[dotnetv4.example_code.redshift.CreateClusterSteering]
// snippet-end:[dotnetv4.example_code.redshift.CreateClusterSteering]
Format: [{Service}.dotnetv4.{ActionName}]
.dotnetv4.[{Service}.dotnetv4.{Service}Wrapper][{Service}.dotnetv4.{Service}Scenario]// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
using System;
using System.Threading.Tasks;
using Amazon.Redshift;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using RedshiftActions;
namespace RedshiftTests;
[TestClass]
public class RedshiftIntegrationTests
{
private static RedshiftWrapper? _redshiftWrapper;
[ClassInitialize]
public static void ClassInitialize(TestContext context)
{
// Initialize clients
}
[ClassCleanup]
public static async Task ClassCleanup()
{
// Clean up resources
}
[TestMethod]
[TestCategory("Integration")]
public async Task TestOperation()
{
// Test implementation
}
}
When updating existing projects to new standards:
<OutputType>Exe</OutputType> to Actions project<LangVersion>latest</LangVersion> to all projects# Build solution
dotnet build dotnetv4/{Service}/{Service}Examples.sln
# Run all tests
dotnet test dotnetv4/{Service}/{Service}Examples.sln
# Run integration tests only
dotnet test dotnetv4/{Service}/Tests/{Service}Tests.csproj --filter TestCategory=Integration
# Run Hello example
dotnet run --project dotnetv4/{Service}/Actions/{Service}Actions.csproj
# Run Basics scenario
dotnet run --project dotnetv4/{Service}/Scenarios/{Service}Basics.csproj
Solution: Update all AWS SDK packages to latest version (e.g., 3.7.401)
Solution: Add <LangVersion>latest</LangVersion> to all project files
Solution: Ensure Actions project has <OutputType>Exe</OutputType>
Solution: Check indentation - no extra level after file-scoped namespace
Solution: Ensure using MSTest attributes ([TestClass], [TestMethod])
steering_docs/dotnet-tech.mdsteering_docs/dotnet-tech/hello.mdsteering_docs/dotnet-tech/tests.mdsteering_docs/dotnet-tech/wrapper.md