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
# 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
| Option | Purpose |
|---|---|
| --recursive | Delete all objects under the prefix |
| --dryrun | Show what would be deleted |
| --exclude / --include | Filter which keys are removed |