Removing Objects from a Bucket

You can remove one or more objects you uploaded or copied into a bucket.

You cannot remove an object if you do not have the write or full-control permission for the bucket that contains the object. For more information, see Access Control List (ACL) Reference.

If you enabled the versioning on your bucket, you need to specify the version-id of the version you want to remove. To completely remove an object, you need to remove all its versions from the bucket. For more information, see Listing the Versions of an Object.

Removing Objects from a Bucket Using AWS CLI

Removing an Object from a Bucket

To remove an object from a bucket, use the delete-object command following this syntax:

Request sample
$ aws s3api delete-object \
    --profile YOUR_PROFILE \
    --bucket BUCKET \
    --key OBJECT \
    --version-id A0VsEK0saANNAKcOAJj0aIA00RozToyq \
    --endpoint https://oos.eu-west-2.outscale.com

This command contains the following attributes that you need to specify:

  • (optional) profile: The named profile you want to use, created when configuring AWS CLI. For more information, see Installing and Configuring AWS CLI.

  • bucket: The name of the bucket.

  • key: The name of the object in the bucket.

  • (optional) version-id: If the bucket versioning was enabled, even if it is now disabled, the ID of the version of the object you want to remove.

    If the version-id starts with an hyphen ("-"), you need to specify the attribute following this syntax:

    --version-id=-A0VsEK0saANNAKcOAJj0aIA00RozToyq
  • endpoint: The endpoint corresponding to the Region you want to send the request to.

If you have never enabled versioning in this bucket, this action does not return any element.

If you have ever enabled versioning in this bucket, even if you disabled it later, the delete-object command returns the following elements:

  • VersionId: The version ID of the object you removed.

  • DeleteMarker: If you removed an object without specifying its version ID, the creation of a delete marker (always true).

    A delete marker replaces the object and has no associated data. If several versions of a same object have been created using versioning, you need to delete each specific version one by one using their IDs to completely delete the object.

    Result Sample
    {
        "VersionId": "IlkGwkYgCoITL6SNC5lpj2um8vNnDqD",
        "DeleteMarker": true
    }

Removing Several Objects from a Bucket

To remove several objects from a bucket, use the delete-objects command following this syntax:

Request sample
$ aws s3api delete-objects \
    --profile YOUR_PROFILE \
    --bucket BUCKET \
    --delete Objects=[{Key=OBJECT_1},{Key=OBJECT_2}] \
    --endpoint https://oos.eu-west-2.outscale.com

This command contains the following attributes that you need to specify:

  • (optional) profile: The named profile you want to use, created when configuring AWS CLI. For more information, see Installing and Configuring AWS CLI.

  • bucket: The name of the bucket from which you want to remove objects.

  • delete: Information about the objects you want to remove. This element contains the following attributes you need to specify:

    • Objects: The list of objects you want to remove.

      • Key: The names of the objects in the bucket.

  • endpoint: The endpoint corresponding to the Region you want to send the request to.

The delete-objects command returns the following elements:

  • Deleted: Information about one or more objects you removed. This element contains the following information:

    • DeleteMarkerVersionId: If the bucket versioning is enabled, the version ID of the delete marker.

    • Key: The name of the object you removed.

    • DeleteMarker: If you removed an object without specifying its version ID, the creation of a delete marker (always true).

Result Sample
{
    "Deleted": [
        {
            "DeleteMarkerVersionId": "yCYmn.BwXmCViMvaCBrUz-eGUKwJK4r",
            "Key": "OBJECT_1",
            "DeleteMarker": true
        },
        {
            "DeleteMarkerVersionId": "notageX0XA9YT1JJ.APH3ThQROTDftQ",
            "Key": "OBJECT_2",
            "DeleteMarker": true
        }
    ]
}
  • You can also perform this action using an s3 command following this syntax:

    $ aws s3 rm --profile YOUR_PROFILE s3://YOUR_BUCKET/YOUR_OBJECT --endpoint https://oos.eu-west-2.outscale.com
  • You can also manage your object storage resources using s3cmd commands. For more information, see s3cmd.

Related Pages

AWS™ and Amazon Web Services™ are trademarks of Amazon Technologies, Inc or its affiliates in the United States and/or other countries.