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.vn2. Upload object
Example 1:
aws s3 cp ./local-file.txt s3://demoawscli-bucket/file.txt \
--profile han02-prod \
--endpoint-url https://han02.vstorage.vngcloud.vnExample 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.vn3. Download object
aws s3 cp s3://demoawscli-bucket/file.txt ./downloaded.txt \
--profile han02-prod \
--endpoint-url https://han02.vstorage.vngcloud.vn4. List objects in bucket
aws s3 ls s3://demoawscli-bucket/ \
--recursive \
--profile han02-prod \
--endpoint-url https://han02.vstorage.vngcloud.vn5. Delete object
aws s3 rm s3://demoawscli-bucket/file.txt \
--profile han02-prod \
--endpoint-url https://han02.vstorage.vngcloud.vnSome advanced use cases
Copy directory from local to object storage:
aws s3 cp ./my-folder/ s3://demoawscli-bucket/my-folder/ \
--recursive \
--profile han02-prod \
--endpoint-url https://han02.vstorage.vngcloud.vnSynchronize directory from local to object storage:
aws s3 sync ./local-folder/ s3://demoawscli-bucket/backup/ \
--profile han02-prod \
--endpoint-url https://han02.vstorage.vngcloud.vnGet object metadata
aws s3api head-object \
--bucket demoawscli-bucket \
--key my-folder/randomfile_1.txt \
--profile han02-prod \
--endpoint-url https://han02.vstorage.vngcloud.vnGenerate presigned URL for object
aws s3 presign s3://demoawscli-bucket/my-folder/randomfile_1.txt \
--expires-in 3600 \
--profile han02-prod \
--endpoint-url https://han02.vstorage.vngcloud.vnEnable bucket versioning
aws s3api put-bucket-versioning \
--bucket demoawscli-bucket \
--versioning-configuration Status=Enabled \
--profile han02-prod \
--endpoint-url https://han02.vstorage.vngcloud.vnConfig bucket policy
aws s3api put-bucket-policy \
--bucket demoawscli-bucket \
--policy file://bucket-policy.json \
--profile han02-prod \
--endpoint-url https://han02.vstorage.vngcloud.vnYou need to create the appropriate
bucket-policy.jsonfile 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
