s3hub - user-friendly AWS S3 management tool with interactive mode
Tags: showdev, aws, go, cli
Published: 2024-02-04 16:08:20

## Why I Created s3hub
When building AWS resources with CloudFormation, I often find myself needing to check the contents of S3 buckets. How do you typically check the contents of S3 buckets? Personally, I'm not fond of the AWS Management Console (GUI), and I find the AWS CLI somewhat cumbersome.

It's a bad habit of mine, but I tend to create tools to solve problems. The tool I've created this time is named [s3hub](https://github.com/nao1215/rainbow?tab=readme-ov-file), and its main feature is its interactive mode.

![interactive](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/g1puw5cbdg3qvvn84zp0.gif)

## Features
The s3hub command provides following features:
- Create a S3 bucket
- List S3 buckets
- List S3 objects in the S3 bucket
- Copy files to S3 bucket
- Delete contents from the S3 bucket
- Delete the S3 bucket
- Interactive mode

## How to install
```shell
go install github.com/nao1215/rainbow/cmd/s3hub@latest
```

## How to use
The s3hub command allows you to specify a profile as an option, but it is more user-friendly to use the `AWS_PROFILE` environment variable. S3hub operates without requiring the 's3://' protocol to be added to the bucket name.


### Create a bucket(s)

```shell
s3hub mb ${YOUR_BUCKET_NAME}
```
![mb](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yn4wlj1slx7336sza2fq.gif)


### List buckets
```shell
s3hub ls
```
![ls](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ozhk0wt4rk7n872jzk6w.gif)


### List contents of a bucket
```shell
s3hub ls ${YOUR_BUCKET_NAME}
```
![ls-all](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9r4kbre6qpwhr2hwmaic.gif)


### Copy files to a bucket
From local to S3:
```shell
s3hub cp ${YOUR_FILE_PATH} s3://${YOUR_BUCKET_NAME}
```

From S3 to local:
```shell
s3hub cp s3://${YOUR_BUCKET_NAME} ${YOUR_FILE_PATH}
```

### Delete a object from a bucket
If you want to delete a specific object, use the following command:
```shell
s3hub rm ${CONTENT_PATH_IN_BUCKET}/${S3_KEY}
```

If you want to delete all contents in a bucket, use the wildcard:
```shell
s3hub rm ${YOUR_BUCKET_NAME}/*
```

### Delete a bucket with objects
When the number of S3 objects is large, we parallelize the deletion process to enhance speed.
```shell
s3hub rm --recursive ${YOUR_BUCKET_NAME}
```

## s3hub is Part of the Rainbow Project
I use AWS for work, and I plan to develop numerous tools to make development with AWS easier. I thought "rainbow" would be a fitting name for the repository that manages multiple tools. I borrowed it from my favorite band, Ritchie Blackmore's Rainbow (I'm 33 years old, but I love this band).

I plan to continue developing many tools in the future, so if you're interested, please support me with [GitHub Star](https://github.com/nao1215/rainbow) and such. GitHub Stars are a great way to boost developers' motivation for free.

The Rainbow Project incurs costs because it utilizes AWS. For those who are willing to provide financial support, please consider supporting us through [GitHub Sponsors](https://github.com/sponsors/nao1215). We would be deeply grateful and appreciative.