Amazon Simple Storage Service (Amazon S3) is an object storage service that offers industry-leading scalability, data availability, security, and performance.
In this guide we will see how to work with s3 from the terminal using awscli – aws
command.
Related content
- How to set up Minio as an Object Storage in Rocky Linux Server
- How to set CORS headers on your Amazon S3 bucket
- How to store Django Static and Media files in Amazon S3
- Script to Upload files to AWS S3 Using Golang
- Using AWS S3 Programatically with Python using Boto3 SDK
Installation
AWS Cli is provided as a python pip package. Install it wth this command:
sudo pip install -U aws-cli
Basic operations
Create bucket:
aws s3 mb s3://prod-ph-atlas-auth-certs --region ap-southeast-1
List content of bucket
aws s3 ls s3://bucket-name
Copy local file to bucket
aws s3 cp ~/tmp/account/account-kafka-client-truststore.jks s3://prod-ph-atlas-auth-certs/truststore/
Delete bucket
# Force if not empty
aws s3 rb s3://bucket-name --force
Sync two buckets
aws s3 sync s3://DOC-EXAMPLE-BUCKET-SOURCE s3://DOC-EXAMPLE-BUCKET-TARGET
Get bucket acl
aws s3api get-bucket-acl --bucket kip-revelapp-data
Put bucket policy
aws s3api put-bucket-policy --bucket kip-revelapp-data --policy file://files/s3-bucket-public-read-policy.json
Policy:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"s3:*"
],
"Resource": [
"arn:aws:s3:::kip-revelapp-data",
"arn:aws:s3:::kip-revelapp-data/*"
]
}
]
}