Skip to content

Instantly share code, notes, and snippets.

@willwade
Forked from mattzuba/03_s3fs.config
Last active February 11, 2020 08:13
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save willwade/ad351d680428d4a3f090 to your computer and use it in GitHub Desktop.
Save willwade/ad351d680428d4a3f090 to your computer and use it in GitHub Desktop.
use s3fs for a node elasticbeanstalk app. Note the forked differences to the PHP one from @mattzuba - notably env vars are not available
packages:
yum:
gcc: []
libstdc++-devel: []
gcc-c++: []
fuse: []
fuse-devel: []
libcurl-devel: []
libxml2-devel: []
openssl-devel: []
mailcap: []
automake: []
sources:
/tmp: https://github.com/s3fs-fuse/s3fs-fuse/archive/v1.78.zip
files:
"/opt/elasticbeanstalk/bin/get_env_var":
mode: "000755"
owner: "root"
group: "root"
content: |
#!/usr/bin/python
import subprocess, json, sys
if len(sys.argv) < 2:
sys.exit('Usage: %s eb-env-key' % sys.argv[0])
else:
jsonstr = subprocess.check_output(['/opt/elasticbeanstalk/bin/get-config','environment'])
ekeys = json.loads(jsonstr)
print ekeys[sys.argv[1]]
"/etc/fuse.conf" :
mode: "000644"
owner: root
group: root
content: |
# mount_max = 1000
user_allow_other
"/opt/elasticbeanstalk/hooks/appdeploy/pre/11_unmount_s3fs.sh":
mode: "000755"
owner: root
group: root
content: |
#!/usr/bin/env bash
if mountpoint -q [/mnt/speechbubble-assets]; then
fusermount -u [/mnt/speechbubble-assets]
fi
"/opt/elasticbeanstalk/hooks/appdeploy/enact/02_mount_s3fs.sh":
mode: "000755"
owner: root
group: root
content: |
#!/usr/bin/env bash
export AWS_ACCESS_KEY_ID=`/opt/elasticbeanstalk/bin/get_env_var AWS_ACCESS_KEY_ID`
export AWS_SECRET_KEY=`/opt/elasticbeanstalk/bin/get_env_var AWS_SECRET_KEY`
# Make sure it's mounted as the nodejs user
uid=`id -u nodejs`
gid=`id -g nodejs`
s3fs speechbubble-assets /mnt/speechbubble-assets -o nonempty -o uid=$uid -o gid=$gid -o use_cache=/tmp -o allow_other -o default_acl=public-read
commands:
01_create_dir:
test: "[ ! -d /mnt/speechbubble-asset ]"
command: "mkdir -p /mnt/speechbubble-assets && chown nodejs:nodejs /mnt/speechbubble-assets"
02_patch_s3fs:
cwd: /tmp/s3fs-fuse-1.78/src
command: "sed -i 's/AWSACCESSKEYID/AWS_ACCESS_KEY_ID/g;s/AWSSECRETACCESSKEY/AWS_SECRET_KEY/g' s3fs.cpp"
03_install_s3fs:
cwd: /tmp/s3fs-fuse-1.78
test: "[ ! -x /usr/bin/s3fs ]"
command: "autoreconf --install && export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig && ./configure --prefix=/usr && make && make install"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment