In this guide, we will walk through how to use the AWS CLI to perform basic operations with Amazon S3, such as creating a bucket, listing objects, and deleting both objects and the bucket.
To create an S3 bucket using the AWS CLI, execute the following command. Make sure to replace aws-cli-2000
with your desired bucket name.
aws s3 mb s3://aws-cli-2000
Make sure your bucket name is unique and complies with AWS naming conventions.
After creating the bucket, use the following command to list all the available S3 buckets:
aws s3 ls
To view the contents of a specific S3 bucket, use the following command:
aws s3 ls s3://bucket-name
Replace bucket-name
with the name of the bucket you want to inspect.
To remove an object from the S3 bucket, run the following command:
aws s3 rm s3://bucket-name/object
Replace bucket-name
with your bucket name and object
with the specific object you want to delete.
Deleting an object is permanent and cannot be undone.
Finally, once all objects are removed, you can delete the bucket itself with the command:
aws s3 rb s3://bucket-name
Ensure the bucket is empty before attempting to delete it. Use --force
to delete non-empty buckets, but exercise caution.
By following these steps, you’ve learned how to create, list, and delete S3 buckets and objects using the AWS CLI. These fundamental commands will help you manage your S3 resources efficiently.