(ctx context.Context, s3Client awsclients.S3API, bucketName string)
| 200 | } |
| 201 | |
| 202 | func emptyS3Bucket(ctx context.Context, s3Client awsclients.S3API, bucketName string) error { |
| 203 | // List all objects |
| 204 | input := &s3.ListObjectsV2Input{ |
| 205 | Bucket: aws.String(bucketName), |
| 206 | } |
| 207 | |
| 208 | for { |
| 209 | result, err := s3Client.ListObjectsV2WithContext(ctx, input) |
| 210 | if err != nil { |
| 211 | return fmt.Errorf("failed to list objects: %w", err) |
| 212 | } |
| 213 | |
| 214 | if len(result.Contents) == 0 { |
| 215 | break |
| 216 | } |
| 217 | |
| 218 | // Delete objects in batch |
| 219 | var objects []*s3.ObjectIdentifier |
| 220 | for _, obj := range result.Contents { |
| 221 | objects = append(objects, &s3.ObjectIdentifier{ |
| 222 | Key: obj.Key, |
| 223 | }) |
| 224 | } |
| 225 | |
| 226 | deleteInput := &s3.DeleteObjectsInput{ |
| 227 | Bucket: aws.String(bucketName), |
| 228 | Delete: &s3.Delete{ |
| 229 | Objects: objects, |
| 230 | }, |
| 231 | } |
| 232 | |
| 233 | _, err = s3Client.DeleteObjectsWithContext(ctx, deleteInput) |
| 234 | if err != nil { |
| 235 | return fmt.Errorf("failed to delete objects: %w", err) |
| 236 | } |
| 237 | |
| 238 | log.Printf("Deleted %d objects from bucket", len(objects)) |
| 239 | |
| 240 | // Check if there are more objects |
| 241 | if !*result.IsTruncated { |
| 242 | break |
| 243 | } |
| 244 | input.ContinuationToken = result.NextContinuationToken |
| 245 | } |
| 246 | |
| 247 | return nil |
| 248 | } |
| 249 | |
| 250 | func deleteCloudWatchLogs(ctx context.Context, clients *awsclients.Clients, functionName string) error { |
| 251 | logGroupName := fmt.Sprintf("/aws/lambda/%s", functionName) |
no test coverage detected