|
| 1 | +# Go Hello Examples Generation |
| 2 | + |
| 3 | +## MANDATORY: Knowledge Base Consultation (FIRST STEP) |
| 4 | +**🚨 CRITICAL - Must be completed BEFORE any code generation** |
| 5 | + |
| 6 | +```bash |
| 7 | +# Step 1: List available knowledge bases |
| 8 | +ListKnowledgeBases() |
| 9 | + |
| 10 | +# Step 2: Query coding standards (REQUIRED) |
| 11 | +QueryKnowledgeBases("coding-standards-KB", "Go-code-example-standards") |
| 12 | + |
| 13 | +# Step 3: Query implementation patterns (REQUIRED) |
| 14 | +QueryKnowledgeBases("Go-premium-KB", "Go implementation patterns") |
| 15 | + |
| 16 | +# Step 4: AWS service research (REQUIRED) |
| 17 | +search_documentation("What is [AWS Service] and what are its key API operations?") |
| 18 | +read_documentation("https://docs.aws.amazon.com/[service]/latest/[relevant-page]") |
| 19 | +``` |
| 20 | + |
| 21 | +**FAILURE TO COMPLETE KNOWLEDGE BASE CONSULTATION WILL RESULT IN INCORRECT CODE STRUCTURE** |
| 22 | + |
| 23 | +## Purpose |
| 24 | +Generate simple "Hello" examples that demonstrate basic service connectivity and the most fundamental operation using direct AWS SDK for Go v2 client calls. |
| 25 | + |
| 26 | +## Requirements |
| 27 | +- **MANDATORY**: Every AWS service MUST include a "Hello" scenario |
| 28 | +- **Simplicity**: Should be the most basic, minimal example possible |
| 29 | +- **Standalone**: Must work independently of other examples |
| 30 | +- **Direct Client**: Use AWS SDK for Go v2 client directly, no wrapper structs needed |
| 31 | +- **Context**: ALWAYS use context.Context for AWS operations |
| 32 | + |
| 33 | +## File Structure |
| 34 | +``` |
| 35 | +gov2/{service}/hello/ |
| 36 | +├── hello.go # MANDATORY: Hello example file |
| 37 | +``` |
| 38 | + |
| 39 | +## Hello Example Pattern |
| 40 | +```go |
| 41 | +// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 42 | +// SPDX-License-Identifier: Apache-2.0 |
| 43 | + |
| 44 | +// Package main demonstrates basic {AWS Service} connectivity. |
| 45 | +package main |
| 46 | + |
| 47 | +import ( |
| 48 | + "context" |
| 49 | + "errors" |
| 50 | + "fmt" |
| 51 | + "log" |
| 52 | + |
| 53 | + "github.com/aws/aws-sdk-go-v2/config" |
| 54 | + "github.com/aws/aws-sdk-go-v2/service/{service}" |
| 55 | + "github.com/aws/smithy-go" |
| 56 | +) |
| 57 | + |
| 58 | +// main demonstrates basic {AWS Service} connectivity by {basic operation description}. |
| 59 | +func main() { |
| 60 | + ctx := context.Background() |
| 61 | + |
| 62 | + // Load AWS configuration |
| 63 | + sdkConfig, err := config.LoadDefaultConfig(ctx) |
| 64 | + if err != nil { |
| 65 | + log.Fatalf("Couldn't load default configuration: %v", err) |
| 66 | + } |
| 67 | + |
| 68 | + // Create service client |
| 69 | + {service}Client := {service}.NewFromConfig(sdkConfig) |
| 70 | + |
| 71 | + // Perform the most basic operation for this service |
| 72 | + result, err := {service}Client.{BasicOperation}(ctx, &{service}.{BasicOperationInput}{ |
| 73 | + // Add minimal required parameters if any |
| 74 | + }) |
| 75 | + if err != nil { |
| 76 | + var ae smithy.APIError |
| 77 | + if errors.As(err, &ae) { |
| 78 | + switch ae.ErrorCode() { |
| 79 | + case "UnauthorizedOperation", "AccessDenied": |
| 80 | + fmt.Println("You don't have permission to access {AWS Service}.") |
| 81 | + default: |
| 82 | + fmt.Printf("Couldn't access {AWS Service}. Error: %v\n", err) |
| 83 | + } |
| 84 | + } else { |
| 85 | + fmt.Printf("Couldn't access {AWS Service}. Error: %v\n", err) |
| 86 | + } |
| 87 | + return |
| 88 | + } |
| 89 | + |
| 90 | + fmt.Println("Hello, {AWS Service}!") |
| 91 | + // Display appropriate result information based on service type |
| 92 | + |
| 93 | +} |
| 94 | +``` |
| 95 | + |
| 96 | +## Hello Examples by Service Type |
| 97 | + |
| 98 | +### List-Based Services (S3, DynamoDB, etc.) |
| 99 | +- **Operation**: List primary resources (buckets, tables, etc.) |
| 100 | +- **Message**: Show count and names of resources |
| 101 | +- **Example**: |
| 102 | +```go |
| 103 | +result, err := s3Client.ListBuckets(ctx, &s3.ListBucketsInput{}) |
| 104 | +if err != nil { |
| 105 | + // Handle error |
| 106 | +} |
| 107 | + |
| 108 | +fmt.Printf("Found %d bucket(s):\n", len(result.Buckets)) |
| 109 | +for _, bucket := range result.Buckets { |
| 110 | + fmt.Printf(" %s\n", *bucket.Name) |
| 111 | +} |
| 112 | +``` |
| 113 | + |
| 114 | +### Status-Based Services (GuardDuty, Config, etc.) |
| 115 | +- **Operation**: Check service status or list detectors/configurations |
| 116 | +- **Message**: Show service availability and basic status |
| 117 | +- **Example**: |
| 118 | +```go |
| 119 | +result, err := guarddutyClient.ListDetectors(ctx, &guardduty.ListDetectorsInput{}) |
| 120 | +if err != nil { |
| 121 | + // Handle error |
| 122 | +} |
| 123 | + |
| 124 | +fmt.Printf("Found %d detector(s)\n", len(result.DetectorIds)) |
| 125 | +``` |
| 126 | + |
| 127 | +### Compute Services (EC2, Lambda, etc.) |
| 128 | +- **Operation**: List instances/functions or describe regions |
| 129 | +- **Message**: Show available resources or regions |
| 130 | +- **Example**: |
| 131 | +```go |
| 132 | +result, err := ec2Client.DescribeRegions(ctx, &ec2.DescribeRegionsInput{}) |
| 133 | +if err != nil { |
| 134 | + // Handle error |
| 135 | +} |
| 136 | + |
| 137 | +fmt.Printf("Found %d region(s):\n", len(result.Regions)) |
| 138 | +for _, region := range result.Regions { |
| 139 | + fmt.Printf(" %s\n", *region.RegionName) |
| 140 | +} |
| 141 | +``` |
| 142 | + |
| 143 | +## Error Handling Patterns |
| 144 | +```go |
| 145 | +// Standard error handling for hello examples |
| 146 | +if err != nil { |
| 147 | + var ae smithy.APIError |
| 148 | + if errors.As(err, &ae) { |
| 149 | + switch ae.ErrorCode() { |
| 150 | + case "UnauthorizedOperation", "AccessDenied": |
| 151 | + fmt.Println("You don't have permission to access {AWS Service}.") |
| 152 | + case "InvalidUserID.NotFound": |
| 153 | + fmt.Println("User credentials not found or invalid.") |
| 154 | + default: |
| 155 | + fmt.Printf("Couldn't access {AWS Service}. Error: %v\n", err) |
| 156 | + } |
| 157 | + } else { |
| 158 | + fmt.Printf("Couldn't access {AWS Service}. Error: %v\n", err) |
| 159 | + } |
| 160 | + return |
| 161 | +} |
| 162 | +``` |
| 163 | + |
| 164 | +## Context Usage |
| 165 | +```go |
| 166 | +// Always use context for AWS operations |
| 167 | +ctx := context.Background() |
| 168 | + |
| 169 | +// For operations with timeout (if needed) |
| 170 | +ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) |
| 171 | +defer cancel() |
| 172 | + |
| 173 | +result, err := client.Operation(ctx, &service.OperationInput{ |
| 174 | + // Parameters |
| 175 | +}) |
| 176 | +``` |
| 177 | + |
| 178 | +## Validation Requirements |
| 179 | +- ✅ **Must run without errors** (with proper credentials) |
| 180 | +- ✅ **Must handle credential issues gracefully** |
| 181 | +- ✅ **Must display meaningful output** |
| 182 | +- ✅ **Must use direct AWS SDK for Go v2 client calls** |
| 183 | +- ✅ **Must include proper package and function documentation** |
| 184 | +- ✅ **Must use context.Context for all AWS operations** |
| 185 | +- ✅ **Must follow Go naming conventions** |
| 186 | + |
| 187 | +## Common Patterns |
| 188 | +- Always use `{service}.NewFromConfig(sdkConfig)` to create clients |
| 189 | +- Include comprehensive error handling with smithy.APIError checking |
| 190 | +- Provide user-friendly output messages using fmt.Printf |
| 191 | +- Handle both service-specific and general exceptions |
| 192 | +- Keep it as simple as possible - no additional structs or complexity |
| 193 | +- Use context.Background() for basic operations |
| 194 | +- Follow Go naming conventions (camelCase for unexported, PascalCase for exported) |
| 195 | + |
| 196 | +## File Naming and Structure |
| 197 | +- **File location**: `gov2/{service}/hello/hello.go` |
| 198 | +- **Package**: `package main` |
| 199 | +- **Function structure**: `main()` function as entry point |
| 200 | +- **Documentation**: Include package-level and function-level comments |
| 201 | +- **Imports**: Only import necessary packages, group standard library, AWS SDK, and third-party imports |
0 commit comments