<?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: Tejansh Rana</title>
    <description>The latest articles on DEV Community by Tejansh Rana (@tejanshrana).</description>
    <link>https://dev.to/tejanshrana</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%2F574161%2F3d46ed16-a87b-413d-9273-de2a4b348e8e.jpeg</url>
      <title>DEV Community: Tejansh Rana</title>
      <link>https://dev.to/tejanshrana</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/tejanshrana"/>
    <language>en</language>
    <item>
      <title>How to add themes to your website with CSS and JS</title>
      <dc:creator>Tejansh Rana</dc:creator>
      <pubDate>Thu, 18 Feb 2021 22:54:25 +0000</pubDate>
      <link>https://dev.to/tejanshrana/how-to-add-themes-to-your-website-with-css-and-js-4n86</link>
      <guid>https://dev.to/tejanshrana/how-to-add-themes-to-your-website-with-css-and-js-4n86</guid>
      <description>&lt;p&gt;I've been working on my portfolio website of late and wanted to add the "theme switch" where users get to select whether they want to view my website in dark mode or light mode. While working on that, I realized this can be extended to not just two, but as many themes as you'd like. Pretty cool, eh? Let's see how we can do that.&lt;/p&gt;

&lt;p&gt;First, take a look at what it'll look like:&lt;/p&gt;

&lt;p&gt;This is the light mode:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--O7q4jVgK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1613684987839/FVXHpNEhN.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--O7q4jVgK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1613684987839/FVXHpNEhN.png" alt="light-mode.PNG"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And this is the dark mode:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--NvvrQx8g--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1613685002620/PxeKZmHsJ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--NvvrQx8g--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1613685002620/PxeKZmHsJ.png" alt="dark-mode.PNG"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And the theme switch is in the right top corner&lt;/p&gt;

&lt;p&gt;First of all, let's define all your CSS in one file, and the CSS variables for the colors we want to change in another file. Let's call the one with all the CSS as our &lt;br&gt;
&lt;code&gt;style.css&lt;/code&gt; and the ones with dark theme colors as &lt;code&gt;dark-variables.css&lt;/code&gt; and likewise the one with light theme colors as &lt;code&gt;light-variables.css&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Let's take a look at the two files now:&lt;/p&gt;

