Amazon Elastic Beanstalk Ebextension – Come installare s3fs

In questo articolo vedremo come configurare una webapp su Amazon Elastic BeanStalk per installare il comando s3fs, che come certamente saprete è utile per montare su filesystem linux i bucket S3.

amazon-web-services

 

 

 

 

Il seguente script inserito dentro la directory ebextensions nella root della webapp consente di installare il pacchetto s3fs, e quindi di montare sul filesystem dei sistemi operativi linux un bucket S3. Lo script ha alcune configurazioni da customizzare, come ad esempio i valodi di amazon.accesskey e amazon.secretkey, che dovranno essere utilizzati per generare il file di confgurazione di s3fs, e la directory di mount che verrà creata sotto /mnt/. Ricordo che gli script di configurazione vanno formattati secondo le regole di YAML

Lo script di configurazione è il seguente:

 

packages:
yum:
gcc: []
libstdc++-devel: []
gcc-c++: []
fuse: []
fuse-devel: []
curl: []
curl*: []
libcurl-devel: []
libxml2: []
libxml2*: []
libxml2-devel: []
openssl-devel: []
 
  sources:
/home/ec2-user: http://s3fs.googlecode.com/files/s3fs-1.61.tar.gz
 
files:
“/root/install_s3fs.sh” :
mode: “000700”
owner: root
group: root
content: |
#!/bin/bash
  #
# s3fs install script for Elastic Beanstalk instances
#  INSTALL_LOG_FILE=/root/installs3fs.log
STARTON=$(date +’%Y-%m-%d %H:%M:%S’)
  echo Starting at $STARTON > $INSTALL_LOG_FILE
if [ ! -f /usr/bin/s3fs ]
then
#installing s3fs
echo ‘installing s3fs’ >> $INSTALL_LOG_FILE
cd /home/ec2-user/s3fs-1.61/
./configure –prefix=/usr
make
make install
else
echo ‘s3fs bin already exists, nothing to do’ >> $INSTALL_LOG_FILE
fi
  #generate s3fs configuration file with keys
echo ‘generate s3fs configuration’ >> $INSTALL_LOG_FILE
touch /etc/.passwd-s3fs
chmod 600 /etc/.passwd-s3fs
echo ‘@amazon.accesskey@:@amazon.secretkey@’ > /etc/.passwd-s3fs
  #create s3 mount directory
if [ ! -d /mnt/s3mount ]
then
echo creating mount directory >> $INSTALL_LOG_FILE
mkdir /mnt/s3mount
fi
 
 commands:
start-s3sf-setup:
command: ./install_s3fs.sh
cwd: /root/

 

Una volta installato, il comando sarà immediatamente utilizzabile per poter montare un bucket S3.

 

 

Lascia un commento