{"id":11440,"date":"2014-01-27T13:00:49","date_gmt":"2014-01-27T07:30:49","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=11440"},"modified":"2016-12-19T15:07:29","modified_gmt":"2016-12-19T09:37:29","slug":"mounting-s3-bucket-into-an-ec2-instance","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/mounting-s3-bucket-into-an-ec2-instance\/","title":{"rendered":"Mounting S3 bucket into an EC2 instance"},"content":{"rendered":"<p>One of our clients has hosted his application on AWS and it uses EC2 instances behind the load balancer. The application provides an interface where users are suppose to upload files. For saving the same on centralize location we use S3 bucket and mount the same on the EC2 instances. Following are the step which we follow to get the things working:<\/p>\n<p><strong>Prerequisite\u00a0<\/strong>: First we execute the following command, which will install the required packages necessary to install S3fs command.<\/p>\n<p><strong>Debian:<\/strong><\/p>\n<div>[shell]sudo apt-get install make gcc g++ pkg-config libfuse-dev libcurl4-openssl-dev libxml2-dev[\/shell]<\/p>\n<\/div>\n<div>\n<p><strong>Amazon AMI:<\/strong><\/p>\n<p>[shell]yum\u00a0remove\u00a0fuse\u00a0fuse*fuse-devel<br \/>\nyum\u00a0install\u00a0gcc libstdc++-devel gcc-c++\u00a0curl-devel libxml2-devel openssl-devel mailcap fuse fuse-devel[\/shell]<\/p>\n<p>Now we download the S3fs code, untar it and install it by using following command:<\/p>\n<\/div>\n<div>[shell]cd \/opt<br \/>\nwget<br \/>\ntar xzvf s3fs-1.71.tar.gz<br \/>\ncd\u00a0s3fs-1.71\/<br \/>\n.\/configure<br \/>\nmake<br \/>\nmake install [\/shell]<\/p>\n<\/div>\n<div><\/div>\n<div>The above command will build and \u00a0install the S3fs.<\/div>\n<div><\/div>\n<div>In the next step we will create a file which stores the access key and secret key of our account (you can find the same under\u00a0<strong>AWS Menu -&gt; Your Account -&gt; Security Credentials)<\/strong>.<\/div>\n<div><\/div>\n<div>[shell]vim \/etc\/passwd-s3fs[\/shell]<\/p>\n<p>Now we will store our secret key and access key like following:<\/p>\n<p>[shell]chmod 640 \/etc\/passwd-s3fs[\/shell]<\/p>\n<\/div>\n<div><\/div>\n<div>Now we will set the<span style=\"font-size: small;\"><span style=\"line-height: 19px;\">\u00a0<em><strong>a<\/strong><\/em><\/span><\/span><em><strong>llow_other mount<\/strong><\/em>\u00a0option so even if we are mounting the bucket using non root account, they can have permission to use<span style=\"font-size: small;\"><span style=\"line-height: 19px;\">\u00a0<\/span><\/span><em><strong>allow_other<\/strong><\/em>\u00a0option.<\/div>\n<div><\/div>\n<div>For this (to uncomment\u00a0<em><strong>user_allow_other<\/strong><\/em>\u00a0in fuse configuration file), we will execute the following command,<\/div>\n<div><\/div>\n<div>[shell]sed -ie &#8216;s\/#user_allow_other\/user_allow_other\/g&#8217; \/etc\/fuse.conf[\/shell]<\/p>\n<\/div>\n<div><\/div>\n<div>Now we will create a directory where we want to mount our S3 bucket,<\/div>\n<p>[shell]mkdir \/var\/www\/uploads[\/shell]<\/p>\n<div>Now we can mount our bucket by running the below mentioned command:<\/div>\n<div><\/div>\n<div>[shell]s3fs &lt;bucketname&gt; -o use_cache -o allow_other \/var\/www\/uploads[\/shell]<\/p>\n<\/div>\n<div><\/div>\n<div>Now if above provided credentials are right and the bucket exists, it will mount the bucket on <strong><em>\/var\/www\/uploads<\/em><\/strong> folder.<\/div>\n<div><\/div>\n<div>To check the same we can use the\u00a0mount -l\u00a0command and look for <em><strong>\/var\/www\/uploads<\/strong><\/em> .<\/div>\n<div><\/div>\n<div>I hope this blog was helpful for you in\u00a0Mounting S3 bucket to EC2 instance.<\/div>\n","protected":false},"excerpt":{"rendered":"<p>One of our clients has hosted his application on AWS and it uses EC2 instances behind the load balancer. The application provides an interface where users are suppose to upload files. For saving the same on centralize location we use S3 bucket and mount the same on the EC2 instances. Following are the step which [&hellip;]<\/p>\n","protected":false},"author":90,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":3},"categories":[1174],"tags":[1281,1283,1282,1284],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/11440"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/90"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=11440"}],"version-history":[{"count":0,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/11440\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=11440"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=11440"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=11440"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}