DEV Community

Cover image for Manage AWS S3 Object Storage via the CLI
R o r d a n ♨️
R o r d a n ♨️

Posted on • Edited on

Manage AWS S3 Object Storage via the CLI

AWS S3 is a viable serverless object storage service that can be utilized via your command line.

A bucket is the name for the cloud storage and an object is the file within it.

To create a bucket, simply have your aws cli already configured and run the following command with the region in which you would like your storage to be hosted.

aws s3api create-bucket --bucket <name> --<region>
Enter fullscreen mode Exit fullscreen mode

Image description

Sending data from your local directory straight to an s3 bucket can be done by utilizing the copy command.

aws s3 cp <local directory> <s3 bucket w/ path>
Enter fullscreen mode Exit fullscreen mode

Call the local directory path with the s3 path-based naming style afterwards by appending s3:// as a prefix to the bucket name.

Image description

Note that the difference between using aws s3 vs aws s3api is that the s3api command reflects the operations of plain API commands, while as "aws s3" can be utilized for higher level commands such as file transferring.

View currently active s3 buckets with the following command.

aws s3api list-buckets
Enter fullscreen mode Exit fullscreen mode

Image description

The data is neatly shown in JSON format with the name of each bucket and its creation date.

To view the contents of and individual bucket run

aws s3 ls <bucket name>
Enter fullscreen mode Exit fullscreen mode

Image description

And lastly to clean up an environment, and in turn save on additional unwanted costs, its necessary to remove old s3 buckets and the objects within them.

Remove a bucket including all the contents within it, , and --force as an ending flag.

aws s3 rb s3://<bucket name> --force
Enter fullscreen mode Exit fullscreen mode

Image description

Top comments (0)