Reputation: 10290
I know that I can host a static website on S3, but can this be done with AWS EFS? Is it even recommended?
Upvotes: 0
Views: 1879
Reputation: 2143
I have this setup currently using Elastic Beanstalk. All I have is a .ebextensions folder with two scripts:
01-umount-efs.config
commands:
01_mount:
command: umount /var/app/current/efs || /bin/true
02_mount:
command: umount -l /var/app/current/efs || /bin/true
02-mount-efs.config
# Mount
commands:
create_post_dir:
command: "mkdir -p /opt/elasticbeanstalk/hooks/appdeploy/post"
ignoreErrors: true
do_something:
command: "/sbin/service httpd restart"
files:
"/opt/elasticbeanstalk/hooks/appdeploy/post/99_mount_efs.sh":
mode: "000755"
content : |
#!/bin/bash
EC2_REGION="ap-southeast-2"
EFS_MOUNT_DIR=/var/app/current/efs
EFS_FILE_SYSTEM_ID=fs-xxxxxxxx
EC2_ZONE=$(curl -s http://169.254.169.254/latest/meta-data/placement/availability-zone)
echo "Mounting EFS filesystem ${EFS_DNS_NAME} to directory ${EFS_MOUNT_DIR} ..."
echo "Region is ${EC2_REGION}"
echo 'Stopping NFS ID Mapper...'
service rpcidmapd status &> /dev/null
if [ $? -ne 0 ] ; then
echo 'rpc.idmapd is already stopped!'
else
service rpcidmapd stop
if [ $? -ne 0 ] ; then
echo 'ERROR: Failed to stop NFS ID Mapper!'
exit 1
fi
fi
echo 'Checking if EFS mount directory exists...'
if [ ! -d ${EFS_MOUNT_DIR} ]; then
echo "Creating directory ${EFS_MOUNT_DIR} ..."
mkdir -p ${EFS_MOUNT_DIR}
if [ $? -ne 0 ]; then
echo 'ERROR: Directory creation failed!'
exit 1
fi
chmod 777 ${EFS_MOUNT_DIR}
if [ $? -ne 0 ]; then
echo 'ERROR: Permission update failed!'
exit 1
fi
else
echo "Directory ${EFS_MOUNT_DIR} already exists!"
fi
mountpoint -q ${EFS_MOUNT_DIR}
if [ $? -ne 0 ]; then
echo "mount -t nfs4 -o nfsvers=4.1 ${EC2_ZONE}.${EFS_FILE_SYSTEM_ID}.efs.${EC2_REGION}.amazonaws.com:/ ${EFS_MOUNT_DIR}"
mount -t nfs4 -o nfsvers=4.1 ${EC2_ZONE}.${EFS_FILE_SYSTEM_ID}.efs.${EC2_REGION}.amazonaws.com:/ ${EFS_MOUNT_DIR}
if [ $? -ne 0 ] ; then
echo 'ERROR: Mount command failed!'
exit 1
fi
else
echo "Directory ${EFS_MOUNT_DIR} is already a valid mountpoint!"
fi
echo 'EFS mount complete.'
Just need to change ap-southeast-2 (EC2_REGION) and fs-xxxxxxxx (EFS_FILE_SYSTEM_ID).
Then in your Beanstalk Configuration > Software set the Document Root to /efs
You can also setup FTP access to the EFS by going through the EC2 instance:
Example FTP settings
{
"type": "sftp",
"host": "ec2-XX-XX-XXX-XX.ap-southeast-2.compute.amazonaws.com",
"user": "ec2-user",
"port": "22",
"remote_path": "/var/app/current/efs/",
"connect_timeout": 30,
"ftp_passive_mode": true,
"ssh_key_file": "C:/Path/To/KeyFile/ec2-access.ppk",
"remote_time_offset_in_hours": 10,
}
Note: Your "host" can change because you are using Elastic Beanstalk and instances spin up and down all the time. So far I have not found an easier way to access the files on an EFS.
Upvotes: 0
Reputation: 3404
It can be done but I would not recommend it due to pricing and performance. EFS is currently $0.30/GB and S3 is $0.03/GB per month. Also, serving from EFS requires one or more running EC2 instances. I don't know of any benchmarks but I fully expect S3 to also offer better performance since S3 scales automatically.
Upvotes: 1
Reputation: 14523
EFS is Elastic File System. Basically EFS is a volume that can be attached to multiple instances and very helpful in case of autoscaling.
But basic function of EFS is volume, so off course you can host a website on a EC2 instance using EFS as the volume. The issue is with pricing as EFS is costlier then EBS.
And also hosting a static website on S3 is easy as you have to just upload the files to the bucket. In case of EFS you will need a EC2 instance and then you will mount the EFS to the EC2 instance and then setup the web server for the website and then serve the website. So it is too much work for hosting a static website using EFS.
So I will recommend S3.
Upvotes: 3