Mount an Amazon S3 bit bucket as a drive in unix using FUSE

You can put this in your startup scripts, but I just run mine when I want to upload files to S3 for content distribution or for backup. A couple of my backup scripts invoke this script, then umount fuse when they’re done backing things up to s3. It hasn’t fully been tested yet, but let me know how it works out. Remember to store your AWS credentials in a safe place where only trusted people can read them. It’s also a good idea to expire and rotate them frequently.

#!/bin/bash
# Asher Bond 2010
# http://www.asherbond.com/blog/2010/09/14/mount-an-amazon-s3-bit-bucket-as-a-drive-in-unix-using-fuse/
#
# USAGE: s3-mount.sh bucket-name [/mnt/point/optional/if/different]
# 
# mount s3 using s3-simple-fuse
# This is released under GPL
# you might need to:
# See http://code.google.com/p/s3-simple-fuse/ for s3-simple-fuse
# apt-get install python-fuse
# apt-get install python-dateutil
# apt-get install python-boto


# if you don't specify a mount point it just assumes /mnt/bit-bucket-name
function s3-mount ()
{


        if [ "$#" == 1 ] ; then
                # allow for custom /mnt/points
                mnt="/mnt/$1"
        else    mnt="$2"
        fi

        # keep this safe
        aws_access_key_id='AKUIAS7YOURMOM8XUTA4GA'
        aws_secret_access_key='sa09idontask2hsdfkjh34tnotrealna5p8'

        mkdir $mnt
        s3-simple-fuse $mnt -o AWS_ACCESS_KEY_ID=$aws_access_key_id,AWS_SECRET_ACCESS_KEY=$aws_secret_access_key,bucket=$1

}


s3-mount $1 $2


# to-do: mount google storage
# http://code.google.com/apis/storage/
#function google-storage-mount ()
#{
#}
Tagged with: , , , , , , , ,
Posted in cloud computing, designing scalable systems
7 comments on “Mount an Amazon S3 bit bucket as a drive in unix using FUSE
  1. Indian DJ says:

    Thats a really wonderful post with necessary Facts. Thank you for your help.

  2. Schedule says:

    Maybe you should edit the blog name Mount an Amazon S3 bit bucket as a drive in unix using FUSE. I liked the blog post still.

  3. jacob says:

    I get a error with your script
    s3-mount.sh: 16: Syntax error: “(” unexpected

  4. Asher Bond says:

    Jacob, have you copied the script from the “view pane” window? Sometimes the “copy to clipboard” feature is in conflict with certain browsers. I just ran the script from “view pane” and copied and pasted it and did not find an error on line 16. Line 16 should say:
    function s3-mount ()

    and that’s all. maybe the line break is awkward?

    Let me know if you need any more help. Thanks. [:

  5. jacob says:

    yes you are right I try now with firefox and the now is working. Nice script

  6. TntDrive says:

    Under windows you may use TntDrive to mount Amazon S3 Buckets as a Local Drive or Network Drive.

  7. Paul says:

    How do you specify the bucket name in this script?