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.
b. Click the Create New Users button.
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.
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.
e. Click on the new AWS_Admin name in the User Name column.
Note: Click the name and not the checkbox
f. Click on the Permissions tab and then click on the Attach Policy button.
g. Select the check box next to AdministratorAccess and then click Attach Policy.
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.
i. Click the Apply button.
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.
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.
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.
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/
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 ./
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
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.