<?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>DEV Community: Denys Bochko</title>
    <description>The latest articles on DEV Community by Denys Bochko (@denys_bochko).</description>
    <link>https://dev.to/denys_bochko</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F862097%2F76ad668c-e1c6-4845-b51c-0fb1196d5930.jpg</url>
      <title>DEV Community: Denys Bochko</title>
      <link>https://dev.to/denys_bochko</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/denys_bochko"/>
    <language>en</language>
    <item>
      <title>Setting up separate environments on AWS</title>
      <dc:creator>Denys Bochko</dc:creator>
      <pubDate>Mon, 15 Jul 2024 18:05:01 +0000</pubDate>
      <link>https://dev.to/denys_bochko/setting-up-separate-environments-on-aws-1phc</link>
      <guid>https://dev.to/denys_bochko/setting-up-separate-environments-on-aws-1phc</guid>
      <description>&lt;p&gt;I recently faced the challenge of creating a separate locked-down environment on AWS to share the progress of a project with my designer. This environment needed to be accessible only via a VPN, as I don't have a static IP to associate with it.&lt;/p&gt;

&lt;p&gt;I tried using Twingate VPN to connect to a private VPN on AWS, but it didn't work because the Twingate connector couldn't connect to the server from the private VPN.&lt;/p&gt;

&lt;p&gt;After several days of struggle, I realized that I could achieve this even with a public VPN by setting up security groups to allow traffic only from that VPC, not from outside. Moreover, since I am using EC2 to host my web server, I can install a Twingate connector on the same instance. By allowing outbound connections in that security group, I enabled the connector to connect to the Twingate servers. This setup allows the VPN to function, and any users authorized on the VPN can access the site.&lt;/p&gt;

&lt;p&gt;Another challenge was connecting a private hosting zone to the EC2 instance so I could have a domain name pointing to the dev site. This was easily solved by simply entering the EC2 internal IP address into the A record of that domain, and everything worked beautifully.&lt;/p&gt;

&lt;p&gt;To summarize:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Public VPC&lt;/li&gt;
&lt;li&gt;EC2 instance&lt;/li&gt;
&lt;li&gt;Change the SSH port for better security; this port will need to be opened to the world so you can remotely SSH into the instance.&lt;/li&gt;
&lt;li&gt;Security group that allows traffic only within that VPC (e.g., 172.0.0.0/16); I think it is the top choice in the source field when creating an incoming connection filter in the SG.&lt;/li&gt;
&lt;li&gt;Add that security group to the EC2 instance.&lt;/li&gt;
&lt;li&gt;Set up a private DNS zone with the domain name.&lt;/li&gt;
&lt;li&gt;Create an A record and use the EC2 internal address as the destination.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Knowledge/experience sharing just in case somebody else is in the same situation&lt;/p&gt;

</description>
      <category>devops</category>
      <category>aws</category>
    </item>
    <item>
      <title>Mount S3 bucket to EC2 with IAM policy - step by step</title>
      <dc:creator>Denys Bochko</dc:creator>
      <pubDate>Fri, 13 May 2022 17:38:15 +0000</pubDate>
      <link>https://dev.to/denys_bochko/mount-s3-bucket-to-ec2-with-iam-policy-step-by-step-223l</link>
      <guid>https://dev.to/denys_bochko/mount-s3-bucket-to-ec2-with-iam-policy-step-by-step-223l</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://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fe3rhz67qa1sagsdzgyzp.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fe3rhz67qa1sagsdzgyzp.png" alt="IAm role setup" width="800" height="891"&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://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fods2yw5uhg8tjwcizamq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fods2yw5uhg8tjwcizamq.png" 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>aws</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
