stree is a CLI tool designed to visualize the directory tree structure of an S3 bucket.
By inputting an S3 bucket/prefix and utilizing various flags to customize your request, you can obtain a colorized or non-colorized directory tree right in your terminal.
Whether it's for verifying the file structure, sharing the structure with your team, or any other purpose, stree offers an easy and convenient way to explore your S3 buckets.
日本語の紹介記事→stree:S3バケットをtreeするCLIコマンド
Community | AWS open source newsletter, #189
- Colorized Output: By default,
streeprovides a colorized tree structure, making it easy to differentiate between directories and files at a glance. This feature can be turned off with the-nor--no-colorflag. - LocalStack Support:
streesupports local testing with LocalStack, a fully functional local AWS cloud stack, thanks to the--localand--endpoint-urlflags. - Custom AWS Profile and Region: Specify the AWS profile and region with the
--profileand--regionflags to override the default settings as needed. - Ease of Installation: Install
streevia Go, Homebrew, or by downloading the latest compiled binaries from the GitHub releases page. - Depth level Specification: With the new
--Lflag, you can now specify how many levels deep in the directory structure you'd like to visualize. This offers a more focused view, especially for large S3 buckets. - Role Switching Support:
streeis now enhanced with the ability to switch AWS roles with MFA using the--mfaflag. This makes it easier to manage and view S3 buckets that require different IAM roles for access. - Environment Variable Support:
streenow prioritizes environment variables for AWS Profile and Region settings. The tool will use theAWS_PROFILEenvironment variable if set, falling back to thedefaultprofile otherwise. Similarly, it will use theAWS_REGIONorAWS_DEFAULT_REGIONenvironment variables for the AWS region, if available. (see AWS CLI Environment Variables for more information) - Full Path Display: With the
-fflag, the full path of each file is now displayed in the output, making it easier to identify the location of each item within the S3 bucket.
go install github.com/orangekame3/stree@latestbrew install orangekame3/tap/streeDownload the latest compiled binaries and put it anywhere in your executable path.
Warning
Prerequisite
You must set up the config and credentials to be used with aws cli in advance
From here on, it is assumed that the config and credentials are set as follows.
~/.aws/config
[my_profile]
region = ap-northeast-1
output = json~/.aws/credentials
[my_profile]
aws_access_key_id=XXXXXXXXXXXXXXXXXXXXX
aws_secret_access_key=XXXXXXXXXXXXXXXXXSpecify the bucket name and profile, and execute the following command. The profile is specified with --profile (-p).
stree my-bucket -p my_profileYou will get the following output.
my-bucket
└── test
├── dir1
│ ├── dir1_1
│ │ └── dir1_1_1
│ │ ├── file1.csv
│ │ └── file2.csv
│ └── dir1_2
│ ├── file1.csv
│ ├── file2.csv
│ └── file3.csv
├── dir2
│ └── dir2_1
│ └── dir2_1_1
│ ├── file1.csv
│ ├── file2.csv
│ └── file3.csv
└── dir3
├── file1.csv
└── file2.csv
9 directories, 10 filesstree my-bucket/test/dir2 -p my_profileThe result of executing this command is as follows.
my-bucket
└── test
└── dir2
└── dir2_1
└── dir2_1_1
├── file1.csv
├── file2.csv
└── file3.csv
4 directories, 3 filesYou can specify the region with --region (-r). Use the --region flag to override when you want to specify a region other than the one listed in the profile.
It can also be used with Localstack. When using it with Localstack, the endpoint and region are set to the following by default.
endpoint = http://localhost:4566
region = us-east-1Since the majority of cases are expected to use the above settings, we have added a flag for Localstack, which is --local (-l).
stree my-bucket/test/dir2 -lIn case you need to change the endpoint and region due to special circumstances, you can override with --region (-r) flag and --endpoint (-e).
stree my-bucket/test/dir2 -r us-east-1 -e http://localhost:4537You can disable color output with --no-color (-n).
With color
Without color
You can specify the depth level with --level (-L). The default is 0, which means that all directories are displayed.
stree my-bucket -p my_profile -L 3
my-bucket
└── test
├── dir3
│ ├── file1.csv
│ └── file2.csv
├── dir1
│ ├── dir1_1
│ └── dir1_2
└── dir2
└── dir2_1You can switch roles with MFA using the --mfa flag. This makes it easier to manage and view S3 buckets that require different IAM roles for access.
To use this feature, you must first set up the config and credentials to be used with aws cli in advance.
[profile dev_david]
source_profile = my_profile
# MFA device
mfa_serial = arn:aws:iam::820544363308:mfa/david_mfa_device
# Role to assume
role_arn = arn:aws:iam::820544363308:role/david_rolesee Assume AWS IAM Roles with MFA Using the AWS SDK for Go for more information
And then execute the following command.
stree my-bucket -p dev_david -mfaAlso, if you wish to operate with a profile that assumes a role, you can specify it using the --profile (-p) flag, without the need for MFA.
[profile dev_david]
source_profile = my_profile
# Role to assume
role_arn = arn:aws:iam::820544363308:role/david_roleAnd then execute the following command.
stree my-bucket -p dev_davidUsage:
stree [bucket/prefix] [flags]
Flags:
-e, --endpoint-url string AWS endpoint URL to use (useful for local testing with LocalStack)
-h, --help help for stree
-L, --level int Descend only level directories
-l, --local Use LocalStack configuration
-m, --mfa Use Multi-Factor Authentication
-n, --no-color Disable colorized output
-p, --profile string AWS profile to use (default "default")
-r, --region string AWS region to use (overrides the region specified in the profile)
-f Print the full path prefix for each file.stree is licensed under the MIT License - see the LICENSE file for details.
The concept of "stree" was inspired by the pioneering work seen in gtree. I'm grateful for the inspiration.