Use AWS CLI and s5cmd
AWS CLI is the official command-line tool and the most complete; s5cmd handles many files with high concurrency and is faster. Both can connect to S4 directly.
Prerequisites
- You have created a bucket;
- You have created a sub-user and AccessKey and completed the grants.
AWS CLI
Install and configure
Install by following the official instructions, then create a separate profile for S4:
aws configure set aws_access_key_id "Your AccessKey" --profile s4
aws configure set aws_secret_access_key "Your SecretKey" --profile s4
aws configure set region cn-east-1 --profile s4
aws configure set endpoint_url https://s3.bitiful.net --profile s4Putting endpoint_url in a profile requires AWS CLI 2.13 or later. With older versions, add --endpoint-url https://s3.bitiful.net to every command.
Add --profile s4 to all later commands, or set the environment variable first:
export AWS_PROFILE=s4Upload and download
# Upload
aws s3 cp ./logo.png s3://my-bucket/images/logo.png
# Specify the type and browser cache
aws s3 cp ./app.js s3://my-bucket/static/app.js \
--content-type "application/javascript" --cache-control "max-age=86400"
# Upload an entire directory
aws s3 cp ./dist s3://my-bucket/site/ --recursive
# Download
aws s3 cp s3://my-bucket/images/logo.png ./logo.pngSync
# Upload only files that changed
aws s3 sync ./dist s3://my-bucket/site/
# Also delete extra files in the bucket; do a dry run with --dryrun first
aws s3 sync ./dist s3://my-bucket/site/ --delete --dryrun
aws s3 sync ./dist s3://my-bucket/site/ --deleteView and delete
aws s3 ls # Buckets you have been granted
aws s3 ls s3://my-bucket/images/ # Top-level directory
aws s3 ls s3://my-bucket/images/ --recursive --human-readable --summarize
aws s3 rm s3://my-bucket/images/logo.png
aws s3 rm s3://my-bucket/tmp/ --recursive # Delete an entire directory; cannot be undonePresigned download links
aws s3 presign s3://my-bucket/images/logo.png --expires-in 3600The validity period is in seconds, up to 604800 (7 days).
Move and conditional writes
# Native move, no data copied
aws s3api copy-object --bucket my-bucket --key "new/photo.jpg" \
--copy-source "my-bucket/old/photo.jpg?move=true"
# Write only if the object does not exist
aws s3api put-object --bucket my-bucket --key locks/job --body ./job.txt --if-none-match "*"aws s3 mv copies and then deletes, so use the move above for large files. --if-none-match requires a recent AWS CLI.
Adjust concurrency and part size
aws configure set s3.max_concurrent_requests 20 --profile s4
aws configure set s3.multipart_threshold 64MB --profile s4
aws configure set s3.multipart_chunksize 64MB --profile s4s5cmd
Install and configure
Download it from the s5cmd releases page, or install it with Homebrew:
brew install peak/tap/s5cmdConfigure it with environment variables:
export AWS_ACCESS_KEY_ID="Your AccessKey"
export AWS_SECRET_ACCESS_KEY="Your SecretKey"
export AWS_REGION=cn-east-1
export S3_ENDPOINT_URL=https://s3.bitiful.netCommon commands
# List
s5cmd ls s3://my-bucket/images/
# Upload a directory
s5cmd cp './dist/*' s3://my-bucket/site/
# Download a directory
s5cmd cp 's3://my-bucket/site/*' ./dist/
# Sync
s5cmd sync ./dist/ s3://my-bucket/site/
# Batch delete
s5cmd rm 's3://my-bucket/tmp/*'
# Calculate size
s5cmd du --humanize 's3://my-bucket/site/*'Adjust concurrency:
s5cmd --numworkers 64 cp './data/*' s3://my-bucket/data/The default concurrency is 256, which can trigger the QPS limit; lower it when you see 429.
FAQ
aws s3 mb returns 403
Sub-users cannot create buckets. Create buckets in the console.
aws s3 ls returns nothing
It only lists buckets the sub-user has been granted access to. Grant access first.
Could not connect to the endpoint URL
The endpoint is not set, so the request went to AWS. Check with aws configure list --profile s4, or add --endpoint-url to the command.
SignatureDoesNotMatch
Check whether the keys have extra spaces, whether the Region is cn-east-1, and whether the local clock is accurate.