Using AWS CLI

Some common use cases

1. Create a new bucket

aws s3api create-bucket \
  --bucket demoawscli-bucket \
  --profile han02-prod \
  --endpoint-url https://han02.vstorage.vngcloud.vn

2. Upload object

Example 1:

aws s3 cp ./local-file.txt s3://demoawscli-bucket/file.txt \
  --profile han02-prod \
  --endpoint-url https://han02.vstorage.vngcloud.vn

Example 2:

aws s3api put-object \
  --bucket demoawscli-bucket \
  --key test-folder/style.css \
  --body ./demo-file.gz \
  --content-type "text/css; charset=utf-8" \
  --cache-control "max-age=31536000, no-transform, public" \
  --content-encoding "gzip" \
  --acl public-read \
  --profile han02-prod \
  --endpoint-url https://han02.vstorage.vngcloud.vn

3. Download object

4. List objects in bucket

5. Delete object

Some advanced use cases

Copy directory from local to object storage:

Synchronize directory from local to object storage:

Get object metadata

Generate presigned URL for object

Enable bucket versioning

Config bucket policy

You need to create the appropriate bucket-policy.json file first. See here for more details.

For details of other features, please refer to https://docs.aws.amazon.com/cli/latest/userguide/cli-usage-commandstructure.html

Last updated