<?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: Eetu Tuomala</title>
    <description>The latest articles on DEV Community by Eetu Tuomala (@laardee).</description>
    <link>https://dev.to/laardee</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%2F374836%2F842723a6-ed05-4626-915e-522293fbcb58.jpeg</url>
      <title>DEV Community: Eetu Tuomala</title>
      <link>https://dev.to/laardee</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/laardee"/>
    <language>en</language>
    <item>
      <title>Serve a React App from the S3 Bucket</title>
      <dc:creator>Eetu Tuomala</dc:creator>
      <pubDate>Tue, 02 Nov 2021 08:21:47 +0000</pubDate>
      <link>https://dev.to/aws-builders/serve-a-react-app-from-the-s3-bucket-25c2</link>
      <guid>https://dev.to/aws-builders/serve-a-react-app-from-the-s3-bucket-25c2</guid>
      <description>&lt;p&gt;An S3 bucket is a great place to serve static content like a web app build with React. Here are a few tips and tricks that will help you to get started.&lt;/p&gt;

&lt;p&gt;The S3 bucket has a feature that allows static website serving, but the downside is that it doesn't support HTTPS. Nowadays, plain HTTP is not an option. So for HTTPS support, a CloudFront distribution is needed. It also enables custom domain name, Web Application Firewall and a lot of other cool features. And if you have an API in your service, you can add that to CloudFront and serve everything from the same origin to mitigate the CORS pain.&lt;/p&gt;

&lt;p&gt;The S3 bucket is not a web server, so routing causes some issues. When using React router, routing works fine when you enter the site, but a 403 error is returned when opening an URL with a route resource, like &lt;code&gt;mydomain.com/users&lt;/code&gt;. This is because the browser tries to access the &lt;code&gt;/users&lt;/code&gt; file from the bucket, and as it's a React router path, the file doesn't exist in the S3 bucket. If you are wondering why it's 403 instead of 404 is because the bucket is not public.  &lt;/p&gt;

&lt;p&gt;How to prevent this is to modify the CloudFront error response in case of 403 error to be index.html, which routes all failed requests to the index.html and returns 200 status code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt; &lt;span class="nx"&gt;errorResponses&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;httpStatus&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;403&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;responseHttpStatus&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;responsePagePath&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;/index.html&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;ttl&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Duration&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;seconds&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This way, every time a file is not found from the path, it returns index.html and React router kicks in and handles the routing.&lt;/p&gt;

&lt;p&gt;In the example repository &lt;a href="https://github.com/laardee/deploy-react-app" rel="noopener noreferrer"&gt;https://github.com/laardee/deploy-react-app&lt;/a&gt; there is an infra stack build with AWS CDK and a simple React app that has router included.&lt;/p&gt;

</description>
      <category>aws</category>
      <category>beginners</category>
      <category>serverless</category>
    </item>
    <item>
      <title>Architecture Pattern Library</title>
      <dc:creator>Eetu Tuomala</dc:creator>
      <pubDate>Sun, 31 Oct 2021 15:27:08 +0000</pubDate>
      <link>https://dev.to/aws-builders/architecture-pattern-library-5f8g</link>
      <guid>https://dev.to/aws-builders/architecture-pattern-library-5f8g</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkwt9hm3mfkbhjflzird8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkwt9hm3mfkbhjflzird8.png" alt=" " width="800" height="336"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We at the MaaS Global go serverless-first when we build our mobile app's backend service. Since 2016 when we started to develop the service, we've used Lambdas, API Gateways, and other managed services that AWS offers. &lt;/p&gt;

&lt;p&gt;Our service contains hundreds of Lambdas per stage, dozens of API gateways, S3 buckets, and such. In addition to that, there are dozens of ways to do the same thing in AWS. For example, you can use Lambda, Kubernetes, ECS with Fargate, or plain EC2 instances for computing, and all options come with different features and restrictions. So even for senior engineers, adding new pieces to this puzzle can feel overwhelming. When the organization grows, and new engineers join the team, they also must adopt the internally used practices as part of the onboarding process. &lt;/p&gt;

&lt;p&gt;To help engineers with their efforts to architect features consistently, we've introduced a library of patterns that can be used to build larger architectures. It contains simple things like an API gateway, Lambda and PostgreSQL connection, S3 event triggers and queue processing. Also, it includes some high-level patterns such as a webhook proxy and cross-account event routing. &lt;/p&gt;

&lt;p&gt;Our patterns library is publicly available in GitHub  &lt;a href="https://github.com/maasglobal/maas-aws-patterns" rel="noopener noreferrer"&gt;https://github.com/maasglobal/maas-aws-patterns&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>aws</category>
      <category>architecture</category>
      <category>serverless</category>
    </item>
  </channel>
</rss>
