Skip to content

S3cmd Configuration

UENISHI Kota edited this page Feb 12, 2016 · 12 revisions

s3cmd uses a configuration file .s3cfg which should be located in the user's home directory. Running s3cmd --configure launches an interactive tool to generate a configuration. Here are a couple of sample .s3cfg files that can be used to configure s3cmd to interact with Riak CS.

Sample .s3cfg file to interact with Riak CS locally via port 8080

[default]
access_key = 8QON4KC7BMAYYBCEX5J+
bucket_location = US
cloudfront_host = cloudfront.amazonaws.com
cloudfront_resource = /2010-07-15/distribution
default_mime_type = binary/octet-stream
delete_removed = False
dry_run = False
enable_multipart = False
encoding = UTF-8
encrypt = False
follow_symlinks = False
force = False
get_continue = False
gpg_command = /usr/local/bin/gpg
gpg_decrypt = %(gpg_command)s -d --verbose --no-use-agent --batch --yes --passphrase-fd %(passphrase_fd)s -o %(output_file)s %(input_file)s
gpg_encrypt = %(gpg_command)s -c --verbose --no-use-agent --batch --yes --passphrase-fd %(passphrase_fd)s -o %(output_file)s %(input_file)s
gpg_passphrase = password
guess_mime_type = True
host_base = s3.amazonaws.com
host_bucket = %(bucket)s.s3.amazonaws.com
human_readable_sizes = False
list_md5 = False
log_target_prefix =
preserve_attrs = True
progress_meter = True
proxy_host = localhost
proxy_port = 8080
recursive = False
recv_chunk = 4096
reduced_redundancy = False
secret_key = rGyDLBi7clBuvrdrkFA6mAJkwJ3ApUVr4Pr9Aw==
send_chunk = 4096
simpledb_host = sdb.amazonaws.com
skip_existing = False
socket_timeout = 300
urlencoding_mode = normal
use_https = False
verbosity = WARNING
signature_v2=True

Script to create a Riak CS user account and output an .s3cfg file with access_key and secret_key populated

#!/bin/sh

usage()
{
    echo "$0 USERNAME EMAIL [HOST PORT]"
}

if [ -z "$1" ]
  then
    usage
    exit
fi
if [ -z "$2" ]
  then
    usage
    exit
fi
if [ -z "$3" ]
  then
    HOST="localhost"
else
      HOST=$3
fi
if [ -z "$4" ]
  then
    PORT=8080
else
    PORT=$4
fi

PARSECREDS="import json
import sys
user_input = sys.stdin.read()
user_json = json.loads(user_input)
sys.stdout.write(user_json['key_id'] + ' ' + user_json['key_secret'] + ' ' + user_json['id'])
sys.stdout.flush()"

CREDS=`curl -s --data "{\"email\":\"$2\", \"name\":\"$1\"}" -H 'Content-Type: application/json' "http://$HOST:$PORT/riak-cs/user" | python -c "$PARSECREDS"`
KEYID=`echo $CREDS | awk '{print $1}'`
KEYSECRET=`echo $CREDS | awk '{print $2}'`
CANONICALID=`echo $CREDS | awk '{print $3}'`

CONFIG="[default]
#canonical_id=$CANONICALID
access_key = $KEYID
secret_key = $KEYSECRET
bucket_location = US
cloudfront_host = cloudfront.amazonaws.com
cloudfront_resource = /2010-07-15/distribution
default_mime_type = binary/octet-stream
delete_removed = False
dry_run = False
encoding = UTF-8
encrypt = False
follow_symlinks = False
force = False
get_continue = False
gpg_command = /usr/local/bin/gpg
gpg_decrypt = %(gpg_command)s -d --verbose --no-use-agent --batch --yes --passphrase-fd %(passphrase_fd)s -o %(output_file)s %(input_file)s
gpg_encrypt = %(gpg_command)s -c --verbose --no-use-agent --batch --yes --passphrase-fd %(passphrase_fd)s -o %(output_file)s %(input_file)s
gpg_passphrase = password
guess_mime_type = True
host_base = s3.amazonaws.com
host_bucket = %(bucket)s.s3.amazonaws.com
human_readable_sizes = False
list_md5 = False
log_target_prefix =
preserve_attrs = True
progress_meter = True
proxy_host = $HOST
proxy_port = $PORT
recursive = False
recv_chunk = 4096
reduced_redundancy = False
send_chunk = 4096
simpledb_host = sdb.amazonaws.com
skip_existing = False
socket_timeout = 300
urlencoding_mode = normal
use_https = False
verbosity = WARNING
signature_v2=True"

echo "$CONFIG"