I recently wrote a bash script that automates a database backups to zipped files on a Raspberry Pi. I would then periodically SSH in and transfer the backup files.
This package provides a unified command line interface to Amazon Web Services. Getting Started. This README is for the AWS CLI version 1. If you are looking for information about the AWS CLI version 2, please visit the v2 branch. Learn how to install AWS CLI on Ubuntu 20.04. It is an open-source command-line utility tool for managing Amazon web services.
This was a simple temporarily and manual solution, but I wanted a way to automate sending these files to a remote backup. I use AWS quite often, so my immediate plan was to transfer the files to S3 (Amazon’s simply storage platform). I found that Amazon has a very nifty command-line tool for AWS including S3.
Aws Command Line Tools Mac
Using AWS command line tool (AWS cli), you can manage most of the AWS resources. Firstly, for Auto Scaling we must install some command-line tools. This is done to minimize your usage of billable services. The Amazon EC2 command-line interface tools (also called the EC2 CLI tools) wrap the Amazon EC2 API actions. These tools are written in Java and include shell scripts for both Windows and Linux, OS X, or Unix. The Amazon Web Services (AWS) command line tool is a full-featured alternative to using the AWS console to perform actions in your account. Getting started is dead simple.
Here are my notes…
Installation
The platform I’m demonstrating with is Raspbian Jessie. This should be much the same for other Debian-based Linux distros, like Ubuntu.
Install Python PIP
Install AWS CLI
This will take a little while to complete.
Documentation: http://docs.aws.amazon.com/cli/latest/userguide/installing.html
Add aws command to the PATH variable
This is for convenience and means we can access the aws command anywhere in the terminal.
Documentation: http://docs.aws.amazon.com/cli/latest/userguide/awscli-install-linux.html#awscli-install-linux-path
Check installation
Configuration
You will need to create a user on your AWS account and carefully configure it’s permissions and policies. I won’t cover this in detail, but the basics steps are:
- Log in the the AWS console web site.
- Go to the IAM Management Console > Users > Add user
- Type in a user name and select Programmatic access to get an access key ID and secret access key, instead of a password.
- Set up the user’s permissions.
- Apply the user credentials to AWS CLI on the Linux machine.
In my situation, I’m using this for remote backups, so I restricted the user to a single S3 Bucket (‘my-bucket’ in this example), and only list and upload permissions, but not delete.
Here’s my custom policy JSON:
Make sure to keep the provided ID and key safe and secure. We’ll use this next. Note: The credentials displayed in my examples are fake! 😉
Back on the Linux machine, we’ll configure aws with our new user credentials:
That’s it! You should be ready to go 🙂
Example S3 operations
Here are a few basic examples on how to access S3 using command line.
List the contents of an S3 bucket
Aws Command Line Tools Configure
List the contents of an S3 bucket directory
Upload a file to S3
Aws Command Line Tools Mac
Delete a file from S3
Aws Command Line Tools Kinesis
Note: I received an access denied message because my user should not be allowed to delete files.