AWS

Using AWS S3 from the terminal with awscli

Pinterest LinkedIn Tumblr

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.

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/*"
            ]
        }
    ]
}

I am a Devops Engineer, but I would describe myself as a Tech Enthusiast who is a fan of Open Source, Linux, Automations, Cloud and Virtualization. I love learning and exploring new things so I blog in my free time about Devops related stuff, Linux, Automations and Open Source software. I can also code in Python and Golang.

Write A Comment