aws-s3-rm
Remove objects from Amazon S3 buckets
TLDR
Delete a specific S3 object
Preview the deletion of a specific S3 object without deleting it (dry-run)
Delete an object from a specific S3 access point
Remove all objects from a bucket (empty the bucket)
Display help
SYNOPSIS
aws-s3-rm S3URI [--recursive] [--dryrun] [--force] [--include pattern] [--exclude pattern] [--region region-name] [--profile profile-name]
PARAMETERS
S3URI
The S3 path to the object(s) or prefix (folder) to delete. Format: s3://bucket-name/key-path.
--recursive, -r
Recursively deletes objects under the specified prefix. Essential for deleting entire folders.
--dryrun
Performs a simulated run of the command, displaying what would be deleted without actually making any changes.
--force
Suppresses confirmation prompts for recursive deletions, useful for scripting or automation.
--include pattern
When used with --recursive, specifies a pattern to include files. Only files matching this pattern will be deleted. Can be specified multiple times.
--exclude pattern
When used with --recursive, specifies a pattern to exclude files. Files matching this pattern will not be deleted. Has precedence over --include. Can be specified multiple times.
--region region-name
Specifies the AWS region to send the request to (e.g., us-east-1). Overrides environment variables or configuration files.
--profile profile-name
Specifies the AWS CLI profile to use from your credential file (e.g., default or a custom profile).
DESCRIPTION
The aws-s3-rm command, typically an alias or wrapper for the aws s3 rm subcommand of the AWS Command Line Interface (CLI), provides a straightforward way to remove objects and prefixes (folders) from Amazon S3 buckets. It's a fundamental tool for managing S3 storage directly from your terminal. When used without the --recursive option, it deletes a single specified object. With --recursive, it efficiently removes all objects within a given S3 prefix, effectively deleting a folder and its contents. This command is designed for simple, idempotent deletions, meaning that attempting to delete an object that does not exist will not result in an error. It's crucial to exercise caution as deletions are generally irreversible, especially without bucket versioning enabled. The command handles various scenarios, including specifying file paths and directory structures, and offers options for dry runs and confirmation bypass for automated scripts.
CAVEATS
Irreversibility: Deletions are typically permanent and cannot be undone, especially if bucket versioning is not enabled.
Permissions: The AWS credentials used must have appropriate IAM permissions (s3:DeleteObject and s3:DeleteObjectVersion) for the specified S3 bucket and objects.
Versioning Behavior: If bucket versioning is enabled, aws s3 rm (and thus aws-s3-rm) does not truly delete object versions; instead, it creates a delete marker for the object's current version, effectively hiding previous versions. To permanently delete specific object versions, the aws s3api delete-object --version-id command is required.
Cost Implications: Deletion requests count towards your S3 billing, and associated storage costs for deleted objects cease once they are removed.
PERMISSIONS REQUIRED
To successfully use aws-s3-rm, the IAM user or role configured for your AWS CLI must have the s3:DeleteObject permission for the target S3 bucket and its objects. If you are dealing with versioned buckets, the s3:DeleteObjectVersion permission is also necessary to truly delete specific versions (though aws s3 rm primarily creates delete markers, explicit version deletion requires s3api).
DEALING WITH VERSIONED BUCKETS
When a bucket has versioning enabled, using aws-s3-rm (or aws s3 rm) on an object does not permanently remove its previous versions. Instead, it adds a delete marker as the current version. This marker makes the object appear deleted in typical ls operations, but all prior versions still exist and incur storage costs. To truly delete a specific version, you must use the aws s3api delete-object --version-id command, specifying the exact version ID you wish to remove permanently.
HISTORY
The aws-s3-rm command, while not a standalone binary in core Linux distributions, is a common alias or shell script wrapper around the aws s3 rm subcommand of the AWS Command Line Interface (CLI). The AWS CLI itself was first released in 2013, providing a unified tool to manage AWS services from the command line. The s3 family of commands, including rm, was among the earliest and most frequently used functionalities, reflecting the foundational role of Amazon S3 for cloud storage. Its development has focused on simplifying common S3 operations, offering powerful options like recursive deletion and filtering, making it an indispensable tool for developers and administrators managing cloud resources.