Skip to content
Latchkey

aws s3 rm: Delete Objects & Common CI Errors

Delete objects from S3 - one key, or a whole prefix.

aws s3 rm removes objects from a bucket. With --recursive it deletes everything under a prefix, which makes it powerful for cleanup and dangerous if pointed at the wrong path.

What it does

aws s3 rm s3://bucket/key deletes a single object; with --recursive it deletes every object under the given prefix. --exclude/--include filter which keys are removed, and --dryrun shows exactly what would be deleted without removing anything - the safety check you should run first.

Common usage

Terminal
# Delete one object
aws s3 rm s3://my-bucket/old/build.zip

# Preview a recursive delete (deletes nothing)
aws s3 rm s3://my-bucket/tmp/ --recursive --dryrun

# Delete a prefix, keeping one pattern
aws s3 rm s3://my-bucket/tmp/ --recursive --exclude "*.keep"

Common error in CI: deletes too much / versioned objects linger

A mistyped prefix with --recursive can wipe a whole bucket, and on a versioned bucket s3 rm only adds delete markers - the data is still there (and still billed). Fix: always run with --dryrun first and scope to a specific prefix; never run aws s3 rm s3://bucket --recursive without one. On versioned buckets, removing old versions needs aws s3api delete-objects with version IDs or a lifecycle rule - plain rm does not purge versions. Deletes require s3:DeleteObject.

Key options

OptionPurpose
--recursiveDelete all objects under the prefix
--dryrunShow what would be deleted
--exclude / --includeFilter which keys are removed

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →