<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>The Ops Community ⚙️: Denys Bochko</title>
    <description>The latest articles on The Ops Community ⚙️ by Denys Bochko (@denysbochko).</description>
    <link>https://community.ops.io/denysbochko</link>
    <image>
      <url>https://community.ops.io/images/a_L5_J0SgnXFKrCiPXqZosXIq6byn0y1CfU-vi5dwsU/rs:fill:90:90/g:sm/mb:500000/ar:1/aHR0cHM6Ly9jb21t/dW5pdHkub3BzLmlv/L3JlbW90ZWltYWdl/cy91cGxvYWRzL3Vz/ZXIvcHJvZmlsZV9p/bWFnZS8xMDEvNTEx/OTA2ZDEtNDY3YS00/NGM0LWI5ZDgtY2Q1/NzczYmM1ZGM2Lmpw/Zw</url>
      <title>The Ops Community ⚙️: Denys Bochko</title>
      <link>https://community.ops.io/denysbochko</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://community.ops.io/feed/denysbochko"/>
    <language>en</language>
    <item>
      <title>Mount S3 bucket to EC2 with IAM policy - step by step</title>
      <dc:creator>Denys Bochko</dc:creator>
      <pubDate>Wed, 25 May 2022 19:18:15 +0000</pubDate>
      <link>https://community.ops.io/denysbochko/mount-s3-bucket-to-ec2-with-iam-policy-step-by-step-42jp</link>
      <guid>https://community.ops.io/denysbochko/mount-s3-bucket-to-ec2-with-iam-policy-step-by-step-42jp</guid>
      <description>&lt;p&gt;I had to go through that process recently and I wanted to share what I had to do to accomplish that. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Prerequisite&lt;/strong&gt;: ready and running EC2 instance and an S3 bucket has been created.&lt;/p&gt;

&lt;h2&gt;
  
  
  Install s3fs (S3 files system)
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Update the system&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo yum update
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Install dependencies&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo yum install automake fuse \
fuse-devel gcc-c++ git libcurl-devel \
libxml2-devel make openssl-devel
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Download s3fs code from the source&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git clone https://github.com/s3fs-fuse/s3fs-fuse.git
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Install it&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# cd s3fs-fuse\r\n# ./autogen.sh
# ./configure — prefix=/usr — with-openssl
# make 
# sudo make install
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Make sure it is installed properly&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;which s3fs
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will give you the location of its binaries&lt;/p&gt;

&lt;h2&gt;
  
  
  IAM policy and role.
&lt;/h2&gt;

&lt;p&gt;We need to create a policy that will give EC2 access to that S3 bucket and then we will assign that policy to a role that will be assigned to our EC2 instance.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Create an IAM policy&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This is the JSON of the policy. You can modify it to your needs, this particular policy only needs to manage to read/write/delete files into that bucket.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "VisualEditor0",
            "Effect": "Allow",
            "Action": [
                "s3:PutObject",
                "s3:GetObject",
                "s3:ListBucket",
                "s3:DeleteObject"
            ],
            "Resource": [
                "arn:aws:s3:::&amp;lt;your_bucket_here&amp;gt;/*",
                "arn:aws:s3:::&amp;lt;your_bucket_here&amp;gt;"
            ]
        }
    ]
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Save the policy.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Create IAM role&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Now we need to create a role based on that polity. Head to roles in IAM and click on "Create".&lt;/p&gt;

&lt;p&gt;Select "AWS service" and EC2 under "Use case"&lt;/p&gt;

