(ctx context.Context, clients *awsclients.Clients, cfg *config.CLIConfig, bucketName string)
| 175 | } |
| 176 | |
| 177 | func 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 | |
| 202 | func emptyS3Bucket(ctx context.Context, s3Client awsclients.S3API, bucketName string) error { |
| 203 | // List all objects |
no test coverage detected