deleteObject

April 2024 · 4 minute read

Removes an object from a bucket. The behavior depends on the bucket's versioning state:

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 in the Amazon S3 User Guide. To see sample requests that use versioning, see Sample Request.

Directory buckets - MFA delete is not supported by directory buckets.

You can delete objects by explicitly calling DELETE Object or calling (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.

Directory buckets - S3 Lifecycle is not supported by directory buckets.

Permissions

HTTP Host header syntax

**Directory buckets ** - The HTTP Host header syntax is <i>Bucket_name</i>.s3express-<i>az_id</i>.<i>region</i>.amazonaws.com.

The following action is related to DeleteObject:

Samples

 fun main() { //sampleStart // The following example deletes an object from an S3 bucket. val resp = s3Client.deleteObject { bucket = "examplebucket" key = "objectkey.jpg" } //sampleEnd }
 fun main() { //sampleStart // The following example deletes an object from a non versioned bucket. s3Client.deleteObject { bucket = "ExampleBucket" key = "HappyFace.jpg" } //sampleEnd }

ncG1vNJzZmirlKB7ornAs6anmaeoe6S7zGiiqKycnrtwrc%2BiZqWZpJrAtXvSbGaar6NjwKW3jaSmraSZo3u0sdGvoJydo2PAdHuMrGpmm5yesq%2FAjp2cpZ2kmnqwrsmemq1mmKm6rQ%3D%3D