In this tutorial we are going to help you use the AWS Command Line Interface (CLI) to access Amazon S3. We will do this so you can easily build your own scripts for backing up your files to the cloud and easily retrieve them as needed. This will make automating your backup process faster, more reliable, and more programmatic. You can use this information to build a scheduled task (or cron job) to handle your backup operations.

Note: This tutorial builds upon the information from the Backing Up Your Files to Amazon S3 tutorial. If you haven't done that tutorial yet, you should complete that tutorial first.

Storing Your Files with AWS Requires an Account

Create a Free Account in Minutes

AWS Free Tier includes 5GB storage, 20,000 Get Requests, and 2,000 Put Requests with Amazon S3.

View AWS Free Tier Details »

 

a. Click here to open the AWS Identity and Access Management console. Click on Users on the left side.

Getting-Started-IAM1

(click to enlarge)

Getting-Started-IAM1

b. Click the Create New Users button.

Getting-Started-IAM2

(click to expand)

Getting-Started-IAM2

c. Enter a user name in the textbox next to 1. under Enter User Names: (we’ll use AWS_Admin for this example) and click the Create button.

Getting-Started-IAM3

(click to expand)

Getting-Started-IAM3

d. Click the Download Credentials button and save the credentials.csv file in a safe location (you’ll need this later in step 3) and then click the Close link.

Getting-Started-IAM4

(click to expand)

Getting-Started-IAM4

e. Click on the new AWS_Admin name in the User Name column.

Note: Click the name and not the checkbox

Getting-Started-IAM5

(click to expand)

Getting-Started-IAM5

f. Click on the Permissions tab and then click on the Attach Policy button.

Getting-Started-IAM6

(click to expand)

Getting-Started-IAM6

g. Select the check box next to AdministratorAccess and then click Attach Policy.

Getting-Started-IAM7

(click to expand)

Getting-Started-IAM7

Although creating login credentials isn’t required for the command line work in this tutorial, it is good security practice to never use your root account. Since we have set up this account as a full administrator of the AWS account, if you do select a password (and thus making the account able to log in) you can take the first step towards good security practices by starting to use this account instead of your root account. If you do not wish to set up a login password for this account you can skip to step 2.

h. Click the Security Credentials tab and then click the Manage Password button.

Getting-Started-IAM8

(click to expand)

Getting-Started-IAM8

i. Click the Apply button.

Getting-Started-IAM9

(click to expand)

Getting-Started-IAM9

j. Click the Download Credentials button and save the credentials.csv file in a safe location. Then click the Close link.

Note: Although the file you are downloading has the same name as the file you downloaded in step 1 part d, the files are different; this file contains the User Name and Password to log in to the AWS web console while the file in step 1 part d contains the Access Key Id and Secret Key used for the command line interface and for API-based access to AWS.

Getting-Started-IAM10

(click to expand)

Getting-Started-IAM10

Now that you have your IAM user, you need to install the AWS Command Line Interface (CLI). Below are instructions based on the kind of operating system you are using; please select the tab that corresponds to your operating system.

Select PC from the tabs below if you are using a Windows-based computer.

Select Mac/Linux from the tabs below if you are using a machine running OSX or Linux.

  • PC

    a. Download and run the Windows installer (64-bit, 32-bit).

    Note: users of Windows Server 2008 v6.0.6002 you will need to use a different install method listed here.


    b. Open a command prompt by pressing the Windows Key + r to open the run box and enter cmd and press the OK button.

    Getting-Started-S3-CLI-Run-Win

    (click to expand)

    Getting-Started-S3-CLI-Run-Win

    c. Type aws configure and press enter. Enter the following when prompted:

    AWS Access Key ID [None]: enter the Access Key Id from the credentials.csv file you downloaded in step 1 part d

    Note: this should look something like AKIAPWINCOKAO3U4FWTN

    AWS Secret Access Key [None]: enter the Secret Access Key from the credentials.csv file you downloaded in step 1 part d

    Note: this should look something like 5dqQFBaGuPNf5z7NhFrgou4V5JJNaWPy1XFzBfX3

    Default region name [None]: enter us-east-1

    Default output format [None]: enter json

    Getting-Started-S3-CLI-Config-Win

    (click to expand)

    Getting-Started-S3-CLI-Config-Win
  • Mac / Linux

    a. Follow these directions for installing the AWS CLI bundled installer.


    b. OSX users: Open a terminal window by pressing Command + Space and typing terminal in the search window. Then press enter to open the terminal window.

    Linux users: Open a terminal window.

    Getting-Started-CLI-OSX1

    (click to expand)

    Getting-Started-CLI-OSX1

    c. Type aws configure and press enter. Enter the following when prompted:

    AWS Access Key ID [None]: enter the Access Key Id from the credentials.csv file you downloaded in step 1 part d

    Note: this should look something like AKIAPWINCOKAO3U4FWTN

    AWS Secret Access Key [None]: enter the Secret Access Key from the credentials.csv file you downloaded in step 1 part d

    Note: this should look something like 5dqQFBaGuPNf5z7NhFrgou4V5JJNaWPy1XFzBfX3

    Default region name [None]: enter us-east-1

    Default output format [None]: enter json

    Getting-Started-CLI-Config-OSX

    (click to expand)

    Getting-Started-CLI-Config-OSX

a. Creating a bucket is optional if you already have a bucket created that you want to use. To create a new bucket named my-first-backup-bucket type aws s3 mb s3://my-first-backup-bucket

Note: bucket naming has some restrictions; one of those restrictions is that bucket names must be globally unique (e.g. two different AWS users can not have the same bucket name); because of this, if you try the command above you will get a BucketAlreadyExists error.

Getting-Started-S3-Create-Buscket-OSX

(click to expand)

Getting-Started-S3-Create-Buscket-OSX

b. To upload the file my-first-backup.bak located in the local directory to the S3 bucket my-first-backup-bucket, you would use the following command: aws s3 cp my-first-backup.bak s3://my-first-backup-bucket/

Getting-Started-S3-Upload-OSX

(click to enlarge)

Getting-Started-S3-Upload-OSX

c. To download my-first-backup.bak from S3 to the local directory we would reverse the order of the commands as follows: aws s3 cp s3://my-first-backup-bucket/my-first-backup.bak ./

Getting-Started-S3-Restore-OSX

(click to enlarge)

Getting-Started-S3-Restore-OSX

d. To delete my-first-backup.bak from your my-first-backup-bucket bucket, use the following command: aws s3 rm s3://my-first-backup-bucket/my-first-backup.bak

Getting-Started-S3-Delete-OSX

(click to enlarge)

Getting-Started-S3-Delete-OSX

Congratulations! You have set up an IAM user, configured your machine for use with the AWS command line interface and you have learned how to create, copy, retrieve, and delete files from the cloud. In the next tutorial you’ll learn how to set up a virtual tape drive for use in backing up file from an existing backup program like Veeam, Symantec Backup Exec, Microsoft System Center 2012 Data Protection Manager, or other back up programs.

Learn how to create a Virtual Tape Library and use it with your existing backup software »


Yes
No