MCPcopy Create free account
hub / github.com/dan-v/lambda-nat-proxy / autoDetectS3Bucket

Function autoDetectS3Bucket

cmd/lambda-nat-proxy/cmd_run.go:245–274  ·  view source on GitHub ↗

autoDetectS3Bucket attempts to detect the S3 bucket from CloudFormation stack

(cfg *config.CLIConfig)

Source from the content-addressed store, hash-verified

243
244// autoDetectS3Bucket attempts to detect the S3 bucket from CloudFormation stack
245func 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
276func init() {
277 // Add run-specific flags

Callers 1

runProxyFunction · 0.85

Calls 3

GetClientsMethod · 0.95
GetStackOutputsMethod · 0.95
NewStackDeployerFunction · 0.92

Tested by

no test coverage detected