Yet another script to mount an AWS S3 bucket in Linux

Screenplay

Screenplay (Photo credit: Matt-Richards)

This was a script written by Alex Brooks who gave me permission to use the base script and change it along the way. Mounting a bucket in S3 on a linux box can be a tricky issue, especially when it does not want to set the permissions to the bucket right so that the average web server can use it. While the integrated person management system is awesome, sometimes you need to set up your bucket manually and latch onto it manually. Unfortunately while this is stupid easy in Windows, in Linux it can be a bit of a chore.

 

To Mount the Bucket at the command line one time until reboot usage

s3fs -o passwd_file=passwd-s3fs bucket_name mount_point

Or you can mount the bucket as a script so that if the box gets rebooted you don’t need to worry as much about running through your system to rebuild the links to the S3 bucket. First you set the permissions, and this is set as a read only bucket for the owner of the service/process, 700. You will want to change the permissions over to something closer to 744 or 755 depending on what you need to do with the objects. If the objects are meant to be writable, then it has to be set to 777, so there is some risk here if you set your mount point to be 777.

s3setup.sh:

#!/bin/bash

#

# script to set up an ubuntu 12.04 AMI with s3 support

#

# includes the key for cloud computing class

#

sudo aptitude install build-essential libxml2-dev libfuse-dev libcurl4-openssl-dev automake subversion

cd ~

svn checkout http://s3fs.googlecode.com/svn/trunk s3fs-read-only

cd s3fs-read-only

./autogen.sh

./configure

make

sudo make install

cd ~

touch passwd-s3fs && chmod 700 passwd-s3fs && echo ‘your AWS key’ > passwd-s3fs

# end script

And then mount that S3 Bucket

s3mount.sh:

#!/bin/bash

#

# s3 bucket mount script

#

# ./s3mount.sh bucket_name mount_point

#

s3fs -o passwd_file=passwd-s3fs $1 $2

# end script

If you want to change the whole bucket to public read, use this to mount to the S3 bucket

#!/bin/bash

#

# s3 bucket mount script

#

# ./s3mount.sh bucket_name mount_point

#

s3fs -o passwd_file=passwd-s3fs -o allow_other -o default_acl=”public-read” $1 $2

# end script

Kinda cool, and interesting, let me know if you have any problems with these scripts.

Enhanced by Zemanta


, , , , , , ,

This entry was posted on October 9, 2012 and is filed under Technology. Written by: . You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.