How do I delete a versioned bucket in AWS S3 using the CLI?

前端 未结 20 928
我在风中等你
我在风中等你 2020-12-07 16:34

I have tried both s3cmd:

$ s3cmd -r -f -v del s3://my-versioned-bucket/

And the AWS CLI:

$ aws s3 rm s3://my-v         


        
20条回答
  •  攒了一身酷
    2020-12-07 16:45

    You can delete all the objects in the versioned s3 bucket. But I don't know how to delete specific objects.

    $ aws s3api delete-objects \
          --bucket  \
          --delete "$(aws s3api list-object-versions \
          --bucket  | \
          jq '{Objects: [.Versions[] | {Key:.Key, VersionId : .VersionId}], Quiet: false}')"
    

    Alternatively without jq:

    $ aws s3api delete-objects \
        --bucket ${bucket_name} \
        --delete "$(aws s3api list-object-versions \
        --bucket "${bucket_name}" \
        --output=json \
        --query='{Objects: Versions[].{Key:Key,VersionId:VersionId}}')"
    

提交回复
热议问题