(ctx context.Context, event json.RawMessage)
| 47 | } |
| 48 | |
| 49 | func handleRequest(ctx context.Context, event json.RawMessage) error { |
| 50 | // Parse the input event |
| 51 | var order Order |
| 52 | if err := json.Unmarshal(event, &order); err != nil { |
| 53 | log.Printf("Failed to unmarshal event: %v", err) |
| 54 | return err |
| 55 | } |
| 56 | |
| 57 | // Access environment variables |
| 58 | bucketName := os.Getenv("RECEIPT_BUCKET") |
| 59 | if bucketName == "" { |
| 60 | log.Printf("RECEIPT_BUCKET environment variable is not set") |
| 61 | return fmt.Errorf("missing required environment variable RECEIPT_BUCKET") |
| 62 | } |
| 63 | |
| 64 | // Create the receipt content and key destination |
| 65 | receiptContent := fmt.Sprintf("OrderID: %s\nAmount: $%.2f\nItem: %s", |
| 66 | order.OrderID, order.Amount, order.Item) |
| 67 | key := "receipts/" + order.OrderID + ".txt" |
| 68 | |
| 69 | // Upload the receipt to S3 using the helper method |
| 70 | if err := uploadReceiptToS3(ctx, bucketName, key, receiptContent); err != nil { |
| 71 | return err |
| 72 | } |
| 73 | |
| 74 | log.Printf("Successfully processed order %s and stored receipt in S3 bucket %s", order.OrderID, bucketName) |
| 75 | return nil |
| 76 | } |
| 77 | |
| 78 | func main() { |
| 79 | lambda.Start(handleRequest) |
nothing calls this directly
no test coverage detected