The aws s3 rm command is a part of the AWS Command Line Interface (CLI) and is used to delete S3 objects stored in Amazon S3. Amazon S3 (Simple Storage Service) is an object storage service provided by Amazon Web Services that allows you to store and retrieve large amounts of data.
Here’s an overview of the aws s3 rm command and its functionality:
- Deleting S3 Objects: The primary purpose of the aws s3 rm command is to delete S3 objects. You specify the S3 bucket name and the object key as arguments, and AWS will remove the specified object from the S3 bucket.
- Batch Deletion: The aws s3 rm command supports batch deletion, allowing you to specify multiple objects to be deleted in a single command. You can provide multiple object keys or use wildcards (*) to delete multiple objects that match a certain pattern.
- Recursive Deletion: The aws s3 rm command provides an option (–recursive or -r) to perform a recursive deletion. This is useful when you want to delete all objects within a bucket or a specific prefix, including objects within subfolders.
- Confirming Deletion: By default, the aws s3 rm command prompts for confirmation before deleting each individual object. You can use the –no-prompt option to bypass the confirmation prompt and automate the deletion process.
- Versioned Objects: If versioning is enabled for an S3 bucket, the aws s3 rm command deletes the latest version of the object by default. You can use the –version-id option to specify a specific version of the object to delete.
- Access Control: The aws s3 rm command requires appropriate permissions to delete objects from an S3 bucket. The IAM user or role used to execute the command must have the necessary S3 permissions to delete the specified objects.
The aws s3 rm command provides a convenient and efficient way to delete S3 objects directly from the command line. It allows you to automate object deletion, remove unnecessary or outdated files, and manage the content of your S3 buckets.
aws s3 rm Command Examples
1. Delete a specific S3 object:
# aws s3 rm s3://bucket_name/path/to/file
2. Preview the deletion of a specific S3 object without deleting it (dry-run):
# aws s3 rm s3://bucket_name/path/to/file --dryrun
3. Delete an object from a specific S3 access point:
# aws s3 rm s3://arn:aws:s3:region:account_id:access_point/access_point_name/object_key
4. Display help:
# aws s3 rm help