Skip to content

pmdiaz/s3sh

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

S3sh - S3 Shell

A Rust command-line interface (CLI) application for managing Amazon S3 buckets and objects simply and elegantly.

Features

  • Bucket Management: List, create, and view configuration.
  • Object Management: List, upload (with progress bar), delete, restore, and view attributes.
  • Lifecycle Management: Manage lifecycle rules (transitions and expiration).
  • Friendly Interface: Formatted output with colors and tables.
  • Flexible Configuration: Support for AWS profiles and regions.

Requirements

  • Rust (cargo) installed.
  • AWS credentials configured (via aws configure or environment variables).

Installation and Build

To build the project:

cargo build --release

The resulting binary will be located at target/release/s3sh.

Usage

The application can be run directly with cargo run or using the compiled binary.

Global Options

  • -r, --region <REGION>: Specify the AWS region (e.g., us-east-1).
  • -p, --profile <PROFILE>: Specify the AWS profile to use.

Bucket Commands

List all buckets:

cargo run -- bucket list

Create a new bucket:

cargo run -- bucket create <bucket-name>

# Create with initial configuration
cargo run -- bucket create <bucket-name> --public true --versioning true --tags Env=Dev

View bucket configuration:

cargo run -- bucket config <bucket-name>

Update bucket configuration:

# Make public (disable Block Public Access)
cargo run -- bucket update <bucket-name> --public true

# Enable versioning
cargo run -- bucket update <bucket-name> --versioning true

# Configure encryption (AES256 or aws:kms)
cargo run -- bucket update <bucket-name> --encryption AES256

# Add tags
cargo run -- bucket update <bucket-name> --tags Environment=Dev Project=S3sh

Lifecycle Management

Manage lifecycle rules for a bucket.

# Add a lifecycle rule
s3sh bucket lifecycle <bucket-name> \
  --id <rule-id> \
  --transitions '[{"days": 30, "storage_class": "STANDARD_IA"}]' \
  --expiration 365

# Complex example with prefix and multiple transitions
cargo run -- bucket lifecycle my-test-bucket \
  --id "archive-logs-rule" \
  --prefix "logs/" \
  --transitions '[
    {"days": 30, "storage_class": "STANDARD_IA"},
    {"days": 90, "storage_class": "GLACIER"}
  ]' \
  --expiration 365

Arguments:

  • --id: Unique identifier for the rule.
  • --transitions: JSON array with transitions (e.g., [{"days": 30, "storage_class": "STANDARD_IA"}]).
  • --expiration: (Optional) Days for object expiration.
  • --prefix: (Optional) Prefix to filter affected objects.
  • --status: (Optional) true to enable, false to disable (default: true).

Object Commands

List objects in a bucket:

cargo run -- object list <bucket-name>

Upload a file:

cargo run -- object upload <bucket-name> <path-to-file>
# Optionally specify a different key (S3 name):
cargo run -- object upload <bucket-name> <path-to-file> --key <destination-name>

View object attributes:

cargo run -- object attributes <bucket-name> <object-key>

Delete an object:

cargo run -- object delete <bucket-name> <object-key>

Restore an object (from Glacier):

cargo run -- object restore <bucket-name> <object-key>

Credential Configuration

The application uses the default AWS credential provider chain. It will look for credentials in this order:

  1. Environment variables (AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, etc.).
  2. Configuration files (~/.aws/credentials, ~/.aws/config).

Testing

The project includes unit and integration tests. To run them:

cargo test

Integration tests are located in the tests/ directory and use mocks to simulate AWS S3 responses, so they do not require real credentials nor do they generate costs.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages