S3 - AWS Cli
Install
Install with Python pip:
Install with AWS script:
# Download installer
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
# Unzip + Start install script
unzip awscliv2.zip
sudo ./aws/install
# Remove files
rm -rf awscliv2.zip aws
Configuration
Start configuration with CLI:
Example of configuration:
# ~/.aws/config
[ceph4]
output = json
region = paris
# ~/.aws/credentials
[ceph4]
aws_access_key_id = XXXXXXXXXXXXX
aws_secret_access_key = XXXXXXXXXXXXXXXXXXXXXX
Commands
S3 CLI
List bucket:
aws s3 \
(--profile {profile}) \
(--endpoint-url {s3-url}) \
ls s3://{bucket}
# Ex:
# aws s3 --endpoint-url https://s3.plop.com ls s3://plopy-bucks
Create bucket:
aws s3 \
(--profile {profile}) \
(--endpoint-url {s3-url}) \
mb s3://{bucket}
# Ex:
# aws s3 --endpoint-url https://s3.plop.com mb s3://new-plopy-bucks
Copy file:
aws s3 \
(--profile {profile}) \
(--endpoint-url {s3-url}) \
cp {file} s3://{bucket}/{file}
# Ex:
# aws s3 --endpoint-url https://s3.plop.com cp file.txt s3://plopy-bucks/file.txt
Delete file:
aws s3 \
(--profile {profile}) \
(--endpoint-url {s3-url}) \
rm (--recursive) s3://{bucket}/{file}
# Ex:
# aws s3 --endpoint-url https://s3.plop.com rm s3://plopy-bucks/file.txt
Set html index/error file to use bucket as website:
aws s3 website \
(--profile {profile}) \
(--endpoint-url {s3-url}) \
--index-document {html-index-file} \
--error-document {html-error-file} s3://{bucket}
# Ex:
# aws s3 website s3://my-bucket/ --index-document index.html --error-document error.html
S3 API
Create bucket:
aws s3api create-bucket \
(--profile {profile}) \
(--endpoint-url {s3-url}) \
--bucket {bucket} \
(--create-bucket-configuration LocationConstraint={zone})
Set object to Public:
aws s3api put-object-acl \
(--profile {profile}) \
(--endpoint-url {s3-url}) \
--bucket {bucket} \
--key {object} \
--acl public-read
Set bucket to Public:
aws s3api put-bucket-acl \
(--profile {profile}) \
(--endpoint-url {s3-url}) \
--bucket {bucket} \
--acl public-read
Get bucket ACL:
Link
- https://docs.aws.amazon.com/cli/latest/reference/