Skip to main content

AWS CLI

The AWS Command Line Interface (CLI) provides powerful command-line access to OSS using the same commands as Amazon S3.

Installation

Quick Install

# Using pip
pip install awscli

# Verify installation
aws --version

Platform-specific Install

macOS: brew install awscli
Ubuntu/Debian: sudo apt install awscli
CentOS/RHEL: sudo yum install awscli

Configuration

Configure OSS Profile

aws configure --profile oss

Enter when prompted:

  • Access Key ID: Your OSS Access Key
  • Secret Access Key: Your OSS Secret Key
  • Region: us-east-1
  • Output format: json

Create Alias (Optional)

Add to your shell profile (.bashrc, .zshrc):

alias oss='aws s3 --endpoint-url https://<CustomerId>.oss.swiftserve.com --profile oss'

Then use: oss ls instead of the full command.

Basic Operations

Bucket Operations

# List buckets
aws s3 ls --endpoint-url https://<CustomerId>.oss.swiftserve.com --profile oss

# Create bucket
aws s3 mb s3://my-bucket --endpoint-url https://<CustomerId>.oss.swiftserve.com --profile oss

# Delete bucket (must be empty)
aws s3 rb s3://my-bucket --endpoint-url https://<CustomerId>.oss.swiftserve.com --profile oss

# Force delete (removes all objects first)
aws s3 rb s3://my-bucket --force --endpoint-url https://<CustomerId>.oss.swiftserve.com --profile oss

Object Operations

# List objects
aws s3 ls s3://my-bucket --endpoint-url https://<CustomerId>.oss.swiftserve.com --profile oss

# Upload file
aws s3 cp file.txt s3://my-bucket/ --endpoint-url https://<CustomerId>.oss.swiftserve.com --profile oss

# Download file
aws s3 cp s3://my-bucket/file.txt ./ --endpoint-url https://<CustomerId>.oss.swiftserve.com --profile oss

# Delete object
aws s3 rm s3://my-bucket/file.txt --endpoint-url https://<CustomerId>.oss.swiftserve.com --profile oss

Synchronization

# Sync local folder to bucket
aws s3 sync ./local-folder s3://my-bucket/remote-folder/ \
--endpoint-url https://<CustomerId>.oss.swiftserve.com --profile oss

# Sync bucket to local folder
aws s3 sync s3://my-bucket/ ./local-backup/ \
--endpoint-url https://<CustomerId>.oss.swiftserve.com --profile oss

# Sync with delete (remove extra files)
aws s3 sync ./local-folder s3://my-bucket/ --delete \
--endpoint-url https://<CustomerId>.oss.swiftserve.com --profile oss

Advanced Features

Backup Script Example

#!/bin/bash
# daily-backup.sh
SOURCE="/important/data"
BUCKET="backup-bucket"
DATE=$(date +%Y-%m-%d)
ENDPOINT="https://<CustomerId>.oss.swiftserve.com"

aws s3 sync "$SOURCE" "s3://$BUCKET/$DATE/" \
--endpoint-url "$ENDPOINT" --profile oss \
--exclude "*.tmp" --exclude "*.log"

Performance Tuning

# Configure for large files
aws configure set default.s3.multipart_threshold 64MB --profile oss
aws configure set default.s3.multipart_chunksize 16MB --profile oss
aws configure set default.s3.max_concurrent_requests 10 --profile oss

Presigned URLs

# Generate download URL (valid for 1 hour)
aws s3 presign s3://my-bucket/file.txt --expires-in 3600 \
--endpoint-url https://<CustomerId>.oss.swiftserve.com --profile oss

Troubleshooting

IssueSolution
SSL Certificate ErrorsAdd --no-verify-ssl flag temporarily
Connection TimeoutsIncrease timeout: aws configure set default.cli_read_timeout 120
Access DeniedVerify credentials and endpoint URL
Large File FailuresReduce chunk size: aws configure set default.s3.multipart_chunksize 8MB

Common Patterns

CI/CD Integration

# Deploy website
aws s3 sync ./dist s3://website-bucket/ \
--endpoint-url https://<customer-id>.oss.swiftserve.com \
--profile oss --delete

File Filtering

# Upload only images
aws s3 sync ./photos s3://my-bucket/photos/ \
--exclude "*" --include "*.jpg" --include "*.png" \
--endpoint-url https://<customer-id>.oss.swiftserve.com --profile oss

Storage Usage Report

# Get bucket size and object count
aws s3 ls s3://my-bucket --recursive --human-readable --summarize \
--endpoint-url https://<customer-id>.oss.swiftserve.com --profile oss

AWS CLI is ideal for automation and scripting. For GUI management, see S3Browser.