> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.bitiful.com/en/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.bitiful.com/_mcp/server.

# Use AWS CLI and s5cmd

> Connect to Bitiful S4 with AWS CLI and s5cmd: configuration, upload and download, sync, presigned links, move, and batch operations.

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](https://docs.bitiful.com/en/bitiful-s4/handbook/buckets.md);
- You have [created a sub-user and AccessKey](https://docs.bitiful.com/en/bitiful-s4/handbook/access-keys.md) and completed the [grants](https://docs.bitiful.com/en/bitiful-s4/handbook/permissions.md).

## AWS CLI

### Install and configure

Install by following the [official instructions](https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html), then create a separate profile for S4:

**Windows**

```powershell title="PowerShell"
aws.exe configure set aws_access_key_id "Your AccessKey" --profile s4
aws.exe configure set aws_secret_access_key "Your SecretKey" --profile s4
aws.exe configure set region cn-east-1 --profile s4
aws.exe configure set endpoint_url https://s3.bitiful.net --profile s4
```

**macOS**

```bash
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 s4
```

**Linux**

```bash
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 s4
```

Putting `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:

**Windows**

```powershell title="PowerShell"
$env:AWS_PROFILE="s4"
```

**macOS**

```bash
export AWS_PROFILE=s4
```

**Linux**

```bash
export AWS_PROFILE=s4
```

On Windows, run the commands in PowerShell and replace `D:\` in the examples with your own directory.

### Upload and download

**Windows**

```powershell title="PowerShell"
# Upload
aws.exe s3 cp D:\logo.png s3://my-bucket/images/logo.png

# Specify the type and browser cache
aws.exe s3 cp D:\app.js s3://my-bucket/static/app.js --content-type "application/javascript" --cache-control "max-age=86400"

# Upload an entire directory
aws.exe s3 cp D:\dist s3://my-bucket/site/ --recursive

# Upload images only
aws.exe s3 cp D:\assets s3://my-bucket/assets/ --recursive --exclude "*" --include "*.png" --include "*.jpg"

# Download
aws.exe s3 cp s3://my-bucket/images/logo.png D:\logo.png

# Back up a database and upload it
mysqldump.exe mydb --result-file=D:\backup\mydb.sql
aws.exe s3 cp D:\backup\mydb.sql s3://my-bucket/backup/mydb.sql

# Print to standard output
aws.exe s3 cp s3://my-bucket/notes/todo.txt -
```

**macOS**

```bash
# 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

# Upload images only
aws s3 cp ./assets s3://my-bucket/assets/ --recursive --exclude "*" --include "*.png" --include "*.jpg"

# Download
aws s3 cp s3://my-bucket/images/logo.png ./logo.png

# Upload from standard input, or print to standard output
mysqldump mydb | gzip | aws s3 cp - s3://my-bucket/backup/mydb.sql.gz
aws s3 cp s3://my-bucket/notes/todo.txt -
```

**Linux**

```bash
# 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

# Upload images only
aws s3 cp ./assets s3://my-bucket/assets/ --recursive --exclude "*" --include "*.png" --include "*.jpg"

# Download
aws s3 cp s3://my-bucket/images/logo.png ./logo.png

# Upload from standard input, or print to standard output
mysqldump mydb | gzip | aws s3 cp - s3://my-bucket/backup/mydb.sql.gz
aws s3 cp s3://my-bucket/notes/todo.txt -
```

### Sync

**Windows**

```powershell title="PowerShell"
# Upload only files that changed
aws.exe s3 sync D:\dist s3://my-bucket/site/

# Also delete extra files in the bucket; do a dry run with --dryrun first
aws.exe s3 sync D:\dist s3://my-bucket/site/ --delete --dryrun
aws.exe s3 sync D:\dist s3://my-bucket/site/ --delete

# In CI, file times change on every build; comparing by size uploads less
aws.exe s3 sync D:\dist s3://my-bucket/site/ --size-only
```

**macOS**

```bash
# 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/ --delete

# In CI, file times change on every build; comparing by size uploads less
aws s3 sync ./dist s3://my-bucket/site/ --size-only
```

**Linux**

```bash
# 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/ --delete

# In CI, file times change on every build; comparing by size uploads less
aws s3 sync ./dist s3://my-bucket/site/ --size-only
```

### View and delete

**Windows**

```powershell title="PowerShell"
aws.exe s3 ls                                  # Buckets you can access
aws.exe s3 ls s3://my-bucket/images/           # One directory level
aws.exe s3 ls s3://my-bucket/images/ --recursive --human-readable --summarize

# Filter, for example objects larger than 100 MB
aws.exe s3api list-objects-v2 --bucket my-bucket --prefix images/ --query 'Contents[?Size>`104857600`].[Key,Size]' --output text

# View metadata
aws.exe s3api head-object --bucket my-bucket --key images/logo.png

aws.exe s3 rm s3://my-bucket/images/logo.png
aws.exe s3 rm s3://my-bucket/tmp/ --recursive  # Delete a whole directory, cannot be undone
```

**macOS**

```bash
aws s3 ls                                  # Buckets you can access
aws s3 ls s3://my-bucket/images/           # One directory level
aws s3 ls s3://my-bucket/images/ --recursive --human-readable --summarize

# Filter, for example objects larger than 100 MB
aws s3api list-objects-v2 --bucket my-bucket --prefix images/ --query 'Contents[?Size>`104857600`].[Key,Size]' --output text

# View metadata
aws s3api head-object --bucket my-bucket --key images/logo.png

aws s3 rm s3://my-bucket/images/logo.png
aws s3 rm s3://my-bucket/tmp/ --recursive  # Delete a whole directory, cannot be undone
```

**Linux**

```bash
aws s3 ls                                  # Buckets you can access
aws s3 ls s3://my-bucket/images/           # One directory level
aws s3 ls s3://my-bucket/images/ --recursive --human-readable --summarize

# Filter, for example objects larger than 100 MB
aws s3api list-objects-v2 --bucket my-bucket --prefix images/ --query 'Contents[?Size>`104857600`].[Key,Size]' --output text

# View metadata
aws s3api head-object --bucket my-bucket --key images/logo.png

aws s3 rm s3://my-bucket/images/logo.png
aws s3 rm s3://my-bucket/tmp/ --recursive  # Delete a whole directory, cannot be undone
```

### Presigned download links

**Windows**

```powershell title="PowerShell"
aws.exe s3 presign s3://my-bucket/images/logo.png --expires-in 3600
```

**macOS**

```bash
aws s3 presign s3://my-bucket/images/logo.png --expires-in 3600
```

**Linux**

```bash
aws s3 presign s3://my-bucket/images/logo.png --expires-in 3600
```

The validity period is in seconds, up to 604800 (7 days). For presigned upload links and S4 extension parameters, see [Presigned URLs](https://docs.bitiful.com/en/developer/s3/presigned-url.md).

### Metadata and tags

**Windows**

```powershell title="PowerShell"
# Change the type and cache headers without re-uploading
aws.exe s3 cp s3://my-bucket/app.js s3://my-bucket/app.js --metadata-directive REPLACE --content-type "application/javascript" --cache-control "max-age=86400"

# Set and view tags
aws.exe s3api put-object-tagging --bucket my-bucket --key app.js --tagging 'TagSet=[{Key=env,Value=prod}]'
aws.exe s3api get-object-tagging --bucket my-bucket --key app.js
```

**macOS**

```bash
# Change the type and cache headers without re-uploading
aws s3 cp s3://my-bucket/app.js s3://my-bucket/app.js --metadata-directive REPLACE --content-type "application/javascript" --cache-control "max-age=86400"

# Set and view tags
aws s3api put-object-tagging --bucket my-bucket --key app.js --tagging 'TagSet=[{Key=env,Value=prod}]'
aws s3api get-object-tagging --bucket my-bucket --key app.js
```

**Linux**

```bash
# Change the type and cache headers without re-uploading
aws s3 cp s3://my-bucket/app.js s3://my-bucket/app.js --metadata-directive REPLACE --content-type "application/javascript" --cache-control "max-age=86400"

# Set and view tags
aws s3api put-object-tagging --bucket my-bucket --key app.js --tagging 'TagSet=[{Key=env,Value=prod}]'
aws s3api get-object-tagging --bucket my-bucket --key app.js
```

`REPLACE` replaces all metadata. Custom metadata you leave out is removed.

### Move and conditional writes

**Windows**

```powershell title="PowerShell"
# Native move, no data copied
aws.exe 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.exe s3api put-object --bucket my-bucket --key locks/job --body D:\job.txt --if-none-match "*"
```

**macOS**

```bash
# 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 "*"
```

**Linux**

```bash
# 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. See [Move and rename objects](https://docs.bitiful.com/en/bitiful-s4/features/move-object.md). If the object already exists, the conditional write returns 412 `PreconditionFailed`. See [Conditional requests](https://docs.bitiful.com/en/developer/s3/conditional-requests.md). `--if-none-match` requires a recent AWS CLI.

### Clean up incomplete multipart uploads

Interrupted multipart uploads keep occupying space:

**Windows**

```powershell title="PowerShell"
aws.exe s3api list-multipart-uploads --bucket my-bucket --query "Uploads[].[Key,UploadId,Initiated]" --output text

aws.exe s3api abort-multipart-upload --bucket my-bucket --key videos/a.mp4 --upload-id "UploadId from above"
```

**macOS**

```bash
aws s3api list-multipart-uploads --bucket my-bucket --query "Uploads[].[Key,UploadId,Initiated]" --output text

aws s3api abort-multipart-upload --bucket my-bucket --key videos/a.mp4 --upload-id "UploadId from above"
```

**Linux**

```bash
aws s3api list-multipart-uploads --bucket my-bucket --query "Uploads[].[Key,UploadId,Initiated]" --output text

aws s3api abort-multipart-upload --bucket my-bucket --key videos/a.mp4 --upload-id "UploadId from above"
```

### Adjust concurrency and part size

**Windows**

```powershell title="PowerShell"
aws.exe configure set s3.max_concurrent_requests 20 --profile s4
aws.exe configure set s3.multipart_threshold 64MB --profile s4
aws.exe configure set s3.multipart_chunksize 64MB --profile s4
```

**macOS**

```bash
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 s4
```

**Linux**

```bash
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 s4
```

## s5cmd

### Install and configure

s5cmd suits large numbers of small files. Download it from the [s5cmd releases page](https://github.com/peak/s5cmd/releases), or install it with a package manager:

**Windows**

```powershell
scoop install s5cmd
```

**macOS**

```bash
brew install peak/tap/s5cmd
```

**Linux**

```bash
brew install peak/tap/s5cmd
```

Configure it with environment variables:

**Windows**

```powershell title="PowerShell"
$env:AWS_ACCESS_KEY_ID="Your AccessKey"
$env:AWS_SECRET_ACCESS_KEY="Your SecretKey"
$env:AWS_REGION="cn-east-1"
$env:S3_ENDPOINT_URL="https://s3.bitiful.net"
```

**macOS**

```bash
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.net
```

**Linux**

```bash
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.net
```

### Common commands

**Windows**

```powershell title="PowerShell"
# List
s5cmd.exe ls s3://my-bucket/images/

# Upload a directory
s5cmd.exe cp 'D:\dist\*' s3://my-bucket/site/

# Download a directory
s5cmd.exe cp 's3://my-bucket/site/*' D:\dist\

# Sync
s5cmd.exe sync D:\dist\ s3://my-bucket/site/

# Batch delete
s5cmd.exe rm 's3://my-bucket/tmp/*'

# Calculate size
s5cmd.exe du --humanize 's3://my-bucket/site/*'

# View contents, upload from standard input
s5cmd.exe cat s3://my-bucket/notes/todo.txt
echo "hello" | s5cmd.exe pipe s3://my-bucket/notes/hello.txt

# Temporary download link
s5cmd.exe presign --expire 1h s3://my-bucket/images/logo.png
```

**macOS**

```bash
# 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/*'

# View contents, upload from standard input
s5cmd cat s3://my-bucket/notes/todo.txt
echo "hello" | s5cmd pipe s3://my-bucket/notes/hello.txt

# Temporary download link
s5cmd presign --expire 1h s3://my-bucket/images/logo.png
```

**Linux**

```bash
# 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/*'

# View contents, upload from standard input
s5cmd cat s3://my-bucket/notes/todo.txt
echo "hello" | s5cmd pipe s3://my-bucket/notes/hello.txt

# Temporary download link
s5cmd presign --expire 1h s3://my-bucket/images/logo.png
```

Write several commands to a file and run them concurrently, in no particular order:

Use `/` in local paths in this file, on Windows too, for example `D:/backup/a.zip`.

```text title="commands.txt"
cp ./a.zip s3://my-bucket/backup/a.zip
cp ./b.zip s3://my-bucket/backup/b.zip
rm s3://my-bucket/tmp/old.txt
```

**Windows**

```powershell title="PowerShell"
s5cmd.exe run commands.txt
```

**macOS**

```bash
s5cmd run commands.txt
```

**Linux**

```bash
s5cmd run commands.txt
```

Adjust concurrency:

**Windows**

```powershell title="PowerShell"
s5cmd.exe --numworkers 64 cp 'D:\data\*' s3://my-bucket/data/
```

**macOS**

```bash
s5cmd --numworkers 64 cp './data/*' s3://my-bucket/data/
```

**Linux**

```bash
s5cmd --numworkers 64 cp './data/*' s3://my-bucket/data/
```

The default concurrency is 256, which can trigger the [QPS limit](https://docs.bitiful.com/en/bitiful-s4/limits.md); lower it when you see 429.

## FAQ

<details>
<summary>Do I need to set output in aws configure?</summary>

No. When a script processes the result, add `--output json` or `--output text` to the command.

</details>

<details>
<summary>aws s3 mb returns 403</summary>

Sub-users cannot create buckets. Create buckets in the [console](https://docs.bitiful.com/en/bitiful-s4/handbook/buckets.md).

</details>

<details>
<summary>aws s3 ls returns nothing</summary>

It only lists buckets the sub-user has been granted access to. [Grant access](https://docs.bitiful.com/en/bitiful-s4/handbook/permissions.md) first.

</details>

<details>
<summary>Could not connect to the endpoint URL</summary>

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.

</details>

<details>
<summary>SignatureDoesNotMatch</summary>

Check whether the keys have extra spaces, whether the Region is `cn-east-1`, and whether the local clock is accurate.

</details>