&lt;p&gt;light-variables.css:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;:root {
    --background: antiquewhite;
    --font: #242526;
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;dark-variables.css&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;:root {
    --background: #242526;
    --font: antiquewhite;
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That's great. Now, let's add them to our &lt;code&gt;index.html&lt;/code&gt; like this. Note that the link for variables file has an id &lt;code&gt;stylesheet&lt;/code&gt;. We will be using this later:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  &amp;lt;link id="stylesheet" rel="stylesheet" href="dark-variables.css" /&amp;gt;
  &amp;lt;link rel="stylesheet" href="style.css" /&amp;gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, I want the users to land on the dark-themed page by default and they can change it to the light theme if they want to. If you want it the other way, you can change the first stylesheet to &lt;code&gt;light-variables.css&lt;/code&gt; like below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;link id="stylesheet" rel="stylesheet" href="light-variables.css" /&amp;gt;
&amp;lt;link rel="stylesheet" href="style.css" /&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next, we need to add an &lt;code&gt;event listener&lt;/code&gt; to the theme switch button. Let's first look at what that button looks like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; &amp;lt;div id="theme-switch" class="theme-switch"&amp;gt;
          &amp;lt;div id="theme-icon" class="fas fa-moon"&amp;gt;&amp;lt;/div&amp;gt;
 &amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It's basically a div with id &lt;code&gt;theme-switch&lt;/code&gt; that contains another div with id &lt;code&gt;theme-icon&lt;/code&gt; which basically uses  &lt;a href="//fontawesome.com"&gt;font awesome&lt;/a&gt;  icons. &lt;/p&gt;

&lt;p&gt;Now, let's add the event listener. What we need to do here is add a &lt;code&gt;click&lt;/code&gt; event listener to trigger the theme switch function. &lt;/p&gt;

&lt;p&gt;Let's break that down into smaller chunks now:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Let's get the theme-button first:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const themeButton = document.getElementById('theme-switch')
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Now, let's add the event listener to trigger the theme switch function:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;themeButton.addEventListener('click', themeSwitch)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Now, let's define the &lt;code&gt;themeSwitch&lt;/code&gt; function bit by bit. First, let's get the stylesheet that is attached to the page currently:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const stylesheet = document.getElementById('stylesheet')
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Remember we gave the id "stylesheet" to the variables file? That's what we are getting here.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Next, let's check the href associated with the stylesheet. We can do that like:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const currentStyle = stylesheet.href
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Now, that we have the href, we can check which style is currently active and change to the other one. Let's do that:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   if (currentStyle.indexOf(lightTheme) !== -1) {
        stylesheet.href = darkTheme
        themeIcon.classList.remove(lightIcon)
        themeIcon.classList.add(darkIcon)
    }
    else {
        stylesheet.href = lightTheme
        themeIcon.classList.remove(darkIcon)
        themeIcon.classList.add(lightIcon)
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;p&gt;If you've noticed that we are removing and adding another class there, you are correct. That's the icon itself which we want to change when the theme is changed. &lt;br&gt;
So, for the light theme, we want the icon to be a moon to indicate that the users can click that button to switch to the dark theme, and for the dark theme we want the icon to be a sun to indicate that they can switch to light theme.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;This is what the function looks like in the end. Notice the extra declarations there? I just prefer to assign variables to everything. That's my personal preference :)&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function themeSwitch () {
     const darkIcon = "fa-sun";
     const lightIcon = "fa-moon";
     const lightTheme = "light-variables.css";
     const darkTheme = "dark-variables.css";
    if (currentStyle.indexOf(lightTheme) !== -1) {
        stylesheet.href = darkTheme
        themeIcon.classList.remove(lightIcon)
        themeIcon.classList.add(darkIcon)

    }
    else {
        stylesheet.href = lightTheme
        themeIcon.classList.remove(darkIcon)
        themeIcon.classList.add(lightIcon)   

    }

}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There it is! We have a website that supports multiple themes! If you want to add more themes, you can just add more buttons and add an event listener to each one. Each of these buttons can have their stylesheet with the colors of your choice. 😎&lt;/p&gt;

&lt;p&gt;If you liked this article and want to know more about the stuff I am building, let's stay in touch on  &lt;a href="https://twitter.com/TejanshRana"&gt;Twitter &lt;/a&gt; where I regularly post about things I am working on ❤&lt;/p&gt;

</description>
      <category>css</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Host your website on AWS with HTTPS ☁🔐</title>
      <dc:creator>Tejansh Rana</dc:creator>
      <pubDate>Mon, 08 Feb 2021 12:41:07 +0000</pubDate>
      <link>https://dev.to/tejanshrana/host-your-website-on-aws-with-https-o77</link>
      <guid>https://dev.to/tejanshrana/host-your-website-on-aws-with-https-o77</guid>
      <description>&lt;p&gt;So you've built your website and now you want to host it so that the world can see your work. Good call. You have two routes you can take here. First, you can host it via services like  &lt;a href="https://vercel.com/"&gt;Vercel&lt;/a&gt;  or  &lt;a href="https://vercel.com/"&gt;Netlify&lt;/a&gt;  which is the easier route to go. Or second, you can host it via  &lt;a href="https://aws.amazon.com/"&gt;AWS&lt;/a&gt;  (Amazon Web Services), which introduces you to the world of Cloud. The former is easier or let's say, a more straightforward way of deploying your website while the latter is relatively complicated but introduces you to the world of Cloud which has its endless possibilities.  &lt;/p&gt;

&lt;p&gt;In this article, I'd be covering the AWS way only, so if this interests you, keep reading.&lt;/p&gt;

&lt;h3&gt;
  
  
  Overview of what we'd be doing
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--lUxfxlxb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1612624811370/UAtxjSGpc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--lUxfxlxb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1612624811370/UAtxjSGpc.png" alt="staticHosting.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is one of those Cloud architecture diagrams that you must have come across before but made no sense. Except, this time, it will make sense. Let's break it down and understand what these colorful icons mean and why are they relevant.&lt;/p&gt;

&lt;h4&gt;
  
  
  S3
&lt;/h4&gt;

&lt;p&gt;On the right-hand side, the icon marked as "S3" (Simple Storage Service) is an AWS service for storing objects. Imagine it to be like a file storage system in Cloud offered by AWS. This is where your HTML, CSS, and JavaScript files will sit. &lt;/p&gt;

&lt;h4&gt;
  
  
  Cloudfront
&lt;/h4&gt;

&lt;p&gt;In the center, the icon marked as "Cloudfront" is an AWS service that serves as the CDN i.e.  &lt;a href="https://en.wikipedia.org/wiki/Content_delivery_network"&gt;Content Delivery Network&lt;/a&gt;. Click on that link to Wikipedia if you are unsure about what CDNs are. It's explained quite well there.&lt;/p&gt;

&lt;h4&gt;
  
  
  Route53
&lt;/h4&gt;

&lt;p&gt;Finally, on the left, you'd see the icon marked as "Route53". This is the DNS service provided by AWS. This will help us map your domain (say, example.com) to your site. It will make more sense when see start doing it.&lt;/p&gt;

&lt;h3&gt;
  
  
  Let's deploy
&lt;/h3&gt;

&lt;p&gt;Okay, so I am assuming you have an AWS account already. If you don't you can create one  &lt;a href="https://portal.aws.amazon.com/billing/signup#/start"&gt;here&lt;/a&gt;. Once you are in your console, navigate to S3. You can find that here:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--49Zshch9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1612732607960/F9ZCIcDel.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--49Zshch9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1612732607960/F9ZCIcDel.png" alt="consoles3.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once in there, first, we need to create a bucket. Imagine bucket here to be your root directory wherein you'd be storing your files (HTML, CSS, JS, assets, etc.). When you click on the "Create Bucket" option, it'll open up a page wherein you need to add the name of your bucket and other properties. You can name your bucket whatever you'd like, as far as it is unique. The bucket name needs to be unique and has some more restrictions that are listed  &lt;a href="https://docs.aws.amazon.com/AmazonS3/latest/dev/BucketRestrictions.html#bucketnamingrules"&gt;here&lt;/a&gt;. I am going to name my bucket as "my-hashnode-article". You can leave the other properties as is since we want to keep it as simple as possible. Now, click on "Create Bucket" at the end of the page:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--3ztV3FuW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1612734288318/XalRKdGFH.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--3ztV3FuW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1612734288318/XalRKdGFH.png" alt="CretaeBucket.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Okay, so now we have a place to store our files. Next, go to the bucket and upload the files. When you go to your bucket, you'd see the "Upload" button. When you click on that, that'll take you to a new page wherein you can choose to add files or folders.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--1yWlfUzN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1612734379118/8kiUjO1xD.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--1yWlfUzN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1612734379118/8kiUjO1xD.png" alt="addFiles.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now, you can add your files and folders and that's all we need to do with S3. &lt;/p&gt;

&lt;p&gt;Let's move on to Cloudfront now. Like you chose the S3 service from the AWS console, you can choose CloudFront and you should see the landing with the option to create a distribution. Upon clicking, you'd see a huge form you're expected to fill. Don't worry, we are going to skip a lot of those fields and leave them to the default values. Let's start filling in the form:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Origin domain name&lt;/strong&gt;: Choose the S3 bucket where you've uploaded your files.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Origin path&lt;/strong&gt;: If your files are under a directory in your S3 bucket, add that path here, else if it is at the root level, leave it empty. I have mine directly under the bucket so I will leave it empty.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Restrict Bucket Access&lt;/strong&gt;: Yes&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Origin Access Identity&lt;/strong&gt;: Create a New Identity&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Grant Read Permissions on Bucket&lt;/strong&gt;: Yes, Update Bucket Policy&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Viewer Protocol Policy&lt;/strong&gt;: This option is under the Default Cache Behavior Settings. Choose the "Redirect HTTP to HTTPS" option so we can enforce users to be calling your website at HTTPS. If they call your website at HTTP, they'd be automatically redirected to HTTPS. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Alternate Domain Names (CNAMEs)&lt;/strong&gt;: This option is under the Distribution Settings. Here, if you have a domain that you are building this website for, you can add that here. I am going to add "www[dot]tejanshrana[dot]com" since that is my domain. 
If you don't have a domain but would like to buy one, you can refer to the docs  [here](&lt;a href="https://docs.aws.amazon.com/Route53/latest/DeveloperGuide/domain-register.html"&gt;https://docs.aws.amazon.com/Route53/latest/DeveloperGuide/domain-register.html&lt;/a&gt;. You can buy your domain from anywhere you'd like. I had bought mine from  &lt;a href="https://godaddy.com/"&gt;GoDaddy&lt;/a&gt; and in this article, I will also cover the few extra steps you need to take to ensure that your domain is reachable when you've bought a domain from a vendor other than AWS.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;SSL Certificate&lt;/strong&gt;: If you are not adding a custom domain name, you can leave this option defaulted to "Default CloudFront Certificate (*.cloudfront.net)". If you've entered the CNAME, you need to import the SSL certificate. This is required to enable HTTPS on your website. You can do this by clicking the "Request or Import Certificate with ACM" button. This will open a new window from the AWS Certificate Manager service where you're expected to verify that the domain belongs to you. To do this, enter the domain name in the text box and click next. On the next page, you have the option to either verify by DNS validation or by Email validation. Since email is a more straightforward way to validate, let's go with that. Select Email Validation and click next. On the next page, you have the option to add tags. This is an optional step and I am going to skip it. Finally, click on the review button and review the information you've inputted. If everything looks alright. Click on the confirm and request button. You would now receive an email on the email address you'd used to purchase the domain with a link to confirm that it's your domain. Click on that link and you're done! Now, the SSL certificate is imported into your AWS account.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Default Root Object&lt;/strong&gt;: Here, enter the entry point for your website. For instance, my website's entry point is "index.html" so that's what I am going to enter here.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Your completed form should look similar to&lt;/strong&gt;:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--6KzaizAN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1612740604035/tReFrKBBq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--6KzaizAN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1612740604035/tReFrKBBq.png" alt="cloudfrontform.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now, click on Create Distribution when you're done and you'd need to wait a couple of minutes before the distribution is ready. Go get a cup of coffee and reload the page 500 times hoping that the status would change, like the rest of us. When ready you'd see the status change to "Deployed" from "In progress". &lt;/p&gt;

&lt;p&gt;Great, we now have a website for the world to see. However, this website is not yet reachable via your domain name. This needs a few more steps. If you don't have a domain and have chosen to use the default Cloudfront domain, you can see your domain on the Cloudfront landing page:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--m7I3LHR4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1612736708108/QGYz9H6dg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--m7I3LHR4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1612736708108/QGYz9H6dg.png" alt="cloudfrontdashboard.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now, let's configure the DNS to let your website be reachable via your domain name. For this, go to the Route53 AWS service from the AWS console. Upon landing, you'd see an option DNS management called "Create Hosted Zone"; click on that enter the domain name on the next page. Add it without the "www" so that you can use it with different subdomains in the future if need be. You can leave the other options to the default value and click on Create hosted zone. This will create a zone for you that'd be publicly accessible i.e. your domain would be reachable by everyone using the internet.&lt;/p&gt;

&lt;p&gt;Next, click on the hosted zone you've just created, and on the next page, click on "Create Record". On the next page, under Record Name, enter the subdomain by which you want your website to be reached. If you are creating a website for "www[dot]tejanshrana[dot]com", you can enter "www" in the record name. However, if you're creating a website for "tejanshrana.com", you can leave this empty.&lt;br&gt;
Now, toggle on the "Alias" option, and for the Record Type option, select "A - Traffic route to an IPV4 address and some AWS resources". In the dropdown next to it with the option "Route traffic to", choose "Alias to CloudFront distribution" and then choose your distribution name below it.&lt;br&gt;
In the end, your form should look similar to:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--YMv6CvxH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1612737511022/5A2WJ_Rhq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--YMv6CvxH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1612737511022/5A2WJ_Rhq.png" alt="Route53.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now, we need to create another record for the AAAA routes to ensure that your website is available to IPV4 as well as IPV6 traffic. Repeat the same steps again but for the Record Type option, select "AAAA - Traffic route to an IPV6 address and some AWS resources".&lt;/p&gt;

&lt;p&gt;Okay, we are almost there now. If you've bought your domain from GoDaddy, you'd need to login to your GoDaddy account and change the Named Servers there. You can do this in a few simple steps as follows:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Log in to your GoDaddy account. &lt;/li&gt;
&lt;li&gt;Select your domain to access the Domain Settings page.&lt;/li&gt;
&lt;li&gt;Under Additional Settings, select Manage DNS.&lt;/li&gt;
&lt;li&gt;In the Nameservers section, select Change.&lt;/li&gt;
&lt;li&gt;Now, you'd see text boxes to add domains. You can find these values in your AWS Route53 hosted zone dashboard where the type is mentioned as "NS". Look at the below image for reference:&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--p20UxxjK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1612738140970/1UI1X21yR.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--p20UxxjK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1612738140970/1UI1X21yR.png" alt="DNSnames.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Enter all 4 values in this section and save the settings. This takes quite some time to reflect (May take upto 48 hours). You can see the status  &lt;a href="https://www.whatsmydns.net/"&gt;here&lt;/a&gt; by entering your domain name and all or most of the regions should have a green tick (✔) next to it.&lt;/p&gt;

&lt;p&gt;We are LIVE!&lt;/p&gt;

&lt;h3&gt;
  
  
  BONUS
&lt;/h3&gt;

&lt;p&gt;Okay, so say your website is reachable at www[dot]tejanshrana[dot]com but your user enters tejanshrana.com and sees nothing, but you want them to be redirected to www[dot]tejanshrana[dot]com. We can fix that too! Let's do that now. &lt;/p&gt;

&lt;p&gt;Create an S3 bucket like the way you'd originally created for hosting your website. Once created, we don't want to upload anything here since we will be using this to redirect to your original website. Now, go to your bucket and click on Properties. Under properties, go to the last option that says "Static website hosting". Click on Edit and on the next page, you'd again see a few options. Fill them as below:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Static website hosting&lt;/strong&gt;: Enable&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Hosting type&lt;/strong&gt;: Redirect requests for an object&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Host name&lt;/strong&gt;: Enter your website's address here.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Protocol&lt;/strong&gt;: https.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Finally, the form should look similar to:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--w4bNdHaR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1612738920832/g14FMm-X9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--w4bNdHaR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1612738920832/g14FMm-X9.png" alt="nakedredirect.PNG"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once you're done, go back to the properties page of this S3 bucket and to the "Static website hosting" options again. Now, you'd see "Bucket website endpoint" there. Copy this since we are going to use this to create the Cloudfront distribution.&lt;/p&gt;

&lt;p&gt;Now, let's go to Cloudfront and create a distribution for this bucket. Don't worry, we have fewer options to fill in this time. You can do it as follows:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Origin Domain Name&lt;/strong&gt;: Paste the URL you'd copied from the S3 bucket. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Viewer Protocol Policy&lt;/strong&gt;: Redirect HTTP to HTTPS&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;SSL Certificate&lt;/strong&gt;: Custom SSL Certificate (example.com). Select the certificate you'd imported while creating the Cloudfront distribution the first time.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That's it. Create the distribution and wait for it to be deployed.&lt;/p&gt;

&lt;p&gt;Next, go to Route53 and select the hosted zone you'd created previously and create a new record. Now, in the alias, if you are trying to redirect say tejanshrana.com to www[dot]tejanshrana[dot]com, leave it empty, if you are doing it otherwise i.e. www[dot]tejanshrana[dot]com to tejanshrana.com, enter the alias as "www". Follow the same steps as previously and choose the Cloudfront distribution you've created last.&lt;/p&gt;

&lt;p&gt;AND WE ARE DONE! Show the world your new shiny website! In the next blog, I'll cover how to build a completely Serverless application via AWS. So keep an eye if that interests you. 😎&lt;/p&gt;

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