Using AWS Command Line Interface[AWS-CLI] for accessing S3 bucket.

DATE POSTED: 06-10-2018

This was  simple manual solution and temporary way for  automation of  sending all your required  files to a remote backup.Immediate ways  to uploading and downloading the files to S3  become very easy by using AWS -CLI. Thus,here are the step by step manual for accessing a AWS-resource of S3  Bucket.

INSTALLATION:

STEP 1 – AWS CLI requires either Pyton 2.6.5+ or Python 3.3+ to be installed on the system. We can install Python with following command,

For ubuntu and debian based environment:

# sudo apt-get install python3   

For centOS and RHEL  based environment:
# sudo yum install python

For fedora based environment:

# dnf install python                                       

STEP 2 – We will using PIP to install the latest version of AWS CLI, though older version are available with default package managers but latest packages can only be installed using PIP. To install PIP on the system, execute the following command,

# curl -O https://bootstrap.pypa.io/get-pip.py

And  then execute,

#python get-pip.py

Once the script has been executed successfully, we can than run the following command to confirm the installed PIP version,

# pip –version

Installation of AWS CLI

The package manager to install AWS -CLI  in ubuntu / Debian based systems.

# sudo apt-get update awscli

The package manager to install AWS -CLI  in centos / RHEL based systems.

# sudo yum install awscli

But these are not the updated versions. For latest aws cli installation, run the following PIP command from the terminal,

#pip install awscli

To upgrade the aws cli to latest version,
#pip install awscli –upgrade

CONFIGURATION AND USAGE:

 AWS- configuration

Configuring the aws with your accurate access key id and and security key id. Then select your default region name and output format as  text /Jason  format.

-sh-4.2# aws configure

AWS Access Key ID [****************S4HA]: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

AWS Secret Access Key [****************eEeI]:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Default region name [us-east-2]: 

Default output format :

STEP 1: Make Bucket using AWScli

Mb[make bucket]

     -sh-4.2# aws s3 mb s3://python-py2

 Response: make_bucket: python-py2

STEP 2:Moving  a file to a bucket inside a folder using aws-cli

Here the ,

Bucket name: program-py

Directory inside bucket :py

File inside a directory: tests.txt

-sh-4.2# aws s3 cp ./tests.txt s3://program-py/py/

Response:upload: ./tests.txt to s3://program-py/py/tests.txt

 STEP 3:Remove Bucket using AWScli:

-sh-4.2# aws s3 rb s3://python-py-2

Response:remove_bucket failed: s3://python-py-2 An error occurred (NoSuchBucket) when calling the DeleteBucket operation: The specified bucket does not exist.

  • Remove Bucket giving a accurate name of Bucket:

-sh-4.2# aws s3 rb s3://python-py2

Response:remove_bucket: python-py2

STEP 4: listing the bucket of s3

-sh-4.2# aws s3 ls

2018-05-02 07:09:27  Backup 1

2018-05-01 10:58:56   backup 2

2018-10-03 07:35:29 program-py

STEP 5: synchronization with bucket-s3

Synchronizing (updating) local file system with the contents in the S3 bucket.

aws s3 sync s3://program-py

The object commands include aws s3 cp, aws s3 ls, aws s3 mv, aws s3 rm, and sync.The sync command synchronizes the contents of a bucket and a directory, or two buckets. Thus using sync for copying, moving  and sync needed the special permission ,

But  ,the cp, mv, and  sync commands include a  –grants option that can be used to grant permissions on the object to specified users or groups. You set the –grants option to a list of permissions using following syntax:

--grants Permission=Grantee_Type=Grantee_ID
         [Permission=Grantee_Type=Grantee_ID ...]

Permission – Specifies the granted permissions, and can be set to read, readacl, writeacl, or full.
• Grantee_Type – Specifies how the grantee is to be identified, and can be set to uri, emailaddress, or id.
• Grantee_ID – Specifies the grantee based on Grantee_Type.
o uri – The group’s URI. For more information,
o emailaddress – The account’s email address.
o id – The account’s canonical ID.

Accessing a s3 Bucket and managing the objects  by performing uploading , downloading, synchronization becomes more rapid and easy by using AWS-CLI commands.

Leave a Reply