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 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 (s3api)

Removing an Object from a Bucket

Before you begin: Install and configure AWS CLI and set up your profile. For more information, see Installing and Configuring AWS CLI.

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

Request sample
$ aws s3api delete-object \
    --profile YOUR_PROFILE \
    --debug \
    --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 from which you want to remove an object.

  • (optional) debug: When included, returns the detailed log of the operation. This is useful to analyze and troubleshoot issues you may be encountering.

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

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

    If the version-id starts with a 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, the delete-object command 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", "VersionId": "B1WsEK0saANNAKcOAJj0aIA00RozTpzr"}], "Quiet": false}' \
    --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.

        You can specify up to 1000 keys.

      • (optional) VersionId: If the bucket versioning was enabled, even if it is now disabled, the version IDs of the objects you want to remove.

      • (optional) quiet: If true, returns only the keys of objects that could not be deleted.

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

If you have never enabled versioning in this bucket, the delete-objects command returns the following element:

  • Key: The names of the objects you removed.

Result Sample
{
    "Deleted": [
        {
            "Key": "OBJECT_1"
        },
        {
            "Key": "OBJECT_2"
        }
    ]
}

If you enabled bucket versioning at least once, even if you disabled it later, the delete-objects command returns the following elements:

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

    • Key: The names of the objects you removed.

    • DeleteMarker: If you removed objects without specifying their version ID, the creation of delete markers (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.

    • DeleteMarkerVersionId: If the bucket versioning is enabled, the version IDs of the delete markers.

    • VersionID: If you specified the version IDs of objects, the version IDs of the objects you removed.

Result Sample
{
    "Deleted": [
        {
            "Key": "OBJECT_1",
            "DeleteMarker": true,
            "DeleteMarkerVersionId": "yCYmn.BwXmCViMvaCBrUz-eGUKwJK4r"
        },
        {
            "Key": "OBJECT_2",
            "VersionId": "B1WsEK0saANNAKcOAJj0aIA00RozTpzr"
        }
    ]
}

Removing Objects from a Bucket Using AWS CLI (s3)

Before you begin: Install and configure AWS CLI and set up your profile. For more information, see Installing and Configuring AWS CLI.

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

Request Sample
$ aws s3 rm s3://YOUR_BUCKET/YOUR_OBJECT \
    --profile YOUR_PROFILE \
    --dryrun \
    --endpoint https://oos.eu-west-2.outscale.com

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

  • s3://YOUR_BUCKET/YOUR_OBJECT: The path to the object you want to remove from the bucket.

    You can specify the version ID of an object following this syntax: s3://YOUR_BUCKET/YOUR_OBJECT?versionID=<YOUR_VERSION_ID>.

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

  • (optional) dryrun: Provides an overview of the operations performed by the command without actually running it. This is used as a safety measure to review the impact of a command before executing it.

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

Removing Objects from a Bucket Using s3cmd

Before you begin: Install and configure AWS CLI and set up your profile. For more information, see Installing and Configuring AWS CLI.

You can 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.