steering_docs/java-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", "Java-code-example-standards")
# Step 3: Query implementation patterns (REQUIRED)
QueryKnowledgeBases("Java-premium-KB", "Java 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.mdjavav2/example_code/{service}/
āāā src/main/java/com/example/{service}/
ā āāā {Service}Scenario.java # Main scenario file
ā āāā {Service}Actions.java # Actions class (if not exists)
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
package com.example.{service};
import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.{service}.{Service}Client;
import software.amazon.awssdk.services.{service}.model.*;
import software.amazon.awssdk.core.exception.SdkException;
import java.util.List;
import java.util.Scanner;
import java.util.concurrent.TimeUnit;
/**
* Before running this Java V2 code example, set up your development
* environment, including your credentials.
*
* For more information, see the following documentation topic:
*
* https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/get-started.html
*
* This Java code example performs the following tasks:
*
* 1. {Phase 1 description}
* 2. {Phase 2 description}
* 3. {Phase 3 description}
* 4. {Phase 4 description}
*/
// snippet-start:[{service}.java2.{service}_scenario.main]
public class {Service}Scenario {
public static final String DASHES = new String(new char[80]).replace("\0", "-");
private static {Service}Actions {service}Actions;
private static Scanner scanner = new Scanner(System.in);
private static String resourceId;
public static void main(String[] args) {
final String usage = """
Usage:
<region>
Where:
region - The AWS region (for example, us-east-1).
""";
if (args.length != 1) {
System.out.println(usage);
System.exit(1);
}
String region = args[0];
Region awsRegion = Region.of(region);
{Service}Client {service}Client = {Service}Client.builder()
.region(awsRegion)
.build();
{service}Actions = new {Service}Actions();
System.out.println(DASHES);
System.out.println("Welcome to the {AWS Service} basics scenario!");
System.out.println(DASHES);
System.out.println("""
{Service description and what users will learn}
""");
try {
runScenario({service}Client);
} catch (Exception e) {
System.err.println("Scenario failed: " + e.getMessage());
e.printStackTrace();
} finally {
{service}Client.close();
}
}
private static void runScenario({Service}Client {service}Client) throws InterruptedException {
try {
setupPhase({service}Client);
demonstrationPhase({service}Client);
examinationPhase({service}Client);
} catch (Exception e) {
System.err.println("Error during scenario execution: " + e.getMessage());
throw e;
} finally {
cleanupPhase({service}Client);
}
}
private static void setupPhase({Service}Client {service}Client) {
System.out.println(DASHES);
System.out.println("Setting up {AWS Service}...");
System.out.println(DASHES);
try {
// Example: Check for existing resources (from specification)
List<{Resource}> existingResources = {service}Actions.listResources({service}Client);
if (!existingResources.isEmpty()) {
System.out.println("Found " + existingResources.size() + " existing resource(s):");
for ({Resource} resource : existingResources) {
System.out.println(" - " + resource.{resourceName}());
}
System.out.print("Would you like to use an existing resource? (y/n): ");
String useExisting = scanner.nextLine();
if (useExisting.toLowerCase().startsWith("y")) {
resourceId = existingResources.get(0).{resourceId}();
return;
}
}
// Create new resource as specified
System.out.println("Creating new resource...");
resourceId = {service}Actions.createResource({service}Client);
System.out.println("ā Resource created successfully: " + resourceId);
} catch (SdkException e) {
System.err.println("Error during setup: " + e.getMessage());
throw e;
}
}
private static void demonstrationPhase({Service}Client {service}Client) throws InterruptedException {
System.out.println(DASHES);
System.out.println("Demonstrating {AWS Service} capabilities...");
System.out.println(DASHES);
try {
// Implement specific operations from specification
// Example: Generate sample data if specified
{service}Actions.createSampleData({service}Client, resourceId);
System.out.println("ā Sample data created successfully");
// Wait if specified in the specification
System.out.println("Waiting for data to be processed...");
TimeUnit.SECONDS.sleep(5);
} catch (SdkException e) {
System.err.println("Error during demonstration: " + e.getMessage());
throw e;
}
}
private static void examinationPhase({Service}Client {service}Client) {
System.out.println(DASHES);
System.out.println("Examining {AWS Service} data...");
System.out.println(DASHES);
try {
// List and examine data as specified
List<{DataItem}> dataItems = {service}Actions.listData({service}Client, resourceId);
if (dataItems.isEmpty()) {
System.out.println("No data found. Data may take a few minutes to appear.");
return;
}
System.out.println("Found " + dataItems.size() + " data item(s)");
// Get detailed information as specified
List<{DetailedData}> detailedData = {service}Actions.getDataDetails({service}Client, resourceId,
dataItems.subList(0, Math.min(5, dataItems.size())));
displayDataSummary(detailedData);
// Show detailed view if specified
if (!detailedData.isEmpty()) {
System.out.print("Would you like to see detailed information? (y/n): ");
String showDetails = scanner.nextLine();
if (showDetails.toLowerCase().startsWith("y")) {
displayDataDetails(detailedData.get(0));
}
}
// Filter data as specified
filterDataByCriteria(dataItems);
} catch (SdkException e) {
System.err.println("Error during examination: " + e.getMessage());
throw e;
}
}
private static void cleanupPhase({Service}Client {service}Client) {
if (resourceId == null) {
return;
}
System.out.println(DASHES);
System.out.println("Cleanup options:");
System.out.println("Note: Deleting the resource will stop all monitoring/processing.");
System.out.println(DASHES);
System.out.print("Would you like to delete the resource? (y/n): ");
String deleteResource = scanner.nextLine();
if (deleteResource.toLowerCase().startsWith("y")) {
try {
{service}Actions.deleteResource({service}Client, resourceId);
System.out.println("ā Deleted resource: " + resourceId);
} catch (SdkException e) {
System.err.println("Error deleting resource: " + e.getMessage());
}
} else {
System.out.println("Resource " + resourceId + " will continue running.");
System.out.println("You can manage it through the AWS Console or delete it later.");
}
}
private static void displayDataSummary(List<{DetailedData}> detailedData) {
System.out.println("\nData Summary:");
for ({DetailedData} data : detailedData) {
System.out.println(" ⢠" + data.{summaryField}());
}
}
private static void displayDataDetails({DetailedData} data) {
System.out.println("\nDetailed Information:");
System.out.println(" ID: " + data.{idField}());
System.out.println(" Status: " + data.{statusField}());
System.out.println(" Created: " + data.{createdField}());
// Add more fields as specified
}
private static void filterDataByCriteria(List<{DataItem}> dataItems) {
System.out.println("\nFiltering data by criteria...");
// Implement filtering logic as specified in the specification
}
}
// snippet-end:[{service}.java2.{service}_scenario.main]
// Yes/No questions
System.out.print("Use existing resource? (y/n): ");
String useExisting = scanner.nextLine();
boolean shouldUse = useExisting.toLowerCase().startsWith("y");
// Text input
System.out.print("Enter resource name: ");
String resourceName = scanner.nextLine();
// Numeric input
System.out.print("How many items? ");
int count = Integer.parseInt(scanner.nextLine());
// Progress indicators
System.out.println("ā Operation completed successfully");
System.out.println("ā Warning message");
System.out.println("ā Error occurred");
// Formatted output
System.out.println(DASHES);
System.out.println("Found " + items.size() + " items:");
for (Item item : items) {
System.out.println(" ⢠" + item.name());
}
The specification includes an "Errors" section with specific error codes and handling:
// Example error handling based on specification
try {
{Resource} response = {service}Actions.createResource({service}Client);
return response;
} catch ({Service}Exception e) {
String errorCode = e.awsErrorDetails().errorCode();
switch (errorCode) {
case "BadRequestException":
// Handle as specified: "Validate input parameters and notify user"
System.err.println("Invalid configuration. Please check your parameters.");
break;
case "InternalServerErrorException":
// Handle as specified: "Retry operation with exponential backoff"
System.err.println("Service temporarily unavailable. Retrying...");
// Implement retry logic
break;
default:
System.err.println("Unexpected error: " + e.getMessage());
}
throw e;
} catch (SdkException e) {
System.err.println("SDK error: " + e.getMessage());
throw e;
}
scenarios/basics/{service}/SPECIFICATION.mdscenarios/basics/{service}/SPECIFICATION.md thoroughly