&lt;p&gt;&lt;a href="https://community.ops.io/images/kUb7MEtGhXnzjFXRhD0mF-pPrVA1KwRvyutaN-HFRZI/w:880/mb:500000/ar:1/aHR0cHM6Ly9kZXYt/dG8tdXBsb2Fkcy5z/My5hbWF6b25hd3Mu/Y29tL3VwbG9hZHMv/YXJ0aWNsZXMvZTNy/aHo2N3FhMXNhZ3Nk/emd5enAucG5n" class="article-body-image-wrapper"&gt;&lt;img src="https://community.ops.io/images/kUb7MEtGhXnzjFXRhD0mF-pPrVA1KwRvyutaN-HFRZI/w:880/mb:500000/ar:1/aHR0cHM6Ly9kZXYt/dG8tdXBsb2Fkcy5z/My5hbWF6b25hd3Mu/Y29tL3VwbG9hZHMv/YXJ0aWNsZXMvZTNy/aHo2N3FhMXNhZ3Nk/emd5enAucG5n" alt="IAm role setup" width="880" height="981"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;On the next screen select the policy you just created.&lt;/p&gt;

&lt;p&gt;Hit "Next" will bring you to the next screen where you name the role and create its description. &lt;/p&gt;

&lt;p&gt;Hit "Create role" and you are done.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Assign that role to your EC2 instance.&lt;/strong&gt;&lt;br&gt;
&lt;em&gt;NOTE: the location specified is as of May 13, 2022, AWS UI can change&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;All the way to EC2 section, select your EC2 instance and under "Actions" which is on the top right select "Security"-&amp;gt; Modify IAM role.&lt;/p&gt;

&lt;p&gt;That will lead to another page to select the role you just created and assign it to your EC2.&lt;/p&gt;

&lt;p&gt;Ok, we are done here.&lt;/p&gt;
&lt;h2&gt;
  
  
  The mounting
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Create a mounting point.&lt;/strong&gt;&lt;br&gt;
It can be a dir anywhere.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Mounting command&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;s3fs -o iam_role="&amp;lt;your_iam_role&amp;gt;" \
     -o url="https://&amp;lt;your_aws_zone&amp;gt;.amazonaws.com" \
     -o endpoint=&amp;lt;your_aws_zone&amp;gt; \
     -o dbglevel=info \
     -o umask=000,uid=1000 \
     -o curldbg \
     -o allow_other \
     -o nonempty \
     -o &amp;lt;s3_bucket_name&amp;gt; &amp;lt;mounting_point
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;your_iam_role&lt;/code&gt; is the role created and assigned to EC2&lt;br&gt;
&lt;code&gt;your_aws_zone&lt;/code&gt; is the AWS zone your bucket is in. It can be found in bucket properties. I am in Canada, so will be &lt;em&gt;ca-central-1&lt;/em&gt;&lt;br&gt;
&lt;a href="https://community.ops.io/images/lXcuv4r7ZcNBz6dTO-lf-d4rrMX8CDm3FO7eKH8T9DY/w:880/mb:500000/ar:1/aHR0cHM6Ly9kZXYt/dG8tdXBsb2Fkcy5z/My5hbWF6b25hd3Mu/Y29tL3VwbG9hZHMv/YXJ0aWNsZXMvb2Rz/Mnl3NXVoZzh0andj/aXphbXEucG5n" class="article-body-image-wrapper"&gt;&lt;img src="https://community.ops.io/images/lXcuv4r7ZcNBz6dTO-lf-d4rrMX8CDm3FO7eKH8T9DY/w:880/mb:500000/ar:1/aHR0cHM6Ly9kZXYt/dG8tdXBsb2Fkcy5z/My5hbWF6b25hd3Mu/Y29tL3VwbG9hZHMv/YXJ0aWNsZXMvb2Rz/Mnl3NXVoZzh0andj/aXphbXEucG5n" alt="how to locate aws zone in s3" width="650" height="500"&gt;&lt;/a&gt;&lt;br&gt;
&lt;code&gt;umask 000&lt;/code&gt; is what is going to make your dir writable if webserver needs to be put files there. &lt;br&gt;
&lt;code&gt;nonempty&lt;/code&gt; only needs if the dir has anything in it, otherwise skip it&lt;/p&gt;

&lt;p&gt;This worked for me.&lt;/p&gt;

</description>
      <category>tutorials</category>
      <category>aws</category>
    </item>
  </channel>
</rss>
