aws-sdk-go-v2 icon indicating copy to clipboard operation
aws-sdk-go-v2 copied to clipboard

s3manager.BatchDelete missing from SDK V2

Open 0x2b3bfa0 opened this issue 4 years ago • 2 comments

Description

Handy abstractions like service/s3/s3manager.BatchDelete seem to have disappeared in the second version of the SDK. Unless I missed some obvious fact, emptying an AWS S3 bucket requires much more code with V2 than with V1 iterators, to the point of requiring developers to build by hands a ObjectIdentifier slice.

SDK version

1.9.2

Go version

go version go1.17.1 darwin/amd64

Observed behavior

paginator := s3.NewListObjectsV2Paginator(client, &s3.ListObjectsV2Input{
    Bucket: aws.String(bucket),
})

for paginator.HasMorePages() {
    page, err := paginator.NextPage(ctx)
    if err != nil {
        return err
    }
    
    var objects []types.ObjectIdentifier
    for _, object := range page.Contents {
        objects = append(objects, types.ObjectIdentifier{
            Key: object.Key,
        })
    }

    _, err = client.DeleteObjects(ctx, &s3.DeleteObjectsInput{
        Bucket: aws.String(bucket),
        Delete: &types.Delete{
            Objects: objects,
        },
    })
    if err != nil {
        return err
    }
}

Expected behavior

 iterator := s3manager.NewDeleteListIterator(client, &s3.ListObjectsInput{
     Bucket: aws.String(bucket),
 })

 if err := s3manager.NewBatchDeleteWithClient(client).Delete(ctx, iterator); err != nil {
     return err
 }

0x2b3bfa0 avatar Oct 19 '21 23:10 0x2b3bfa0

Hi @0x2b3bfa0 , Yea this is not included in the V2 of the SDK, they were removed basically because we were not really happy with them and did not want them to carry over into V2, but we are planning on eventually having them added back in some way, it's just been low priority on our backlog. For now though, yea the way to do it is to iterate "manually"

KaibaLopez avatar Oct 20 '21 22:10 KaibaLopez

This is an important feature to me.. I hope AWS SDK team can add it back sooner.

ChihweiLHBird avatar Nov 21 '23 04:11 ChihweiLHBird