autoDetectS3Bucket attempts to detect the S3 bucket from CloudFormation stack
(cfg *config.CLIConfig)
| 243 | |
| 244 | // autoDetectS3Bucket attempts to detect the S3 bucket from CloudFormation stack |
| 245 | func autoDetectS3Bucket(cfg *config.CLIConfig) (string, error) { |
| 246 | // Create AWS clients |
| 247 | clientFactory, err := awsclients.NewClientFactory(cfg) |
| 248 | if err != nil { |
| 249 | return "", fmt.Errorf("failed to create AWS clients: %w", err) |
| 250 | } |
| 251 | |
| 252 | // Try to get stack outputs |
| 253 | clients := clientFactory.GetClients() |
| 254 | stackDeployer := deploy.NewStackDeployer(clients, cfg) |
| 255 | |
| 256 | stackOutput, err := stackDeployer.GetStackOutputs(context.Background()) |
| 257 | if err != nil { |
| 258 | // Provide more helpful error message with multiple options |
| 259 | return "", fmt.Errorf("CloudFormation stack '%s' not found in region %s.\n\n"+ |
| 260 | "📦 To deploy infrastructure:\n"+ |
| 261 | " lambda-nat-proxy deploy\n\n"+ |
| 262 | "🔍 To check existing deployments:\n"+ |
| 263 | " lambda-nat-proxy status\n\n"+ |
| 264 | "⚙️ To use a different stack name:\n"+ |
| 265 | " lambda-nat-proxy run --stack-name your-stack-name", |
| 266 | cfg.Deployment.StackName, cfg.AWS.Region) |
| 267 | } |
| 268 | |
| 269 | if stackOutput.CoordinationBucketName == "" { |
| 270 | return "", fmt.Errorf("S3 bucket not found in CloudFormation stack outputs") |
| 271 | } |
| 272 | |
| 273 | return stackOutput.CoordinationBucketName, nil |
| 274 | } |
| 275 | |
| 276 | func init() { |
| 277 | // Add run-specific flags |
no test coverage detected