Using the AWS Command Line Interface to access StorReduce

AWS Command Line Interface

The AWS Command Line Interface (CLI) is a command line tool for accessing AWS and compatible services. This makes it ideal for accessing StorReduce, because StorReduce has a faithful implementation of the Amazon S3 API.

To install the AWS CLI please follow the instructions on the AWS website. If you are on the StorReduce Virtual Appliance, or running Amazon Linux in EC-2 then it may already be installed.

Configuring a StorReduce Profile

The best way to use the AWS CLI with StorReduce is add a profile in the CLI configuration files. A profile is a set of settings that apply to a particular cloud endpoint. Doing this avoids messing up the AWS profile that you might use with AWS in the future. For this example, let’s call the profile “storreduce”.

The profile is stored in the ~/.aws directory on Unix, Linux and OS/X and in C:\Users\USERNAME\.aws\.

  1. Open the config file in the .awsAdd a line profile line at the end of the config file like this at the end of the file:

    [profile storreduce]

    Then save the file. You don’t need to set any variables at this time, you just have to name the profile.

  2. Open the credentials file in the same directory and add the following lines at the end of the file:

    aws_access_key_id = YOUR_STORREDUCE_ACCESS_KEY_ID
    aws_secret_access_key = YOUR_STORREDUCE_SECRET_ACCESS_KEY

    You can obtain the YOUR_STORREDUCE_ACCESS_KEY_ID and YOUR_STORREDUCE_SECRET_ACCESS_KEY and from the StorReduce dashboard. See the section “Create a key for a user” in the getting started guide.

  3. You can now test the CLI. When you run the aws command, you’ll need to specify the profile and the endpoint-url on the command line. E.g.,

    aws --profile=storreduce --endpoint-url=http://YOUR_STORREDUCE_SERVER s3 ls

    Where YOUR_STORREDUCE_SERVER is the domain name of your storreduce server. This must match the hostname configured in the StorReduce Servers Settings tab and it must be resolvable in DNS or a hosts file. This command should list the buckets in your StorReduce server.

If there is an error contacting the server, check that the access keys that you added in step 3 are correct (you can always issue another pair). If that doesn’t work check that that the hostname matches and that it resolvable.

Once you have listed the all the buckets you can try:

  • Listing a bucket:

    aws --profile=storreduce --endpoint-url=http://YOUR_STORREDUCE_SERVER s3 ls s3://BUCKET_NAME

    Note: This should all go on one line.

  • Copying a file into a bucket:

    aws --profile=storreduce --endpoint-url=http://YOUR_STORREDUCE_SERVER s3 cp FILE_NAME s3://BUCKET_NAME
  • Copying a file out of a bucket:

    aws --profile=storreduce --endpoint-url=http://YOUR_STORREDUCE_SERVER s3 cp s3://BUCKET_NAME/FILE_NAME FILE_NAME
  • Syncing a directory with a bucket:

    aws --profile=storreduce --endpoint-url=http://YOUR_STORREDUCE_SERVER s3 DIRECTORY_NAME s3://BUCKET_NAME

To save typing you can make a shell script like this:

exec aws --profile=storreduce --endpoint-url=http://YOUR_STORREDUCE_SERVER s3 "$@"

and save it as srcli and run it like this:

srcli ls

More Information