Articles on: Object storage

AWS CLI: advanced bucket management

Prerequisites


AWS CLI configuration :

aws configure

AWS Access Key ID [****************ofuW] : your_access_key
AWS Secret Access Key [****************25qt] : your_secret_key
Default region name [france]: france
Default output format [None]: leave this field empty


List buckets :

aws s3 ls --endpoint-url https://(leviia endpoint)


List objects in a bucket :

aws s3api list-objects --bucket bucket_name --endpoint-url https:// your_endpoint


List all versions in a bucket :

aws s3api list-object-versions --bucket bucket_name --endpoint-url https:// your_endpoint


List object versions :

aws s3api list-object-versions --bucket bucket_name --prefix file_name --endpoint-url https:// your_endpoint



It is not possible to delete a locked object


Permanently delete the version of an object on the bucket :

aws s3api delete-object --bucket bucket_name --key file_name --version-id id_of_version (of the file version and not of the delete marker for permanent deletion) --endpoint-url https:// your_endpoint


If the version is locked, the API will return an error.


Restore an object deleted on your bucket but having a Delete Marker :

aws s3api delete-object --bucket bucket_name --key file_name --version-id id_of_the_version_of_the_delete_marker_of_the_file --endpoint-url https:// your_endpoint



Delete a bucket :

aws s3 rb s3://bucket_name --force --endpoint-url https:// your_endpoint


If the bucket contains locked objects, the API will return an error.


Delete all files in a bucket :

aws s3 rm s3://bucket_name --recursive --endpoint-url https:// your_endpoint


If the bucket contains locked objects, the API will also return an error.


Delete all .doc files in a bucket :

aws s3 rm s3://bucket_name/doc --recursive --endpoint-url https:// your_endpoint

Updated on: 10/10/2024

Was this article helpful?

Share your feedback

Cancel

Thank you!