<?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: ♠Excelsior 💻</title>
    <description>The latest articles on DEV Community by ♠Excelsior 💻 (@yusufdamiloju).</description>
    <link>https://dev.to/yusufdamiloju</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%2F134158%2Fae341607-8936-4a56-bc5f-e537950c4b91.jpg</url>
      <title>DEV Community: ♠Excelsior 💻</title>
      <link>https://dev.to/yusufdamiloju</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/yusufdamiloju"/>
    <language>en</language>
    <item>
      <title>How To Host Your NuxtJs SPA on S3 with Cloudfront.</title>
      <dc:creator>♠Excelsior 💻</dc:creator>
      <pubDate>Sun, 12 Apr 2020 17:07:41 +0000</pubDate>
      <link>https://dev.to/yusufdamiloju/how-to-host-your-nuxtjs-spa-on-s3-with-cloudfront-2kni</link>
      <guid>https://dev.to/yusufdamiloju/how-to-host-your-nuxtjs-spa-on-s3-with-cloudfront-2kni</guid>
      <description>&lt;p&gt;You are trying to get your new shiny app deployed to the fancy AWS service either to save cost, try out a new option or any other reason you have in mind. You figure it’s not as straight forward as you think, this tutorial will try and lend a helping hand.&lt;/p&gt;

&lt;p&gt;This tutorial assumes knowledge of these services and won’t be explaining some terms.&lt;/p&gt;

&lt;h2&gt;
  
  
  Create and Configure S3
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Navigate to your AWS console, create an S3 bucket.
&amp;gt; This guide will help with that &lt;a href="https://docs.aws.amazon.com/AmazonS3/latest/gsg/CreatingABucket.html"&gt;https://docs.aws.amazon.com/AmazonS3/latest/gsg/CreatingABucket.html&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It’s important that you uncheck the &lt;em&gt;Block all public access&lt;/em&gt; box while creating your bucket.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--3T826nBO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2AbPhcpwSuTAJrwciCk_5v8w.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--3T826nBO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2AbPhcpwSuTAJrwciCk_5v8w.png" alt="Uncheck the *Block all public access* option."&gt;&lt;/a&gt;&lt;em&gt;Uncheck the **Block all public access&lt;/em&gt;* option.*&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Next, we configure our bucket for static website hosting.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--h1HFQY4b--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2ADlP6s_0Sz6CHCGkAoABxpQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--h1HFQY4b--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2ADlP6s_0Sz6CHCGkAoABxpQ.png" alt="Configure Bucket."&gt;&lt;/a&gt;&lt;em&gt;Configure Bucket.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;As shown above;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Select your created bucket from your list that would be displayed at &lt;a href="https://s3.console.aws.amazon.com/s3/home"&gt;https://s3.console.aws.amazon.com/s3/home&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Navigate to the properties tab and select the Static website hosting from the list of options.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Check the &lt;strong&gt;&lt;em&gt;Use this bucket to host a website&lt;/em&gt;&lt;/strong&gt; option&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Change the &lt;em&gt;Error Document&lt;/em&gt; to &lt;strong&gt;&lt;em&gt;index.html&lt;/em&gt;&lt;/strong&gt; (This is because our application is a SPA, and the index page does all the error handling).*&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Save&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;We are done with S3.&lt;/p&gt;

&lt;h2&gt;
  
  
  Create and Configure Cloudfront (Optional)
&lt;/h2&gt;

&lt;p&gt;This is an optional step but is highly recommended.&lt;/p&gt;

&lt;p&gt;This tutorial will help with setting up CloudFront and configuring it for our S3 bucket above &lt;a href="https://aws.amazon.com/premiumsupport/knowledge-center/cloudfront-serve-static-website/"&gt;https://aws.amazon.com/premiumsupport/knowledge-center/cloudfront-serve-static-website/&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Setup Project Scripts
&lt;/h2&gt;

&lt;p&gt;Create a new &lt;em&gt;deploy.sh&lt;/em&gt; file in your project directory, and copy the contents below into it.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Your &lt;em&gt;AWS_ACCESS_KEY_ID&lt;/em&gt; and &lt;em&gt;AWS_SECRET_ACCESS_KEY&lt;/em&gt; can be gotten from the AWS console, this guide will show you how if you don’t already know or have them &lt;a href="https://docs.aws.amazon.com/general/latest/gr/aws-sec-cred-types.html"&gt;https://docs.aws.amazon.com/general/latest/gr/aws-sec-cred-types.html&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;em&gt;AWS_BUCKET_NAME&lt;/em&gt; is the S3 bucket name we created above e.g mine is &lt;em&gt;test-bucket-damiloju&lt;/em&gt; as shown in picture 2.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;em&gt;AWS_CLOUDFRONT&lt;/em&gt; is our CloudFront distribution ID. It can be found here &lt;a href="https://console.aws.amazon.com/cloudfront/home"&gt;https://console.aws.amazon.com/cloudfront/home&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--4fnsPNSb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2AYPvIV9A2kZOfU417umD_FQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--4fnsPNSb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2AYPvIV9A2kZOfU417umD_FQ.png" alt="CloudFront distribution ID"&gt;&lt;/a&gt;&lt;em&gt;CloudFront distribution ID&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Important that you change the mode of your project in your &lt;strong&gt;&lt;em&gt;nuxt.config.js&lt;/em&gt;&lt;/strong&gt; to &lt;strong&gt;&lt;em&gt;spa&lt;/em&gt;&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Make deploy.sh executable and not check into gitignore.&lt;/p&gt;

&lt;p&gt;If you are on Mac or Linux, you can copy the above and paste it in your terminal to make deploy.sh executable.&lt;/p&gt;

&lt;p&gt;Next, we add gulp to our project and install it globally. Run the commands below.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;npm install — save-dev gulp gulp-awspublish gulp-cloudfront-invalidate-aws-publish concurrent-transform&lt;br&gt;
npm install -g gulp&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Now create a &lt;strong&gt;&lt;em&gt;gulpfile.js&lt;/em&gt;&lt;/strong&gt; file in your project directory and add the contents from the script below to it.&lt;/p&gt;

&lt;p&gt;Now we are done.&lt;/p&gt;

&lt;p&gt;All you need to do now is execute your deploy script.&lt;/p&gt;

&lt;p&gt;Go to your terminal and type &lt;strong&gt;&lt;em&gt;./deploy.sh&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You should get something similar to the pictures below as output.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--J6BdUrRe--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2ASVo-S_wFgiIXJOLb1-sOKA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--J6BdUrRe--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2ASVo-S_wFgiIXJOLb1-sOKA.png" alt="Terminal Output"&gt;&lt;/a&gt;&lt;em&gt;Terminal Output&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--6yceBoHR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2AS-Ggh-A0M2oc4hTRehmpnw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--6yceBoHR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2AS-Ggh-A0M2oc4hTRehmpnw.png" alt="Terminal Output 2"&gt;&lt;/a&gt;&lt;em&gt;Terminal Output 2&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;We are good to go :).&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;This takes parts from the official Nuxt Js article (which didn’t work for me) so the solution here provides a somewhat working solution with some differences from it. You can find the full article &lt;a href="https://nuxtjs.org/faq/deployment-aws-s3-cloudfront"&gt;here&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>vue</category>
      <category>aws</category>
      <category>s3</category>
      <category>nuxt</category>
    </item>
  </channel>
</rss>
