Table Of Contents

Feedback

User Guide

First time using the AWS CLI? See the User Guide for help getting started.

Note: You are viewing the documentation for an older major version of the AWS CLI (version 1).

AWS CLI version 2, the latest major version of AWS CLI, is now stable and recommended for general use. To view this page for the AWS CLI version 2, click here. For more information see the AWS CLI version 2 installation instructions and migration guide.

[ aws . s3api ]

delete-object

Description

Removes the null version (if there is one) of an object and inserts a delete marker, which becomes the latest version of the object. If there isn't a null version, Amazon S3 does not remove any objects.

To remove a specific version, you must be the bucket owner and you must use the version Id subresource. Using this subresource permanently deletes the version. If the object deleted is a delete marker, Amazon S3 sets the response header, x-amz-delete-marker , to true.

If the object you want to delete is in a bucket where the bucket versioning configuration is MFA Delete enabled, you must include the x-amz-mfa request header in the DELETE versionId request. Requests that include x-amz-mfa must use HTTPS.

For more information about MFA Delete, see Using MFA Delete . To see sample requests that use versioning, see Sample Request .

You can delete objects by explicitly calling the DELETE Object API or configure its lifecycle ( PutBucketLifecycle ) to enable Amazon S3 to remove them for you. If you want to block users or accounts from removing or deleting objects from your bucket, you must deny them the s3:DeleteObject , s3:DeleteObjectVersion , and s3:PutLifeCycleConfiguration actions.

The following operation is related to DeleteObject :

  • PutObject

See also: AWS API Documentation

See 'aws help' for descriptions of global parameters.

Synopsis

  delete-object
--bucket <value>
--key <value>
[--mfa <value>]
[--version-id <value>]
[--request-payer <value>]
[--bypass-governance-retention | --no-bypass-governance-retention]
[--cli-input-json <value>]
[--generate-cli-skeleton <value>]

Options

--bucket (string)

The bucket name of the bucket containing the object.

When using this API with an access point, you must direct requests to the access point hostname. The access point hostname takes the form AccessPointName -AccountId .s3-accesspoint.*Region* .amazonaws.com. When using this operation using an access point through the AWS SDKs, you provide the access point ARN in place of the bucket name. For more information about access point ARNs, see Using Access Points in the Amazon Simple Storage Service Developer Guide .

--key (string)

Key name of the object to delete.

--mfa (string)

The concatenation of the authentication device's serial number, a space, and the value that is displayed on your authentication device. Required to permanently delete a versioned object if versioning is configured with MFA delete enabled.

--version-id (string)

VersionId used to reference a specific version of the object.

--request-payer (string)

Confirms that the requester knows that they will be charged for the request. Bucket owners need not specify this parameter in their requests. For information about downloading objects from requester pays buckets, see Downloading Objects in Requestor Pays Buckets in the Amazon S3 Developer Guide .

Possible values:

  • requester

--bypass-governance-retention | --no-bypass-governance-retention (boolean)

Indicates whether S3 Object Lock should bypass Governance-mode restrictions to process this operation.

--cli-input-json (string) Performs service operation based on the JSON string provided. The JSON string follows the format provided by --generate-cli-skeleton. If other arguments are provided on the command line, the CLI values will override the JSON-provided values. It is not possible to pass arbitrary binary values using a JSON-provided value as the string will be taken literally.

--generate-cli-skeleton (string) Prints a JSON skeleton to standard output without sending an API request. If provided with no value or the value input, prints a sample input JSON that can be used as an argument for --cli-input-json. If provided with the value output, it validates the command inputs and returns a sample output JSON for that command.

See 'aws help' for descriptions of global parameters.

Examples

The following command deletes an object named test.txt from a bucket named my-bucket:

aws s3api delete-object --bucket my-bucket --key test.txt

If bucket versioning is enabled, the output will contain the version ID of the delete marker:

{
  "VersionId": "9_gKg5vG56F.TTEUdwkxGpJ3tNDlWlGq",
  "DeleteMarker": true
}

For more information about deleting objects, see Deleting Objects in the Amazon S3 Developer Guide.

Output

DeleteMarker -> (boolean)

Specifies whether the versioned object that was permanently deleted was (true) or was not (false) a delete marker.

VersionId -> (string)

Returns the version ID of the delete marker created as a result of the DELETE operation.

RequestCharged -> (string)

If present, indicates that the requester was successfully charged for the request.