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

Function cleanupS3Resources

cmd/lambda-nat-proxy/cmd_destroy.go:177–200  ·  view source on GitHub ↗
(ctx context.Context, clients *awsclients.Clients, cfg *config.CLIConfig, bucketName string)

Source from the content-addressed store, hash-verified

175}
176
177func cleanupS3Resources(ctx context.Context, clients *awsclients.Clients, cfg *config.CLIConfig, bucketName string) error {
178 log.Printf("Cleaning up S3 bucket: %s", bucketName)
179
180 // Remove S3 triggers first
181 triggerDeployer := deploy.NewTriggerDeployer(clients, cfg)
182 functionName := fmt.Sprintf("%s-lambda", cfg.Deployment.StackName)
183 functionArn := fmt.Sprintf("arn:aws:lambda:%s:%s:function:%s",
184 cfg.AWS.Region,
185 clients.AccountID,
186 functionName)
187
188 if err := triggerDeployer.RemoveS3Triggers(ctx, bucketName, functionArn); err != nil {
189 log.Printf("Warning: Failed to remove S3 triggers: %v", err)
190 }
191
192 // Empty the bucket
193 log.Printf("Emptying S3 bucket...")
194 if err := emptyS3Bucket(ctx, clients.S3, bucketName); err != nil {
195 return fmt.Errorf("failed to empty S3 bucket: %w", err)
196 }
197
198 log.Printf("✅ S3 bucket emptied")
199 return nil
200}
201
202func emptyS3Bucket(ctx context.Context, s3Client awsclients.S3API, bucketName string) error {
203 // List all objects

Callers 1

runDestroyFunction · 0.85

Calls 3

RemoveS3TriggersMethod · 0.95
NewTriggerDeployerFunction · 0.92
emptyS3BucketFunction · 0.85

Tested by

no test coverage detected