<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Heshan Wickramaratne on Medium]]></title>
        <description><![CDATA[Stories by Heshan Wickramaratne on Medium]]></description>
        <link>https://medium.com/@iwiick?source=rss-336c28b6feda------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*T-3SXSgsRYhA2CIVXNlIQg.jpeg</url>
            <title>Stories by Heshan Wickramaratne on Medium</title>
            <link>https://medium.com/@iwiick?source=rss-336c28b6feda------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 20:34:19 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@iwiick/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Deploy SSR Apps with GitHub actions and AWS Amplify.]]></title>
            <link>https://blog.devgenius.io/deploy-ssr-apps-with-github-actions-and-aws-amplify-6f4bbbdec585?source=rss-336c28b6feda------2</link>
            <guid isPermaLink="false">https://medium.com/p/6f4bbbdec585</guid>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[cicd]]></category>
            <category><![CDATA[amplify]]></category>
            <category><![CDATA[nextjs]]></category>
            <category><![CDATA[github-actions]]></category>
            <dc:creator><![CDATA[Heshan Wickramaratne]]></dc:creator>
            <pubDate>Mon, 13 May 2024 14:16:42 GMT</pubDate>
            <atom:updated>2024-05-15T04:35:48.590Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5jFCOj3AAaQKqfd1hs0TiQ.png" /></figure><p>Alright. So this one right here is the final outcome of trying heaps of approaches to deploy a Server Side Rendering Application. Specifically a Next.JS application. Surprisingly, there was very little references on this topic with an approach that actually works. So hopefully, if you come across this, I hope it saves you some time and headaches that I went through :)</p><p>One important thing to remember if you are trying to…</p><ol><li>Build the application from inside the GitHub action.</li><li>Push the files into amplify.</li><li>Then start a manual deployment.</li></ol><p>THIS WILL NOT WORK for SSR applications. You will end up getting an error saying</p><p>Manual Deployment are not supported for this type of applications.</p><p>For server side rendering applications, the build will also need to be done from AWS amplified context using a Build Spec. Here’s the working Yaml.</p><pre>name: SSR app with Amplify<br>&#39;on&#39;:<br>  push:<br>    branches:<br>      - master<br>    tags:<br>      - v*<br>  workflow_dispatch: {}<br>env:<br>  roleArn: YOUR_AWS_ASSUME_ROLE_ARN<br>  region: YOUR_AWS_REGION<br>  pat: ${{ secrets.ADMIN_PAT }}<br>  APPLICATION_NAME: YOUR_APPLICATION_NAME<br>  APP_INSTALL_DEPS_PRE_COMMAND: npm i -g PNPM<br>  APP_INSTALL_DEPS_COMMAND: pnpm i<br>  APP_BUILD_COMMAND: npm run build<br>  APP_BUILD_FOLDER: .next<br>  AMPLIFY_ENV_VARS: &#39;,SOME_ENV=test1,SOME_OTHER_ENV=test2&#39;<br>jobs:<br>  build-ssr-web-app:<br>    name: Build Ssr Web App<br>    permissions: write-all<br>    runs-on: ubuntu-latest<br>    steps:<br>      - name: &#39;Run :: Checkout repository&#39;<br>        uses: actions/checkout@v4<br>        with:<br>          fetch-depth: 0<br>      - name: &#39;Run :: Configure AWS credentials&#39;<br>        uses: aws-actions/configure-aws-credentials@v4<br>        with:<br>          role-to-assume: ${{ env.roleARN }}<br>          role-session-name: skyu-pipeline-assume-role-session<br>          aws-region: ${{ env.region }}<br>      - name: &#39;Run :: Initialize AWS Amplify&#39;<br>        id: initialize-amplify<br>        run: |2-<br><br>              echo &quot;Fetching Amplify Apps&quot;<br>              app_list=$(aws amplify list-apps --no-paginate --region ${{ env.region }})<br>              app_id=$(echo &quot;$app_list&quot; | jq -r &#39;.apps[] | select(.name == &quot;${{ env.APPLICATION_NAME }}&quot;)&#39; | jq -r .appId)<br><br>              build_spec=&#39;{<br>                &quot;version&quot;: 1,<br>                &quot;frontend&quot;: {<br>                  &quot;phases&quot;: {<br>                    &quot;preBuild&quot;: {<br>                      &quot;commands&quot;: [<br>                        &quot;${{ env.APP_INSTALL_DEPS_PRE_COMMAND }}&quot;,<br>                        &quot;${{ env.APP_INSTALL_DEPS_COMMAND }}&quot;<br>                      ]<br>                    },<br>                    &quot;build&quot;: {<br>                      &quot;commands&quot;: [<br>                        &quot;${{ env.APP_BUILD_COMMAND }}&quot;<br>                      ]<br>                    }<br>                  },<br>                  &quot;artifacts&quot;: {<br>                    &quot;baseDirectory&quot;: &quot;${{ env.APP_BUILD_FOLDER }}&quot;,<br>                    &quot;files&quot;: [<br>                      &quot;**/*&quot;<br>                    ]<br>                  }<br>                }<br>              }&#39;<br><br>              if [ -n &quot;$app_id&quot; ]; then<br>                echo &quot;Amplify App already exists. Updating...&quot;<br><br>                production_branch=$(echo &quot;$app_list&quot; | jq -r &#39;.apps[] | select(.name == &quot;${{ env.APPLICATION_NAME }}&quot;)&#39; | jq -r .productionBranch.branchName)<br>                echo &quot;Production Branch: $production_branch&quot;<br>                echo &quot;productionBranch=$production_branch&quot; &gt;&gt; $GITHUB_OUTPUT<br><br>                aws amplify update-app \<br>                --app-id &quot;$app_id&quot; \<br>                --environment-variables &quot;Branch=${{ github.ref }},Commit=${{ github.sha }}${{ env.AMPLIFY_ENV_VARS }}&quot; \<br>                --iam-service-role-arn &quot;${{ env.roleARN }}&quot; \<br>                --build-spec &quot;$build_spec&quot; <br>              else<br>                echo &quot;Initializing new Amplify App&quot;<br>                formattedRepoUrl=$(echo &quot;${{ github.repositoryUrl }}&quot; | sed &#39;s|git://|https://|&#39;) <br>                echo &quot;Formatted Repository URL: $formattedRepoUrl&quot;<br>                create_app=$(<br>                  aws amplify create-app \<br>                  --name ${{ env.APPLICATION_NAME }} \<br>                  --platform WEB_COMPUTE \<br>                  --repository $formattedRepoUrl \<br>                  --environment-variables &quot;Branch=${{ github.ref }},Commit=${{ github.sha }}${{ env.AMPLIFY_ENV_VARS }}&quot; \<br>                  --access-token ${{ env.pat }} \<br>                  --region ${{ env.region }} \<br>                  --iam-service-role-arn ${{ env.roleARN }} \<br>                  --build-spec &quot;$build_spec&quot;<br>                )<br>                app_id=$(echo $create_app | jq -r &#39;.app.appId&#39;)<br>              fi<br>              <br>              echo &quot;App ID: $app_id&quot;<br>              echo &quot;appId=$app_id&quot; &gt;&gt; $GITHUB_OUTPUT<br><br>      - name: &#39;Run :: Publish to AWS Amplify&#39;<br>        run: |2-<br><br>              appId=${{ steps.initialize-amplify.outputs.appId }}<br>              productionBranch=${{ steps.initialize-amplify.outputs.productionBranch }}<br><br>              if [ -n &quot;$productionBranch&quot; ]; then <br>                if [ &quot;$productionBranch&quot; != &quot;${{ github.ref_name }}&quot; ]; then<br>                  echo &quot;Production Branch has Changed&quot;<br>                  echo &quot;Deleting Previous Production Branch&quot;<br>                  aws amplify delete-branch \<br>                  --app-id $appId \<br>                  --branch-name $productionBranch<br>                <br>                else <br>                  echo &quot;Production Branch Remains the Same&quot;<br>                fi<br><br>              else<br>                echo &quot;Production Branch Not found&quot;<br>              fi<br><br>              echo &quot;Creating Deployment branch&quot;<br>              aws amplify create-branch --stage PRODUCTION --app-id $appId --branch-name ${{ github.ref_name }} || true<br><br>              echo &quot;Checking for pending job on branch ${{ github.ref_name }}&quot;<br>              while true; do<br>                jobs=$(<br>                  aws amplify list-jobs \<br>                  --app-id $appId \<br>                  --branch-name &quot;${{ github.ref_name }}&quot; \<br>                  --output &quot;json&quot; --no-paginate<br>                )<br>                pending_jobs=$(echo $jobs | jq &#39;.jobSummaries | map(select(.status | IN(&quot;FAILED&quot;, &quot;SUCCEED&quot;, &quot;CANCELLED&quot;) | not))&#39;) <br>                pending_job_count=$(echo $pending_jobs | jq &#39;length&#39;)<br>                echo &quot;Pending Jobs: $pending_job_count&quot;<br><br>                if [ &quot;$pending_job_count&quot; -gt 0 ]; then<br>                    echo &quot;$pending_job_count Pending Job(s) found on branch ${{ github.ref_name }}. Waiting...&quot;<br>                    sleep 10  <br>                else<br>                  echo &quot;All Pending Jobs done... Proceeding&quot;<br>                  break<br>                fi<br>              done<br><br>              echo &quot;Starting Amplify Job&quot;<br>              aws amplify start-job \<br>              --app-id $appId \<br>              --branch-name ${{ github.ref_name }} \<br>              --job-type RELEASE<br></pre><h4>Conclusion</h4><ul><li>Note that I have used “Assume Roles” for the AWS credentials step. You can go with access key approach as well.</li><li>— iam-service-role-arn ${{ env.roleARN }} part is vital for creating an Amplify App. Since I’m using Assume roles, I am using the same role as the service role ARN aswell. This role needs to have Amplify access in the Trust relationships.</li></ul><pre>{<br>    &quot;Version&quot;: &quot;2012-10-17&quot;,<br>    &quot;Statement&quot;: [<br>        {<br>            &quot;Effect&quot;: &quot;Allow&quot;,<br>            &quot;Principal&quot;: {<br>                &quot;Federated&quot;: &quot;arn:aws:iam::&lt;ACCOUNT_ID_TO_ASSUME&gt;:oidc-provider/token.actions.githubusercontent.com&quot;<br>            },<br>            &quot;Action&quot;: &quot;sts:AssumeRoleWithWebIdentity&quot;,<br>            &quot;Condition&quot;: {<br>                &quot;StringEquals&quot;: {<br>                    &quot;token.actions.githubusercontent.com:aud&quot;: &quot;sts.amazonaws.com&quot;<br>                },<br>                &quot;StringLike&quot;: {<br>                    &quot;token.actions.githubusercontent.com:sub&quot;: [<br>                        &quot;repo:&lt;YOUR_GITHUB_ACCOUNT&gt;/*&quot;,<br>                    ]<br>                }<br>            }<br>        },<br>        {<br>            &quot;Effect&quot;: &quot;Allow&quot;,<br>            &quot;Principal&quot;: {<br>                &quot;Service&quot;: &quot;amplify.amazonaws.com&quot;<br>            },<br>            &quot;Action&quot;: &quot;sts:AssumeRole&quot;<br>        }<br>    ]<br>}</pre><ul><li>A GitHub pat is needed for this approach and for some reason, this Personal access token needs to be an “Admin” one. The token is only used for creating an application and is only used once.</li><li>I have used <a href="https://docs.aws.amazon.com/cli/latest/reference/amplify/list-apps.html">List Apps</a>, <a href="https://docs.aws.amazon.com/cli/latest/reference/amplify/create-app.html">Create App</a>, <a href="https://docs.aws.amazon.com/cli/latest/reference/amplify/update-app.html">Update App</a>, <a href="https://docs.aws.amazon.com/cli/latest/reference/amplify/create-branch.html">Create Branch</a>, <a href="https://docs.aws.amazon.com/cli/latest/reference/amplify/delete-branch.html">Delete Branch</a>, <a href="https://docs.aws.amazon.com/cli/latest/reference/amplify/list-jobs.html">List Jobs</a>, <a href="https://docs.aws.amazon.com/cli/latest/reference/amplify/start-job.html">Start Job</a> documentation for creating this Yaml. You can refer these for more improvements based on your requirements.</li></ul><p><em>by, </em><strong><em>Heshan Wickramaratne</em></strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6f4bbbdec585" width="1" height="1" alt=""><hr><p><a href="https://blog.devgenius.io/deploy-ssr-apps-with-github-actions-and-aws-amplify-6f4bbbdec585">Deploy SSR Apps with GitHub actions and AWS Amplify.</a> was originally published in <a href="https://blog.devgenius.io/">Dev Genius</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Saving JSONs as GitHub Secrets and accessing values from Actions]]></title>
            <link>https://blog.devgenius.io/saving-jsons-as-github-secrets-and-accessing-values-from-actions-7d3bdbbc7d28?source=rss-336c28b6feda------2</link>
            <guid isPermaLink="false">https://medium.com/p/7d3bdbbc7d28</guid>
            <category><![CDATA[json]]></category>
            <category><![CDATA[gitops]]></category>
            <category><![CDATA[github]]></category>
            <category><![CDATA[secrets]]></category>
            <category><![CDATA[github-actions]]></category>
            <dc:creator><![CDATA[Heshan Wickramaratne]]></dc:creator>
            <pubDate>Mon, 11 Mar 2024 17:15:35 GMT</pubDate>
            <atom:updated>2024-03-11T17:15:35.851Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wdI1BId4y_CJsE6AqsbdZw.png" /></figure><p>For a while now, I have been using GitHub secrets from GitHub actions. This process is quite straightforward where you can store a secret such as <strong>MY_SECRET</strong> and access it easily via the Action using <strong>${{ secrets.MY_SECRET }}</strong> syntax. But recently, I came across a requirement where I needed to store a GitHub secret as a JSON and access the JSON values from within the action file. In short, all the sensitive secrets I need for this particular action needed to be in a single GitHub secret as key value pairs instead of separate GitHub secrets. This process was not as straightforward as the traditional way. Since I spent some time sorting this out, I thought why not save that time for another.</p><h3>Saving the JSON as a GitHub secret</h3><p>This is the first step and it’s quite easy. GitHub secrets need to be <strong>strings</strong>. So, I went with the obvious solution. <strong>Encode the JSON as </strong><strong>base64</strong> and save it. As an example, let’s say we need to access 2 secrets called mySecret1 and mySecret2 from a Action. Create the JSON like,</p><pre>{<br>  &quot;mySecret1&quot;: &quot;some secret value 1&quot;,<br>  &quot;mySecret2&quot;: &quot;some secret value 2&quot;<br>}</pre><p>and encode this to base64 which should give something like this .</p><pre>ewogICJteVNlY3JldDEiOiAic29tZSBzZWNyZXQgdmFsdWUgMSIsCiAgIm15U2VjcmV0MiI6ICJzb21lIHNlY3JldCB2YWx1ZSAyIgp9</pre><p>Now save this as the GitHub secret. I’m going to save this as MY_SECRET</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zpHgiSZXDmblOkyUVDUpIw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/806/1*Thq5jjq_6do-6CefFuqYtA.png" /></figure><h3>Accessing the JSON secrets from actions</h3><p>This process is a bit tricky. It’s going to be like this.</p><ol><li>Refer the secret from the action.</li><li>Decode the base64 string.</li><li>Mask and add the key values pairs from the decoded JSON to the GitHub Env.</li></ol><p>Let’s create a sample action like this where we are referring the secret from the base64 encoded secret.</p><pre>name: Testing JSON secrets<br><br>on:<br>  push:<br>    branches: [master]<br>  workflow_dispatch: {}<br>  <br>env:<br>  ENCODED_PIPELINE_SECRET: ${{ secrets.MY_SECRET }}<br><br>jobs:<br>  secrets:<br>    name: Accessing JSON secret<br>    permissions: write-all<br>    runs-on: ubuntu-latest<br>    steps:<br>      - name: Envs Before<br>        run: echo &quot;Env values before&quot;</pre><p>After this action is triggered, the Envs should look something like this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/649/1*HOk4cxMFbBZqKF2Yzh0paQ.png" /></figure><p>Now let’s add another step to <strong>decode, mask and extract</strong> the key value pairs. We are going to use <strong>jq</strong> for this. I have added a condition to install jq if it’s not there in the runner since I use Self hosted runners sometimes. You can get rid of the “if” condition if you are using normal GitHub runners.</p><pre>- name: Decode Secrets<br>  run: |<br>    if [ ! -x &quot;$(command -v jq)&quot; ]; then<br>      echo &quot;jq not found, installing...&quot;<br>      sudo apt-get update<br>      sudo apt-get install -y jq<br>    fi<br>    echo &quot;${{ env.ENCODED_PIPELINE_SECRET }}&quot; | base64 --decode | jq -r &#39;to_entries[] | &quot;\(.key)=\(.value)&quot;&#39; | while read line; do echo &quot;$line&quot; &gt;&gt; $GITHUB_ENV; echo &quot;::add-mask::${line#*=}&quot;; done</pre><p>Here’s the improved YAML file.</p><pre>name: Testing JSON secrets<br><br>on:<br>  push:<br>    branches: [master]<br>  workflow_dispatch: {}<br>  <br>env:<br>  ENCODED_PIPELINE_SECRET: ${{ secrets.MY_SECRET }}<br><br>jobs:<br>  secrets:<br>    name: Accessing JSON secret<br>    permissions: write-all<br>    runs-on: ubuntu-latest<br>    steps:<br>      - name: Envs Before<br>        run: echo &quot;Env values before&quot;<br>        <br>      - name: Decode Secrets<br>        run: |<br>          if [ ! -x &quot;$(command -v jq)&quot; ]; then<br>            echo &quot;jq not found, installing...&quot;<br>            sudo apt-get update<br>            sudo apt-get install -y jq<br>          fi<br>          echo &quot;${{ env.ENCODED_PIPELINE_SECRET }}&quot; | base64 --decode | jq -r &#39;to_entries[] | &quot;\(.key)=\(.value)&quot;&#39; | while read line; do echo &quot;$line&quot; &gt;&gt; $GITHUB_ENV; echo &quot;::add-mask::${line#*=}&quot;; done<br>                <br>      - name: Envs After<br>        run: echo &quot;Env values after&quot;</pre><p>Now if you check the logs, you should see something like this..</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/717/1*OPo7Lx4ftSKsx2MeZtUdxw.png" /></figure><p>After this step, it’s only a matter of referencing each secret as <strong>${{ env.mySecret1 }}</strong> etc from anywhere inside the pipeline.</p><p>Hope this helps. Cheers 🍻.</p><p><em>by, </em><strong><em>Heshan Wickramaratne</em></strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7d3bdbbc7d28" width="1" height="1" alt=""><hr><p><a href="https://blog.devgenius.io/saving-jsons-as-github-secrets-and-accessing-values-from-actions-7d3bdbbc7d28">Saving JSONs as GitHub Secrets and accessing values from Actions</a> was originally published in <a href="https://blog.devgenius.io/">Dev Genius</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to do your Final Year Research Project as a SE Undergraduate.]]></title>
            <link>https://medium.com/@iwiick/how-to-do-your-final-year-research-project-as-a-se-undergraduate-87835b2f8520?source=rss-336c28b6feda------2</link>
            <guid isPermaLink="false">https://medium.com/p/87835b2f8520</guid>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[how-to]]></category>
            <category><![CDATA[final-year-projects]]></category>
            <category><![CDATA[ideas]]></category>
            <category><![CDATA[development]]></category>
            <dc:creator><![CDATA[Heshan Wickramaratne]]></dc:creator>
            <pubDate>Wed, 21 Feb 2024 08:46:09 GMT</pubDate>
            <atom:updated>2024-02-21T08:46:09.774Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/626/1*ia-OfVy4pCOZTLF2WgGqRg.png" /></figure><p>The reason I decided to write this article was because I came across an interesting discussion on Stack overflow by an individual overwhelmed with the technologies out there, where to start and most importantly WHAT to do.</p><p>I was a Software Engineering undergraduate not so far back, So this article is for my past self and for anyone who come across this. The chances are if you are reading this, it means you are figuratively ME during this specific period of time.</p><p>So, this little story right here is a small blend of my experience, advice, tips and pointers that helped me graduate with BSc. First Class Honours in Software Engineering from the University of Central Lancashire (UK).</p><h3>💡Final Year Project Ideas…</h3><p>This was the first thing I googled when I started the degree. <strong>Googling “What are good Final Year Project Ideas”</strong> is something every single person does when trying to find a project (I thought it was just me but no). Up until this point we have gotten so used to getting “Assignments” and “Coursework” with defined objectives that the idea of coming up with your own project seems pretty daunting. Hence, you google ideas on what other people THINK are good projects for you to do. I was fortunate enough to realize this early on. The project should be something YOU do. YOUR idea. YOUR passion. It’ll make the project THAT much more interesting for you and for the people who are going to moderate it.</p><h3>♠️ Your area of passion</h3><p>This is one of the biggest tips I can give you guys. Know your passion. Software Engineering covers a huge scope touching on various areas. <strong>It really helps narrowing things down</strong> to a certain area for the final year project. Especially when coming up with project ideas.</p><p>As an example, I always knew I wanted to make a full stack application utilizing Natural Language Processing. This was an area I was fascinated with and it made sense to go with it for 2 reasons.</p><ol><li>Knowing what sort of app/project you want to do will guide you in ultimately identifying your FYP. (From what I’ve seen and experienced, identifying and finalizing a project is the most time consuming part.)</li><li>It’ll make it easier to find a <strong>research gap</strong>.</li></ol><p>Having an area of passion before brainstorming FYPs will save you tons of time than blindly trying to come up with a project idea. This was my starting point, and it will save time for you as well. Why I say that is because I got to witness some people from my batch struggle to finalize an idea for the project. After all, you have been an undergraduate for 2–3 years at this point right?. Means, you have an idea of different areas you like and areas you don’t. Focus on these.</p><h3>🔎 The Research Gap</h3><p>These 2 words have been a pain in my existence since the first time I heard these. Chance are that you have already heard this term if you’re currently in the 3rd or 4th years at uni (maybe even before that). Let me elaborate... Your final year project can be an ordinary project. Some new product you want to bring out as an outcome. In which case your project might not have (or very little) related previous work.</p><p>Or… you can do a <strong>research </strong>project where YOUR project was influenced by previous work where the outcome is a new or improved product. In which case your project will be covering a research gap.</p><p>Here’s an OVER simplified example of what a research gap is, exactly as it was explained to me. (For some reason, I struggled with the meaning of this term at the start)</p><blockquote>Imagine you research on the Topic “xyz” and it’s human impact. You read related work on this topic and all of them have considered the impact only on “cold conditions”. Now a research gap here would be the impact of this on “warm conditions”</blockquote><p>Now you might be wandering why bother doing a research project when you can just do an ordinary project ? Here’s why…</p><ol><li>The final Year project is not just about coding. In my case we had a whole bunch of submissions including both documentation and code. One of these submissions was called “<strong>Background and Related work</strong>”. You do a research project… you have ample amount of previous work and resources to write your heart out. If not, covering areas like these can be quite the hassle. (Again this was witnessing fellow batch mates)</li><li>You can go for an international publication/conference. Achieving 2 great accomplishments with one effort. <strong>One BIG effort </strong>:)</li><li>You can proudly say your project was internationally accepted during the FYP viva and presentation (IF you get the acceptance before vivas that is. Don’t worry, I’ll explain further as we go on)</li></ol><h3>📘 Finalizing a Project</h3><p>While the project proposal is not graded, it’s the most important initial submission. This is where you pitch your idea. Let me rephrase that. <strong>This is where you pitch your novel idea of what you are going to produce after 9–12 months of hard work</strong>. So take this submission seriously.</p><p>You have your area of passion, you know what sort of project you want to do and you know what a research gap is. Now what?</p><blockquote>you need to do a <strong>small research first</strong> to find a research gap to do your own research based on that.</blockquote><p>That’s the simplest way I can word it. This is the point where you read through digital libraries, google scholar, app store, play store, etc… to see what sort of projects and apps are already out there, within your area of passion. <strong>Seeing what HAS been done already will give you an idea of what HASN’T</strong>.</p><p>This is going to be a very tedious task. So what ever ideas that pop into your head, note them down and maintain a list of possible projects. In my case, I started casually searching for Final year projects almost a whole year before the final year. This was because I didn’t want to rush and this ensured that I will be starting the final year with a solid project idea in hand. Which in my experience will put you way ahead of a majority of others.</p><p><strong>Then run your ideas by a Supervisor</strong>. This is really important. I had around 7–8 ideas before finalizing on one. With the help of my supervisor, most of these ideas were cut off one by one on the basis of <strong>not being feasible</strong>, <strong>already done</strong> or <strong>scope too small</strong>.</p><p>Also <strong>talk with your seniors</strong>. This is one of the best ways to get an overall idea of what you have to do and what others did before you. Personally, this helped me immensely because I got to learn from some of their mistakes.</p><p>If you’re reading this before the final year, good for you. If not, you just need to do this part of the process a bit faster. Small heads-up, time is going to be your biggest enemy during this year.</p><h3>🐜 Deciding on Technologies</h3><p>This is the point where you should focus on your strengths and weaknesses. The final year project is all about combining what you have learnt in the previous years and building on top of that. The final year project doesn’t mean you need to learn everything from scratch.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jyE2q7ANbQMElRoTZXynOQ.png" /></figure><p>These are all the technologies I used for my Final year project. Some were very new to me and some weren’t. It’s important to <strong>control the learning curve</strong> you have during Final year project timeline. This is because, you have a very limited time to create something from scratch and demonstrate it’s capabilities.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KIAjNbRjHHub_2CU4NB8DA.png" /></figure><p>As an example I was relatively comfortable and had experience working with the greyed out technologies here. Leaving me with a smaller learning curve and more time to focus on others.</p><h3>💪 Let the FYP begin…</h3><p>To tell it frankly, The final year was the most hectic year of my life. We had 4 modules + the Honours Degree Project module. All together 5 year long modules. The FYP submissions were under the Honours Degree Project module and it’s marks were distributed as follows.</p><ul><li>Project Proposal — <strong>0%</strong></li><li>Technical Plan — <strong>5%</strong></li><li>Background and Related work — <strong>10%</strong></li><li>Project Artefact — <strong>40%</strong></li><li>Final Report — <strong>40%</strong></li><li>Video and Poster — <strong>5%</strong></li></ul><p>Like I said, FYP is not just about coding and the final year is not JUST about the FYP. You still have your lectures, other modules, their assignments and coursework.</p><p>This was my timeline with the FYP submissions…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MdUXZFTw_vbPy5DKs1qx8g.png" /></figure><p>But along with the rest of the final year, it looked something like this…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AtYqr77CL_JY_1yK7Q65zg.png" /></figure><p>You get the point and all these values are the ACTUAL deadlines we got. In my experience, the challenging part of the final year is not the final year project. It’s doing the project along with all others stuff. The important thing is, you can make everything less chaotic by following a few simple techniques.</p><h4>Start Early, Finish Early</h4><p>This was something I followed throughout all 4 years of the degree and it will be a huge relief in the final year. Trust me on this. If you get an assignment for 4 weeks and you can finish it off in 2 weeks. Do just that instead of procrastinating. When you think you have time, you don’t :)</p><h4>Do not Procrastinate</h4><p>This will be your WORST enemy if you do it.</p><h4>VC your project</h4><p>This is mentioning the obvious here but make sure you properly <strong>version control your code</strong>. You simply do not have time to redo months of work just because of rookie mistakes. Git and GitHub all the way.</p><h4>Prioritize</h4><p>This is also quite important because you simply do not have time to divert from the project requirements once you start it. The Final year project is novelty achieved through race against time. So when you get your project proposal approved saying you are going to do this and that. You MUST do that. Or as it was worded in our submission, “<strong>Some form of working implementation of the proposed solution</strong>”</p><p>A little something I did during my project was that I prioritized my project requirements using MoSCoW prioritization. Then I mentioned in the <strong>Technical Plan</strong> that I will be completing all the MUST have’s and SHOULD have’s from those and will only focus on the COULD have’s depending on the time availability.</p><h4>Manage your Reference</h4><p>Make sure you keep tabs of all references you use during the project. Especially when writing the thesis. Even though you might think you know where each resource is. Working under pressure can screw those up. You don’t have to use something fancy like a proper reference management tool. Something simple like a excel sheet will work. That was what I did till I used my own project to do that for me. (That was partially my FYP. I’ll explain a bit more in the final thoughts section.)</p><h3>🌐 Publishing your Project</h3><p>“one effort… two achievements…” This was what my supervisor told me. You will anyways be doing an extensive research on your project for various submissions including the THESIS. The thesis is the BIGGEST documentation submission you will have during the project. So the plan was to put in a little more effort apart from that and do a publication. I’m not going to lie, this is a LOT of additional work. But here’s why this will be rewarding.</p><ol><li>Having a internationally accepted project will give immense credibility. So if you can get the “<strong>Acceptance</strong>” before project viva, that will be an added advantage during moderation.</li><li>Some <strong>universities/campuses financially support you on this process</strong>. Mine did. Both the conference and publication costed more than 500 Euros which was funded by my campus.</li><li>You will be a fresh grad with a publication afterwards. Which again puts you way ahead of the majority.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FoyIA2CrrWbt1Vq26Q1DiQ.png" /></figure><p>Getting your project accepted is a tedious task. you will have to write and re-write submissions and it’s going to be somewhat hectic if you want to get it accepted before Vivas. That was my intention and I DID IT. Which means you can too :)</p><h3>🎲 Final Thoughts</h3><p>Inspiration for your final year project can be very different from one person to another. My inspiration came from reading other peoples’ research papers and realizing that that whole process was agonizingly time consuming. So my project was on a solution for that.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/794/1*VXX899e_vDsOq6TXwQ9jDg.png" /></figure><p><a href="https://www.spiedigitallibrary.org/conference-proceedings-of-spie/12936/129361J/Documon--an-intelligent-web-platform-to-identify-recommend-and/10.1117/12.3011414.full?tab=ArticleLink#_=_">Documon: an intelligent web platform to identify, recommend, and manage material relevance of research publications</a></p><p>While I cannot talk on behalf of other degrees, the <a href="https://www.uclan.ac.uk/undergraduate/courses/software-engineering-bsc">BSc. (Hons) in Software Engineering</a> degree provided by the University of Central Lancashire (UK) gives options where the student can…</p><ol><li>Graduate with Industry Placement (4 years)</li><li>Graduate without Industry Placement (3 years)</li></ol><p>Speaking from experience, those 12 months working in the industry, building real world applications in cross functional teams really make a massive difference. During the final year, we had 2 sets of students in our batch. The final year students who were actual 4th years students coming back from the industry and 2nd years students who skipped the work placement year. There was a HUGE gap in knowledge between these guys. Which ultimately effected their final year projects as well as other modules.</p><p>I worked as a Software Engineering intern at <a href="https://99x.io/">99x</a> for 12 months before coming into the final year and I was not the same person who left the 2nd year at this point. I got to learn so much more than what is taught at a University level. I also got the opportunity to interact with fresh graduates coming into the industry and the caliber of projects they have done before me. All these helped mold the project and outcome of the final year for me. So if you can, and if you do have the opportunity to do an internship before the final year… DO IT… DO NOT MISS THE OPPORTUNITY.</p><p>For us, the Final year project went as the Honours Degree Project. In short, we don’t get Honours if we screw up the project. Because of this, the credit value for the module was also also doubled 💀. So I knew I had to give my absolute best at this while managing the time for the rest of the year. This was especially challenging because I also kept on going for Futsal and swimming practices 3–4 days per week along with a lot of other extra-curricular activities. With all that, I still managed to find time and that is something I’m utterly proud of.</p><p>The reason why I wanted to write this article was because I have included information here that I myself would’ve found useful given someone else wrote this before me. I don’t expect a lot of people to read this but my hope is that it finds who ever needs to read it in time. Just want this to be out there somewhere in the internet till then.</p><p>Here’s my last 4 years in less than 4 minutes…</p><p><a href="https://www.linkedin.com/posts/heshan-wickramaratne_graduation-graduate-classof2023-activity-7138033688629444608-2fKd?utm_source=share&amp;utm_medium=member_desktop">Heshan Wickramaratne on LinkedIn: #graduation #graduate #classof2023 #grad #graduationday #graduates... | 18 comments</a></p><p>by, <strong>Heshan Wickramaratne</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=87835b2f8520" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Create, Register and Terminate EC2 Spot Instances via GitHub actions]]></title>
            <link>https://blog.devgenius.io/create-register-and-terminate-ec2-spot-instances-via-github-actions-aef473b8a00f?source=rss-336c28b6feda------2</link>
            <guid isPermaLink="false">https://medium.com/p/aef473b8a00f</guid>
            <category><![CDATA[github]]></category>
            <category><![CDATA[github-actions]]></category>
            <category><![CDATA[aws-ec2]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[spot-instances]]></category>
            <dc:creator><![CDATA[Heshan Wickramaratne]]></dc:creator>
            <pubDate>Mon, 05 Feb 2024 17:10:19 GMT</pubDate>
            <atom:updated>2024-02-05T17:10:19.539Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*p9mAGpHtBWBiGaDQTnEWlg.png" /></figure><p>Hey guys. So I decided to write this small article because I got stuck trying to implement a specific use case where I needed GitHub action to…</p><ol><li>Create an EC2 spot instance.</li><li>Install Docker and Docker Compose in the instance.</li><li>Register it as a GitHub self hosted runner.</li><li>Use this self-hosted runner to execute some Docker compose commands.</li><li>Terminate the Instance</li><li>and finally remove the Runner from GitHub.</li></ol><p>Since it took me some time to implement the full use case, I thought why not save some time for another. Cost wise, using “Spot ”instances will make a major difference than using “On Demand” instances. But if that’s what you require, <a href="https://github.com/machulav/ec2-github-runner">this action here</a> works perfectly for creating On demand instances. If not, here’s how you can use a spot instance as a GitHub self-hosted runner.</p><h4>Using the Launch Specification to Create Runners</h4><p>All this is done using the --launch-specification attribute from the <a href="https://docs.aws.amazon.com/cli/latest/reference/ec2/request-spot-instances.html">CLI reference for requesting AWS Spot instances</a>. Using this, we can execute commands automatically once the instance is initialized. We are going to use this specification to install docker and docker compose, add proper groups and register it as a GitHub self-hosted runner.</p><p>If you go to Actions → Runners → New Runner → New Self Hosted Runner in your GitHub repo…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tvl3MjNGrfMz8moGWDNj8Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1a2ppx71l8ZSyoJAe2VQbw.png" /></figure><p>You can find the commands to register it as a new Self Hosted Runner. But the catch is, the token provided in the Configure Steps will expire after a while. So your GitHub action will stop working after a while. That’s when I came aross this.</p><p><a href="https://stackoverflow.com/a/59567901/13370488">How I can get a github actions runner token</a></p><p>Turns out, there is an API for that already. So combining all that, The first Job in the action is to create and register EC2 spot instance as a GitHub Self hosted Runner.</p><pre>start-runner:<br>  name: Start Runner<br>  permissions: write-all<br>  runs-on: ubuntu-latest<br>  outputs:<br>    EC2_HOST: ${{ env.EC2_HOST }}<br>    EC2_INSTANCE_ID: ${{ env.EC2_INSTANCE_ID }}<br>  steps:<br>    - name: &quot;Run :: Configure AWS credentials 977acc62-cd41-4861-8256-d2103c3cba5b&quot;<br>      uses: aws-actions/configure-aws-credentials@v4<br>      with:<br>        role-to-assume: ${{ env.roleARN }}<br>        role-session-name: pipeline-assume-role-session<br>        aws-region: ${{ env.region }}<br><br>    - name: &quot;Run :: Create AWS Spot Instance&quot;<br>      run: |2-<br>            # Get GitHub Actions runner registration token<br>            response=$(curl -s -X POST         -H &#39;Accept: application/vnd.github+json&#39;         -H &#39;Authorization: Bearer ${{ env.pat }}&#39;         -H &#39;X-GitHub-Api-Version: 2022-11-28&#39;         https://api.github.com/repos/${GITHUB_REPOSITORY}/actions/runners/registration-token)<br>            RUNNER_REG_TOKEN=$(echo &quot;$response&quot; | jq -r .token)<br>            <br>            if [ $RUNNER_REG_TOKEN != &quot;null&quot; ]; then<br>              USER_DATA=&quot;#!/bin/bash<br>              <br>              apt update &amp;&amp; apt install -y apt-transport-https<br>              apt-get update &amp;&amp; apt install docker.io -y<br>              echo \&quot;Docker Installed\&quot;<br>              usermod -aG docker ubuntu<br>              newgrp docker<br>              echo \&quot;ubuntu Added to Groups\&quot;<br>              # docker-compose<br>              curl -L &#39;https://github.com/docker/compose/releases/latest/download/docker-compose-Linux-x86_64&#39; -o /usr/local/bin/docker-compose<br>              echo \&quot;Docker Compose Installed\&quot;<br>              chmod +x /usr/local/bin/docker-compose<br>              echo \&quot;Docker Compose Permissions added\&quot;<br>              <br>              # Install GitHub Actions runner<br>              mkdir /home/ubuntu/actions-runner &amp;&amp; cd /home/ubuntu/actions-runner<br>              curl -o actions-runner-linux-x64-2.312.0.tar.gz -L https://github.com/actions/runner/releases/download/v2.312.0/actions-runner-linux-x64-2.312.0.tar.gz<br>              echo \&quot;Github Runner Installed\&quot;<br>              # Extract the installer<br>              tar xzf ./actions-runner-linux-x64-2.312.0.tar.gz<br>              echo \&quot;Github Runner Installer Extracted\&quot;<br>              <br>              # Run GitHub Actions runner configuration<br>              export RUNNER_ALLOW_RUNASROOT=1<br>              yes &#39;&#39; | ./config.sh --url https://github.com/${GITHUB_REPOSITORY} --token $RUNNER_REG_TOKEN --labels MY_RUNNER_${{github.sha}}<br>              echo \&quot;Github Runner Configured\&quot;<br>              <br>              # Run GitHub Actions runner<br>              yes &#39;&#39; | ./run.sh <br>              echo \&quot;Github Runner UP!\&quot;<br>              &quot;<br>              <br>              ENCODED_USER_DATA=$(echo -n &quot;$USER_DATA&quot; | sed &#39;s/^[[:space:]]*//&#39; | base64 -w 0)<br>              echo &quot;ENCODED_USER_DATA :: $ENCODED_USER_DATA&quot;<br>              echo &quot;LAUNCH SPECIFICATION JSON :: {\&quot;ImageId\&quot;:\&quot;${{ env.EC2_IMAGE_ID }}\&quot;,\&quot;InstanceType\&quot;:\&quot;${{ env.EC2_INSTANCE_TYPE }}\&quot;,\&quot;KeyName\&quot;:\&quot;QWENKey\&quot;,\&quot;SecurityGroupIds\&quot;:[\&quot;${{ env.EC2_SECURITY_GROUP_ID }}\&quot;],\&quot;SubnetId\&quot;:\&quot;${{ env.EC2_SUBNET_ID }}\&quot;,\&quot;UserData\&quot;:\&quot;$ENCODED_USER_DATA\&quot;}&quot;<br>              <br>              REQUEST_ID=$(aws ec2 request-spot-instances         --spot-price &quot;${{ env.EC2_SPOT_INSTANCE_PRICE }}&quot;         --instance-count 1         --type &quot;one-time&quot;         --launch-specification &quot;{\&quot;ImageId\&quot;:\&quot;${{ env.EC2_IMAGE_ID }}\&quot;,\&quot;InstanceType\&quot;:\&quot;${{ env.EC2_INSTANCE_TYPE }}\&quot;,\&quot;KeyName\&quot;:\&quot;QWENKey\&quot;,\&quot;SecurityGroupIds\&quot;:[\&quot;${{ env.EC2_SECURITY_GROUP_ID }}\&quot;],\&quot;SubnetId\&quot;:\&quot;${{ env.EC2_SUBNET_ID }}\&quot;,\&quot;UserData\&quot;:\&quot;$ENCODED_USER_DATA\&quot;}&quot;         --query &#39;SpotInstanceRequests[0].SpotInstanceRequestId&#39;         --output text)<br>              aws ec2 wait spot-instance-request-fulfilled --spot-instance-request-ids $REQUEST_ID<br>              INSTANCE_ID=$(aws ec2 describe-spot-instance-requests --spot-instance-request-ids $REQUEST_ID --query &#39;SpotInstanceRequests[*].InstanceId&#39; --output text)<br>              HOSTNAME=$(aws ec2 describe-instances --instance-ids $INSTANCE_ID --query &#39;Reservations[0].Instances[0].PublicDnsName&#39; --output text)<br>              <br>              echo &quot;EC2_HOST=$HOSTNAME&quot; &gt;&gt; $GITHUB_ENV<br>              echo &quot;EC2_INSTANCE_ID=$INSTANCE_ID&quot; &gt;&gt; $GITHUB_ENV <br>            else<br>                echo &quot;$response&quot;<br>              exit 1<br>            fi</pre><p>Important things to note here.</p><ul><li>--launch-specification needs to be a JSON. So “” signs need to be properly escaped with \ signs.</li><li>The startup instance commands need to be passed on to the userData attribute as a base64 encoded string.</li><li>ENCODED_USER_DATA=$(echo -n “$USER_DATA” | sed ‘s/^[[:space:]]*//’ | base64 -w 0) line has been used to remove leading spaces if any before encoding.</li></ul><h4>Using the new Self Hosted Runner from a job</h4><p>Once this job is completed, it will create a new Self-Hosted runner. You can then use this self-hosted runner for a job.</p><pre>compose-job:<br>  name: Compose Job<br>  permissions: write-all<br>  runs-on: self-hosted<br>  needs:<br>    - start-runner<br>  steps:<br>    - name: Start<br>      run: echo &quot; Starting GitHub Action!&quot;<br><br>    - name: &quot;Run :: Checkout repository&quot;<br>      uses: actions/checkout@v2<br><br>    - name: &quot;Run :: Docker Compose&quot;<br>      run: |2-<br>            docker-compose -f ${{env.DOCKER_COMPOSE_FILE_PATH}} build &amp;&amp; docker-compose -f ${{env.DOCKER_COMPOSE_FILE_PATH}} up -d &amp;&amp;<br>            ${{env.ADDITIONAL_COMPOSE_COMMANDS}}<br>            docker-compose -f ${{env.DOCKER_COMPOSE_FILE_PATH}} down -v</pre><p>Notice how it runs-on the self-hosted runner.</p><h4>Terminating the instance and removing runners from GithHub</h4><p>Here, we are going to terminate the instance from AWS and cleanup runners using the GitHub API. if: ${{ always() }} has been used here to trigger the stop-runner job regardless of any errors in the previous jobs.</p><pre>stop-runner:<br>  name: Stop Runner<br>  permissions: write-all<br>  runs-on: ubuntu-latest<br>  needs:<br>    - start-runner<br>    - compose-job<br>  if: ${{ always() }}<br>  steps:<br>    - name: &quot;Run :: Configure AWS credentials 43f45f27-01f3-4344-b51d-c554e9bc40db&quot;<br>      uses: aws-actions/configure-aws-credentials@v4<br>      with:<br>        role-to-assume: ${{ env.roleARN }}<br>        role-session-name: pipeline-assume-role-session<br>        aws-region: ${{ env.region }}<br><br>    - name: &quot;Run :: Stop AWS Spot Instance&quot;<br>      run: |2-<br>            aws ec2 terminate-instances --instance-ids ${{ needs.start-runner.outputs.EC2_INSTANCE_ID }}<br>            gh_runner_label=${{ needs.start-runner.outputs.EC2_RUNNER }}<br>            response=$(curl -X GET         https://api.github.com/repos/${GITHUB_REPOSITORY}/actions/runners         -H &#39;Authorization: Bearer ${{ env.pat }}&#39;<br>            )<br>            offline_runners=$(echo &quot;$response&quot; | jq &#39;.runners | map(select((.labels? | any(.name == &quot;EC2_RUNNER_${{github.sha}}&quot;))))&#39;)<br>            echo &quot;Offline Runners :: $offline_runners&quot;<br>            <br>            echo &quot;Attempting to remove offline runners...&quot;<br>            for runner in $(echo &quot;$offline_runners&quot; | jq -r &#39;.[].id&#39;); do<br>              echo &quot;Triggering action for runner ID: $runner&quot;<br>              curl -X DELETE         https://api.github.com/repos/${GITHUB_REPOSITORY}/actions/runners/$runner           -H &#39;Authorization: Bearer ${{ env.pat }}&#39;<br>            done</pre><p>We can use the GitHub API to list all runners and use jq to filter only offline runners with specific labels. I have used the github.sha as the label when creating instances. Therefore I can use the same to remove only the needed instances.</p><h4>Complete YML</h4><pre>name: Ec2 Spot from Actions<br>on:<br>  push:<br>    branches:<br>      - main<br>  workflow_dispatch: {}<br>env:<br>  EC2_INSTANCE_TYPE: t2.medium<br>  EC2_IMAGE_ID: ami-0c7217cdde317cfec<br>  EC2_SUBNET_ID: subnet-0511e49f8669e4d30<br>  EC2_SECURITY_GROUP_ID: sg-0244f2edb7af33703<br>  EC2_SPOT_INSTANCE_PRICE: &quot;0.05&quot;<br>  DOCKER_COMPOSE_FILE_PATH: src/docker-compose.yml<br>jobs:<br>  start-runner:<br>    name: Start Runner<br>    permissions: write-all<br>    runs-on: ubuntu-latest<br>    outputs:<br>      EC2_HOST: ${{ env.EC2_HOST }}<br>      EC2_INSTANCE_ID: ${{ env.EC2_INSTANCE_ID }}<br>    steps:<br>      - name: &quot;Run :: Configure AWS credentials 977acc62-cd41-4861-8256-d2103c3cba5b&quot;<br>        uses: aws-actions/configure-aws-credentials@v4<br>        with:<br>          role-to-assume: ${{ env.roleARN }}<br>          role-session-name: pipeline-assume-role-session<br>          aws-region: ${{ env.region }}<br><br>      - name: &quot;Run :: Create AWS Spot Instance&quot;<br>        run: |2-<br>              # Get GitHub Actions runner registration token<br>              response=$(curl -s -X POST         -H &#39;Accept: application/vnd.github+json&#39;         -H &#39;Authorization: Bearer ${{ env.pat }}&#39;         -H &#39;X-GitHub-Api-Version: 2022-11-28&#39;         https://api.github.com/repos/${GITHUB_REPOSITORY}/actions/runners/registration-token)<br>              RUNNER_REG_TOKEN=$(echo &quot;$response&quot; | jq -r .token)<br>              <br>              if [ $RUNNER_REG_TOKEN != &quot;null&quot; ]; then<br>                USER_DATA=&quot;#!/bin/bash<br>                <br>                apt update &amp;&amp; apt install -y apt-transport-https<br>                apt-get update &amp;&amp; apt install docker.io -y<br>                echo \&quot;Docker Installed\&quot;<br>                usermod -aG docker ubuntu<br>                newgrp docker<br>                echo \&quot;ubuntu Added to Groups\&quot;<br>                # docker-compose<br>                curl -L &#39;https://github.com/docker/compose/releases/latest/download/docker-compose-Linux-x86_64&#39; -o /usr/local/bin/docker-compose<br>                echo \&quot;Docker Compose Installed\&quot;<br>                chmod +x /usr/local/bin/docker-compose<br>                echo \&quot;Docker Compose Permissions added\&quot;<br>                <br>                # Install GitHub Actions runner<br>                mkdir /home/ubuntu/actions-runner &amp;&amp; cd /home/ubuntu/actions-runner<br>                curl -o actions-runner-linux-x64-2.312.0.tar.gz -L https://github.com/actions/runner/releases/download/v2.312.0/actions-runner-linux-x64-2.312.0.tar.gz<br>                echo \&quot;Github Runner Installed\&quot;<br>                # Extract the installer<br>                tar xzf ./actions-runner-linux-x64-2.312.0.tar.gz<br>                echo \&quot;Github Runner Installer Extracted\&quot;<br>                <br>                # Run GitHub Actions runner configuration<br>                export RUNNER_ALLOW_RUNASROOT=1<br>                yes &#39;&#39; | ./config.sh --url https://github.com/${GITHUB_REPOSITORY} --token $RUNNER_REG_TOKEN --labels EC2_RUNNER_${{github.sha}}<br>                echo \&quot;Github Runner Configured\&quot;<br>                <br>                # Run GitHub Actions runner<br>                yes &#39;&#39; | ./run.sh <br>                echo \&quot;Github Runner UP!\&quot;<br>                &quot;<br>                <br>                ENCODED_USER_DATA=$(echo -n &quot;$USER_DATA&quot; | sed &#39;s/^[[:space:]]*//&#39; | base64 -w 0)<br>                echo &quot;ENCODED_USER_DATA :: $ENCODED_USER_DATA&quot;<br>                echo &quot;LAUNCH SPECIFICATION JSON :: {\&quot;ImageId\&quot;:\&quot;${{ env.EC2_IMAGE_ID }}\&quot;,\&quot;InstanceType\&quot;:\&quot;${{ env.EC2_INSTANCE_TYPE }}\&quot;,\&quot;KeyName\&quot;:\&quot;QWENKey\&quot;,\&quot;SecurityGroupIds\&quot;:[\&quot;${{ env.EC2_SECURITY_GROUP_ID }}\&quot;],\&quot;SubnetId\&quot;:\&quot;${{ env.EC2_SUBNET_ID }}\&quot;,\&quot;UserData\&quot;:\&quot;$ENCODED_USER_DATA\&quot;}&quot;<br>                <br>                REQUEST_ID=$(aws ec2 request-spot-instances         --spot-price &quot;${{ env.EC2_SPOT_INSTANCE_PRICE }}&quot;         --instance-count 1         --type &quot;one-time&quot;         --launch-specification &quot;{\&quot;ImageId\&quot;:\&quot;${{ env.EC2_IMAGE_ID }}\&quot;,\&quot;InstanceType\&quot;:\&quot;${{ env.EC2_INSTANCE_TYPE }}\&quot;,\&quot;KeyName\&quot;:\&quot;QWENKey\&quot;,\&quot;SecurityGroupIds\&quot;:[\&quot;${{ env.EC2_SECURITY_GROUP_ID }}\&quot;],\&quot;SubnetId\&quot;:\&quot;${{ env.EC2_SUBNET_ID }}\&quot;,\&quot;UserData\&quot;:\&quot;$ENCODED_USER_DATA\&quot;}&quot;         --query &#39;SpotInstanceRequests[0].SpotInstanceRequestId&#39;         --output text)<br>                aws ec2 wait spot-instance-request-fulfilled --spot-instance-request-ids $REQUEST_ID<br>                INSTANCE_ID=$(aws ec2 describe-spot-instance-requests --spot-instance-request-ids $REQUEST_ID --query &#39;SpotInstanceRequests[*].InstanceId&#39; --output text)<br>                HOSTNAME=$(aws ec2 describe-instances --instance-ids $INSTANCE_ID --query &#39;Reservations[0].Instances[0].PublicDnsName&#39; --output text)<br>                <br>                echo &quot;EC2_HOST=$HOSTNAME&quot; &gt;&gt; $GITHUB_ENV<br>                echo &quot;EC2_INSTANCE_ID=$INSTANCE_ID&quot; &gt;&gt; $GITHUB_ENV <br>              else<br>                  echo &quot;$response&quot;<br>                exit 1<br>              fi<br><br>  compose-job:<br>    name: Compose Job<br>    permissions: write-all<br>    runs-on: self-hosted<br>    needs:<br>      - start-runner<br>    steps:<br>      - name: Start<br>        run: |2-<br>              echo &quot; Starting GitHub Action!&quot; &amp;&amp; <br>              echo &quot;STEPS_CAN_PROCEED=true&quot; &gt;&gt; $GITHUB_ENV<br><br>      - name: &quot;Run :: Checkout repository&quot;<br>        uses: actions/checkout@v2<br><br>      - name: &quot;Run :: Docker Compose&quot;<br>        run: |2-<br>              docker-compose -f ${{env.DOCKER_COMPOSE_FILE_PATH}} build &amp;&amp; docker-compose -f ${{env.DOCKER_COMPOSE_FILE_PATH}} up -d &amp;&amp;<br>              ${{env.ADDITIONAL_COMPOSE_COMMANDS}}<br>              docker-compose -f ${{env.DOCKER_COMPOSE_FILE_PATH}} down -v<br><br>  stop-runner:<br>    name: Stop Runner<br>    permissions: write-all<br>    runs-on: ubuntu-latest<br>    needs:<br>      - start-runner<br>      - compose-job<br>    if: ${{ always() }}<br>    steps:<br>      - name: &quot;Run :: Configure AWS credentials 43f45f27-01f3-4344-b51d-c554e9bc40db&quot;<br>        uses: aws-actions/configure-aws-credentials@v4<br>        with:<br>          role-to-assume: ${{ env.roleARN }}<br>          role-session-name: pipeline-assume-role-session<br>          aws-region: ${{ env.region }}<br><br>      - name: &quot;Run :: Stop AWS Spot Instance&quot;<br>        run: |2-<br>              aws ec2 terminate-instances --instance-ids ${{ needs.start-runner.outputs.EC2_INSTANCE_ID }}<br>              gh_runner_label=${{ needs.start-runner.outputs.EC2_RUNNER }}<br>              response=$(curl -X GET         https://api.github.com/repos/${GITHUB_REPOSITORY}/actions/runners         -H &#39;Authorization: Bearer ${{ env.pat }}&#39;<br>              )<br>              offline_runners=$(echo &quot;$response&quot; | jq &#39;.runners | map(select((.labels? | any(.name == &quot;EC2_RUNNER_${{github.sha}}&quot;))))&#39;)<br>              echo &quot;Offline Runners :: $offline_runners&quot;<br>              <br>              echo &quot;Attempting to remove offline runners...&quot;<br>              for runner in $(echo &quot;$offline_runners&quot; | jq -r &#39;.[].id&#39;); do<br>                echo &quot;Triggering action for runner ID: $runner&quot;<br>                curl -X DELETE         https://api.github.com/repos/${GITHUB_REPOSITORY}/actions/runners/$runner           -H &#39;Authorization: Bearer ${{ env.pat }}&#39;<br>              done</pre><h4>Conclusion</h4><p>There we go. Now you have a GitHub action that creates an EC2 Spot instance, register it as a GitHub self-hosted runner, use the self-hosted instance to run a job and finally terminate it along with the offline Runners in GitHub. Remember to replace the {{env.example}} values with your needed specifications. Hope it helps. Cheers.</p><p>by <strong>Heshan Wickramaratne</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=aef473b8a00f" width="1" height="1" alt=""><hr><p><a href="https://blog.devgenius.io/create-register-and-terminate-ec2-spot-instances-via-github-actions-aef473b8a00f">Create, Register and Terminate EC2 Spot Instances via GitHub actions</a> was originally published in <a href="https://blog.devgenius.io/">Dev Genius</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Advanced JOI schema validation with Generics and Inheritance]]></title>
            <link>https://blog.devgenius.io/advanced-joi-schema-validation-with-generics-and-inheritance-efd28aea88e3?source=rss-336c28b6feda------2</link>
            <guid isPermaLink="false">https://medium.com/p/efd28aea88e3</guid>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[joi]]></category>
            <category><![CDATA[generics]]></category>
            <category><![CDATA[inheritance]]></category>
            <category><![CDATA[validation]]></category>
            <dc:creator><![CDATA[Heshan Wickramaratne]]></dc:creator>
            <pubDate>Sun, 01 Oct 2023 13:32:28 GMT</pubDate>
            <atom:updated>2023-10-01T13:32:28.036Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*U_CIwAJOMRS04rDhqQaveQ.png" /></figure><p>Howdy people 👋. I recently worked on a very interesting piece of code. Based on the requirements, I had to take some important decisions to make the functionality more dynamic. This involved the use of Generic classes, interfaces and inheritance logic. While this made the dynamic logic I needed achievable, it also made validation a tad bit interesting than our usual JOI schema validation.</p><h3>Context</h3><p>I’ll be explaining code related to this specific service I have been working on lately. Therefore, here’s a bit of high level context so you guys understand the problem tackled. This code creates GitHub actions dynamically taking the needed attributes from the request body. A GitHub actions .yaml file has different attributes to it. We’ll be focusing on the <strong>Steps </strong>part of it as seen below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CqI1lRDJBn_-ukdmo_u6jQ.png" /></figure><p>Now some steps, as you can see here uses dynamic values which are populated during run time. (Ex: ${{github.ref}}, ${{github.workspace}} etc.) These values are required to complete the relevant step and what attributes are needed to complete the step depends on the step itself. Let’s call these needed values, <strong>Configs</strong>.</p><h4><strong>Generic Steps</strong></h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3c6d1eca61a9db0812af409b4a8bfc42/href">https://medium.com/media/3c6d1eca61a9db0812af409b4a8bfc42/href</a></iframe><p>Let’s breakdown the code. A step must have a name. The run and uses attributes can be optional (😉see the image I added above which was taken from the official<a href="https://docs.github.com/en/actions/quickstart"> GitHub Docs for actions</a> ).</p><p>Notice how the StepDto class is Generic. This is because the config needed for it would be a Dynamic value passed to it. Just like run and uses attributes, config is also optional for a step.</p><p>Now let’s think of 2 specific steps that require configs. Think of a step to <strong>build a docker image</strong> and a step for a <strong>Trivy Vulnerability scan</strong>.</p><h4>Docker Build Step Config</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1dda828f60151d89c1ed53e0bdb67175/href">https://medium.com/media/1dda828f60151d89c1ed53e0bdb67175/href</a></iframe><p>Now this can be a sample Docker build config for a Docker Build Step. Things get interesting when it comes to a <strong>Trivy scan step</strong> since it <strong>requires a Docker Build before the scan</strong>.</p><h4>Trivy Scan Step Config</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d5adbf4df0094731e4a80729f4e2834f/href">https://medium.com/media/d5adbf4df0094731e4a80729f4e2834f/href</a></iframe><p>Here, we an easily extend to the DockerBuildConfigDto to achieve the functionality we need. Also notice how we can achieve the same inheritance logic for the JOI schemas in line #24 using schema.keys chaining the DockerBuildConfigSchemato the mix. This way your Dtos and Schemas are both nice and neat. TrivyScanConfigSchema here will now validate <strong>scanSeverity</strong>, <strong>usePrevDockerBuild </strong>along with <strong>dockerFileName</strong>, <strong>dockerFilePath </strong>and <strong>imageName</strong>.</p><h4>Validating a Generic Step</h4><p>Now, we can validate a step along with it’s dynamic config using the Generic StepDto class.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/efa91a36ea3c700f64b9a5ad0ef73280/href">https://medium.com/media/efa91a36ea3c700f64b9a5ad0ef73280/href</a></iframe><p>A <strong>step</strong> in this context as passed in line #1 and #2 can be an instance of type <strong>StepDto&lt;T&gt;</strong> as we defined earlier. I have made sure that these steps passed here are of StepDto type by using another schema for the entire service endpoint request which is not entirely relevant to this article here. But in case you are curious .</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xN1xPfWyiXv68QcwnxDPsg.png" /></figure><h3>Conclusion</h3><p>JOI is a very powerful validation library and the reason I wrote this article is because I got the need to use it in a very different way than how I’ve usually been using it (At least this was the case for me 😉). Since you took the time to read it, I hope you learnt something interesting out of it.</p><p>Cheers 🍻.</p><p><em>by, </em><strong><em>Heshan Wickramaratne</em></strong><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=efd28aea88e3" width="1" height="1" alt=""><hr><p><a href="https://blog.devgenius.io/advanced-joi-schema-validation-with-generics-and-inheritance-efd28aea88e3">Advanced JOI schema validation with Generics and Inheritance</a> was originally published in <a href="https://blog.devgenius.io/">Dev Genius</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Generic JOI Validation Pipes with NEST.JS]]></title>
            <link>https://blog.devgenius.io/generic-joi-validation-pipes-with-nest-js-7dbb819a3c45?source=rss-336c28b6feda------2</link>
            <guid isPermaLink="false">https://medium.com/p/7dbb819a3c45</guid>
            <category><![CDATA[schema]]></category>
            <category><![CDATA[validation]]></category>
            <category><![CDATA[nestjs]]></category>
            <category><![CDATA[joi]]></category>
            <category><![CDATA[typescript]]></category>
            <dc:creator><![CDATA[Heshan Wickramaratne]]></dc:creator>
            <pubDate>Fri, 29 Sep 2023 13:31:34 GMT</pubDate>
            <atom:updated>2023-09-29T13:31:34.207Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mde5Fqjmr4UYSfHzB8BvGw.png" /></figure><p>Hey guys 👋. This is going to be a short article on a neat little trick that I started using when validating requests with JOI and NEST.JS. This is done using PIPES. Now according to the official docs from NEST…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jrQ8HC6kFFC8srwM3hUe4Q.png" /></figure><p>Our use case is the 2nd one. Let’s start by creating the Generic <strong>ValidatorPipe </strong>class<strong>.</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/050b05468886ee41d5189af053e76670/href">https://medium.com/media/050b05468886ee41d5189af053e76670/href</a></iframe><p>Important thing to note in the above piece of code is that we have defined this class as a Generic one. This is the same as defining the class as ValidatorPipe&lt;T&gt; which is the common pattern. Instead, I’ve named the generic type as Dto since it’s more aligned with what we are using this for. You’ll see why in a second.</p><p>Now all you have to do is define the needed Dtos and JOI validation schemas. An example would be something like this.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d596e64f99098ff38c9bf120d80e8b5d/href">https://medium.com/media/d596e64f99098ff38c9bf120d80e8b5d/href</a></iframe><p>Taking this same example of creating a user, this is how you would validate the request body from the <strong>controller </strong>in NEST.JS</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a96a385f20749b8b3e56fa89eba5e8d3/href">https://medium.com/media/a96a385f20749b8b3e56fa89eba5e8d3/href</a></iframe><p>As seen in line #14, you can validate any endpoint against a predefined Dto and Schema.</p><p>Cheers 🍻</p><p><em>by, </em><strong><em>Heshan Wickramaratne</em></strong><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7dbb819a3c45" width="1" height="1" alt=""><hr><p><a href="https://blog.devgenius.io/generic-joi-validation-pipes-with-nest-js-7dbb819a3c45">Generic JOI Validation Pipes with NEST.JS</a> was originally published in <a href="https://blog.devgenius.io/">Dev Genius</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[I’m a Software Engineer and I did LASIK…]]></title>
            <link>https://medium.com/@iwiick/im-a-software-engineer-and-i-did-lasik-4b0b6dc0e5d0?source=rss-336c28b6feda------2</link>
            <guid isPermaLink="false">https://medium.com/p/4b0b6dc0e5d0</guid>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[lasik]]></category>
            <category><![CDATA[lasik-eye-surgery]]></category>
            <category><![CDATA[life]]></category>
            <category><![CDATA[lasik-surgery]]></category>
            <dc:creator><![CDATA[Heshan Wickramaratne]]></dc:creator>
            <pubDate>Thu, 03 Aug 2023 03:59:59 GMT</pubDate>
            <atom:updated>2023-08-03T03:59:59.932Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZtS0X55Wzc0eycDqRhuQBQ.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@ionfet?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Ion Fet</a> on <a href="https://unsplash.com/images/things/eye?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>The reason that I decided to write this article is because I myself had certain doubts on the whole process and how it would effect my day to day life. Specially as a person who spends a considerable amount of time in front of digital screens. I searched around, talked with some people who already went through the procedure before me and yet failed to get a complete picture as to what all of this would mean. So… here’s everything you need to know based on my personal experience. <strong>I did the surgery in November, 2021</strong>.</p><h4>1. Is the Surgery Painful?</h4><p>The short answer is NO. The surgery it self is not painful at all. As a matter of fact, it is over before you even know it. They will work on one eye at a time, then move on to the next one. <strong>Personally the only irritation I had was with the metal Speculum</strong> when they started on the left eye. I didn’t feel it in my right eye. but I felt a small sting when they used it on my left eye. This is used to keep your eye lids open during the procedure.</p><h4>2. How long does the Surgery take?</h4><p>This completely <strong>depends on the type of LASIK surgery</strong> that is going to be done on your eyes. For me, it was called “LASIK Extra” for both eyes and it took like 30 minutes per eye. Again, the time will fly by so don’t worry.</p><p>What takes time is the preparation process. They numb the eye for hours before going for the procedure. This is done by using a numbing eye drop and they will periodically come and put this to your eyes for a couple of hours before actually proceeding with the surgery.</p><h4>3. Is it risk free?</h4><blockquote><em>“No surgery is risk free. If the preliminary tests are a go, then there is nothing to worry.”</em></blockquote><p>This was what was told to me by the Surgeon who did my surgery. Being a very curious person by nature, I was able to find out that he had a perfect and long successful track record of performing this surgery a large number of patients. 2 of whom were close friends that highly recommended him.</p><p>Considering all these and some intense google searches on more information, I decided to move forward with the surgery.</p><p>Also, it was advised to do the preliminary tests as close to the surgery date as possible so they will have the most recent data.</p><h4>4. What are the preliminary tests?</h4><p>So there are a couple of preliminary tests that the doc will ask you to do before the surgery. And he will only advice you to do the surgery if the results are green. These were to test the cornea thickness and some others.</p><h4>5. Will I see things properly right after?</h4><p>Answer is yes and no. For a few seconds after the surgery was done (per eye), I was able to see things crystal clear for the first time in my life. I have been putting spectacles since I was 4. But, everything will become blurred very quickly because your eye will be very dry due to the healing process. My vision came back little by little within 2 weeks.</p><blockquote>“Your vision will get clearer up to like 80% within 2 weeks. Rest can take up to 3 months or longer ”</blockquote><p>Again, something told to me by my doc. My personal experience was the same as he foretold.</p><h4>6. What are the first 2 weeks like?</h4><p>The first 2 weeks according to my doctor was the most critical recovery period. During this time, I was asked to stay away from digital screens. Knowing this, I got 2 weeks medical leave approved for 14 days from my workplace from the day of the surgery.</p><p>This period of time was actually quite annoying and uneventful. Personally, I spent these 14 days sleeping or listening to the radio (You guys have no idea how many radio stations repeat the same song multiple times within the same 24 hours). My eyes were super dry during these days and it was irritating most of the time. Moreover, I was given a pair of small plastic eye shields which I had to put on my eyes before going to sleep in order to avoid accidentally squashing them on the pillow when I turn to the sides. After a couple of days, this gets annoying as well, but it was only for these 14 days.</p><p>Then we have the eye drops. I was given around 4 types of eyes drops which I had to put every 2 hours during these 2 weeks. The interval between times you need to put eye drops change as you go to appointments with your doctor where he will update you on these changes.</p><p>Finally, I was told to avoid getting soap or any other products on my eyes during these 2 weeks. Also, you are not allowed to rub your eyes. (Bad news if you are used to rubbing your eyes in the morning when you wake up)</p><h4>7. Life after 2 weeks ?</h4><p>I was asked to come back to see the doc after 2 weeks. This was when I was told that I no longer needed the eye shield when I sleep (Thank God!). And… this was also when the doc removed the protective lenses they put on my eyes. After they do the surgery they will place a protective contact lens sought of thing on your eyes. For me, they removed this after the first 2 weeks.</p><p>After 2 weeks I got most parts of my sight as told before. But the dry eyes + the course of eye drops remained. Since my 2 weeks digital detoxing was over, what I did was, I configured daily reminders for my eye drops on my phone. This was really help full since I also started back work and it’s easy to get distracted completely forgetting the eye drops.</p><p>I had an appointment with the doctor every month for a few months, then every 2 months, every 3 months and final after 6 months etc. During these visits, the eye drop schedule and the amount of eye drops I had to put was changed. I started from putting 4 types of eye drops every 2 hours. As I’m writing this article, I’m putting 1 type of eye drop 2 times a day, once in the morning and once at night (And yes, I’m still using eye drops after almost 20 months for dry eyes).</p><blockquote>In case you are a swimmer like me, I was told to stay away from public pools for the first 3 months and to always use goggles after wards till an year. This was the longest pause I’ve had from swimming after doing the sport for almost 18 years now.</blockquote><h4>8. Back to work ?</h4><p>The first couple of months were the worst in terms of dry eyes. As you might already know, looking at digital screens worsens dry eyes and starting back work did just that for me. There were times I was waiting for the phone to buzz with the reminder for eyes drops. Each time you put a drop, your sight clears up only to slowly get blurred over time till the next drop. The dry eyes get better as the months pass by so don’t worry.</p><p>Personally, I had this experience during the first month where my eyes were like old cameras. When I look at the laptop screen, it’s slightly blurred, but within a few seconds while I keep looking at it, it gets focused. Then when I look away from the laptop, everything else it blurred and after a few seconds that becomes clear and vise versa.</p><p>Moreover, my eyes started getting dried faster working towards the evening which according to my doctor was quite natural.</p><h4>9. 20–20–20 Rule ?</h4><p>This was something suggested by my doc. It made all the difference when I started practicing looking 20 feet away for 20 seconds every 20 minutes. This might sound like a hassle, but this means you will look away from the computer screen for a total of one minute every 1 hour which surprising helps with dry eyes as well as to rest them. TRUST ME. This makes a huge difference. Personally, even for this I put reminder every 20 minutes in my phone starting from 9am till 6pm.</p><blockquote>I had a LOT of reminders during this recovery period. 20–20–20 eye reminders + the eye drop reminders. There are some very helpful apps for the 20–20–20 reminder in app/play store as well</blockquote><h4>10. Blue Light Filtering Specs ?</h4><p>Yes. I did LASIK surgery to avoid putting spectacles and this sounds like an overkill. But… using blue light filtering spectacles is a smart move. Make sure you buy a high quality blue light filtering spectacle because this also makes a huge difference. As Software Engineers, we spend a lot of time in front of digital screens and this will help with dry eyes and eye strain.</p><p>Even I was reluctant to buy spectacles again after surgery even though my doc urged me to after like 3 months from surgery. When I finally did… everything made sense. A proper blue light filtering pair of specs is god given during day to day work. It immensely helped with my dry eyes and it will help you as well.</p><h4>11. Eye drops ?</h4><p>In our field, we would have to continue with these for quite sometime according to my doc and this is mainly for dry eyes. Like I’ve said earlier, I’m on my 20th month post surgery and I’m still using an eye drop called “Systane Ultra” which is a lubricant for dry eyes. I have two more months before I was told to stop this.</p><p>At this point, the peek dry eye moments I have are the mornings when I wake up. Even these are not as bad as it used to be. Dry eyes for me now is more of a slight irritation instead of blurred vision.</p><p>I sought of kept my empty eye drops as a way to see how the time went by. So here they are for you to get an idea :)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*S7N1Z_YP187ZNc8K9Ch3wA.jpeg" /><figcaption>Eye drops after the first 2 weeks</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3X37_keLJzvkeRMS1uBvhg.jpeg" /><figcaption>Eye drops after 1 month</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iJvrNbknZibJCDksQX7Mdw.jpeg" /><figcaption>Eye drops after 12 months</figcaption></figure><p>And yes, I have even more now ;)</p><h4>Conclusion</h4><p>Hopefully, this article helped you to have an understanding about LASIK from the perspective of a person who already went through it. If you have any questions, do let me know in comments. Adding to what I have mentioned so far, doing LASIK was one of the best decisions I’ve taken.</p><p>Cheers 🍻</p><p><em>by, </em><strong><em>Heshan Wickramaratne</em></strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4b0b6dc0e5d0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Hosting your MySQL database in an AZURE Virtual Machine.]]></title>
            <link>https://blog.devgenius.io/hosting-your-mysql-database-in-an-azure-virtual-machine-f09d40bbb242?source=rss-336c28b6feda------2</link>
            <guid isPermaLink="false">https://medium.com/p/f09d40bbb242</guid>
            <category><![CDATA[git]]></category>
            <category><![CDATA[microservices]]></category>
            <category><![CDATA[azure]]></category>
            <category><![CDATA[virtual-machine]]></category>
            <category><![CDATA[mysql]]></category>
            <dc:creator><![CDATA[Heshan Wickramaratne]]></dc:creator>
            <pubDate>Fri, 07 Apr 2023 20:07:00 GMT</pubDate>
            <atom:updated>2023-04-12T06:32:58.678Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*f7XjfF9Gc8msp0vS_QoOHg.png" /></figure><p>In one of my <strong>earlier articles</strong>, I explained how you can host your Node.js application in a Virtual Machine hosted in Azure. I explained how you can <strong>connect to a VM</strong> as well as a handy way you can t<strong>ransfer files from your local device to the Virtual machine.</strong> Now lets see how you can import you locally built MySQL database to a Virtual Machine. You will need the <a href="https://www.mysql.com/products/workbench/">MySQL Workbench</a> if you don’t have it already.</p><h4>Step 01 — Exporting the Database.</h4><ul><li>Log into you MySQL local instance.</li><li>Then select export data option from the Server Menu.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cjUrA78n44uPweCBhf7vXA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*P_wNYbr40udHJr5A-JSjMg.png" /></figure><ul><li>Select the Database you need to export and the needed tables in it.</li><li>Select whether you are going to <strong>Dump the table structures and data</strong>, <strong>Just the table structures</strong> or<strong> just the table data</strong> from the drop down menu.</li><li>Tick Export to <strong>Self-Contained File</strong> and select an output location.</li><li>Tick <strong>Single Transaction</strong> and <strong>include Create Schemas</strong> as well.</li><li>So far you have been in the Object Selection Tab.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VZFqTxfZ-uFbtXHvh9HW8Q.png" /></figure><ul><li>Click on <strong>Export Progress</strong> tab and <strong>start Export</strong>.</li></ul><h4>Step 02— Move the .sql file to your VM</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*co61L4T1PwqDVjfzj0NdjQ.png" /></figure><ul><li>After exporting, you should have a .sql file like this.</li><li>Get this file into your VM. (I have explained here, how you can get your Node JS files to the VM. This is just one possible way while there are others. Feel free to try things out 😄).</li></ul><h4>Step 03— Configuring MySQL server in the VM.</h4><ul><li>Now let’s configure the MySQL Server in your Virtual Machine.</li><li>Install the MySQL Server. sudo apt-get install mysql-server</li><li>At the start, your root account won’t have a password. You can access your SQL server as an admin by, sudo mysql</li><li>Now lets add a new password to your root account.</li><li>SELECT plugin FROM mysql.user WHERE User = ‘root’;</li><li>UPDATE mysql.user SET plugin = ‘mysql_native_password’ WHERE User = ‘root’;</li><li>SELECT plugin FROM mysql.user WHERE User = ‘root’;</li><li>FLUSH PRIVILEGES;</li><li>ALTER USER ‘root’@‘localhost ’ IDENTIFIED BY ‘&lt;new_password&gt;’</li><li>If needed, you can restart the server by using sudo systemctl restart mysql.service</li></ul><blockquote>Note: Make sure you add the “;” after all the SQL statements 😉</blockquote><h4>Step 04 —Import the MySQL Database.</h4><ul><li>After restarting, you can log back into the SQL server by, mysql -u root -p</li><li>Create a new Database by, CREATE DATABASE &lt;enter_database_name_here&gt;;</li><li>Import the Database by, USE path/to/&lt;your_exported_sql_file&gt;.sql; An example, my exported file is named whysoserious_db. So, if i’m currently in the same folder as this file, I would enter USE whysoserious_db.sql;</li><li>An alternative way to do this is USE &lt;database_name&gt;; then SOURCE &lt;path/to/&lt;your_exported_sql_file&gt;.sql&gt;;</li><li>Again, remember the “;” after each SQL statement.</li></ul><h4>Step 05 — Test your Database.</h4><ul><li>The simplest way. Do a query and see whether you exported Database was imported successfully.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Pv7881LFnSuiziTolnsMaw.png" /></figure><h4>Conclusion.</h4><p>That’s it folks. Do checkout my other articles if you find some time 😄. Till next time, happy coding 👋</p><h4>Related Articles.</h4><ul><li><a href="https://blog.devgenius.io/hosting-node-js-backend-in-azure-using-windows-part-01-33d09803fc72">Hosting Node.js Backend in Azure using Windows (Part 01).</a></li></ul><p>by, <strong>Heshan Wickramaratne</strong>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f09d40bbb242" width="1" height="1" alt=""><hr><p><a href="https://blog.devgenius.io/hosting-your-mysql-database-in-an-azure-virtual-machine-f09d40bbb242">Hosting your MySQL database in an AZURE Virtual Machine.</a> was originally published in <a href="https://blog.devgenius.io/">Dev Genius</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Hosting Node.js Backend in Azure using Windows (Part 02).]]></title>
            <link>https://blog.devgenius.io/hosting-node-js-backend-in-azure-using-windows-part-02-60d6216967cd?source=rss-336c28b6feda------2</link>
            <guid isPermaLink="false">https://medium.com/p/60d6216967cd</guid>
            <category><![CDATA[microservices]]></category>
            <category><![CDATA[azure]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[containers]]></category>
            <dc:creator><![CDATA[Heshan Wickramaratne]]></dc:creator>
            <pubDate>Thu, 06 Apr 2023 20:06:55 GMT</pubDate>
            <atom:updated>2023-04-07T03:53:16.439Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hNqF21_LEe9SmjcY2lCobQ.png" /></figure><p>In the <a href="https://medium.com/dev-genius/hosting-node-js-backend-in-azure-using-windows-part-01-33d09803fc72"><strong>previous article</strong></a>, we learnt how you can host your Node application in a Virtual Machine hosted in Azure. In this article, lets learn how we can use Azure Container Instances to do that 😉.</p><h3>Hosting in a Container Instance.</h3><h4>Step 01 —Install Docker.</h4><ul><li>You can download Docker from their official Website found <a href="https://www.docker.com/">here</a>.</li><li>Install and log into your docker account.</li><li>If you are using Docker for the first time, you might get a notification from docker when you login saying <em>“The current user is not in the ‘docker-users’ group. Add yourself to the ‘docker-users’ group and then log out and back in to Windows</em>.”.</li><li>You can fix this by opening the cmd as an Admin.</li><li>Type net localgroup docker-users “your-user-id” /ADD</li><li>Don’t forget the Inverted commas. They are needed.</li><li>Log out and log in back to your account and you should be able to login to your Docker Desktop Application.</li></ul><h4>Step 02— Create the Dockerfile in your project.</h4><ul><li>Now create a “Dockerfile”in your project root. This does not have a file extension if you were wondering that 😉.</li><li>Add the configuration as follows.</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/03c70199548d36b281085131cf51571e/href">https://medium.com/media/03c70199548d36b281085131cf51571e/href</a></iframe><blockquote>Note: You don’t have to install nodemon unless you need it. You can remove that line an Change line 15 to be something like CMD [“npm”, “run”, “start”] where you have a npm script configured in your package.json.</blockquote><ul><li>Add another script to your package.json file to create Docker Images with this command, docker build -t &lt;name_of_your_image&gt;:latest .</li><li>I have named my script as “<strong>build-docker-image</strong>”.</li></ul><blockquote>Note: Don’t forget the “.” at the end of that command 😉 and make sure you add the :latest part to it aswell. This serves a very specific purpose.</blockquote><ul><li>My package.json now looks like this.</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/130f7f820b878684e3294b54dc6a7a1b/href">https://medium.com/media/130f7f820b878684e3294b54dc6a7a1b/href</a></iframe><h4>Step 03 — Create a Docker Image.</h4><ul><li>Make sure the Docker Desktop application is open.</li><li>Then type npm run build-docker-image . (or what ever you named your script as)</li><li>It might take a few seconds, but once done, you will see the Image file in your Docker Desktop Application.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*l57oUdbWdonGPFyeMy0MMQ.png" /></figure><ul><li>“whysoserious_mjs_image” is the name I put to my image file from the script we created in the package.json file. So you should have something here that has the name you put in your script.</li><li>You can click Run in the actions column as see if the Image works as expected in a Docker container.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pdRvOijRze8jRfwCE1emrQ.png" /></figure><h4>Step 04 — Create a Container Registry.</h4><ul><li>Go to your Azure portal and create a new Container Registry as a new Resource. Or you can use an existing one.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cS-ZC9b2GLvO1a8a9XVBwA.png" /></figure><ul><li>Configure the details as needed.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EE4hyYIfTvJWNYsrxTZYbg.png" /></figure><ul><li>Finally Create it.</li><li>Give a few seconds for the resource to be created. Then go to the resource → Access Keys</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2YjH06OgD7o5JmbJGrvyMg.png" /></figure><ul><li>Enable Admin User. Now you should be able to see the Admin Username and passwords.</li><li>Take note of the <strong>Login server</strong>, <strong>username </strong>and <strong>password</strong>.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FNPB84AZSptRK6W_gpBOOg.png" /></figure><ul><li>Open Command prompt and login to the Registry by, docker login &lt;login_server&gt; -u &lt;username&gt; -p &lt;password&gt;</li><li>Tag the image you are going to add to the Registry by, docker tag &lt;image_name&gt; &lt;login_server&gt;/&lt;image_name&gt; . For me this would be like docker tag whysoserious_mjs_image:latest &lt;my_login_server&gt;/docker tag whysoserious_mjs_image:latest</li><li>After this, your Docker Desktop should look something like this.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EtwRLO5EvyO4HgLQ52w8lw.png" /></figure><ul><li>Finally we can push the image to the Registry by, docker push &lt;login_server&gt;/&lt;image_name&gt;</li><li>You should be seeing a screen like this if everything went smooth.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sXoskhylZ4xvh4xXxmRhsw.png" /></figure><ul><li>Once everything is done, you can go to your Container Registry in Azure and Check under Repositories.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sLY4EByPIoAIaH962xzkQA.png" /></figure><h4>Step 05— Create a Container Instance.</h4><ul><li>Now create a new Container Instance as a Resource in you Azure Portal.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FSxMqv-DFKpPGhf1wH9VqQ.png" /></figure><ul><li>Select you registry, the image and the tag.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*j8_cublP_AZeFDrFXEaeRw.png" /></figure><ul><li>Configure <strong>DNS label</strong> and make sure to <strong>add the proper port you defined in your node application as an inbound TCP port</strong>.</li><li>My Node.js Server listens on port 3002. Double Check your root JS file for yours 😉.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QZfZL1Ma8q83LAuLAtSnaA.png" /></figure><ul><li>Finally Create your container Instance 🔥.</li></ul><h4>Step 06 —Access you Node js server.</h4><ul><li>You can access you server by, <a href="https://whysoserious-moderatejokesservice.grexfqdgg6fxhugz.centralindia.azurecontainer.io:3002/api/moderateJoke/">https://&lt;container_instance_dns&gt;:&lt;port_you_defined&gt;/api</a></li><li>You can also access it via the public IP address by, <a href="https://whysoserious-moderatejokesservice.grexfqdgg6fxhugz.centralindia.azurecontainer.io:3002/api/moderateJoke/">https://&lt;container_instance_public_ip&gt;:&lt;port_you_defined&gt;/api</a></li></ul><h4>Conclusion.</h4><p>That is pretty much it. When we create container images, we can use tags to push multiple images to the container registry. With the “latest” tag. we can push the same image multiple times to the container registry while the container instance always takes the latest image from the registry.</p><p>Cheers, till the next article 👋</p><h4>Related Articles</h4><ul><li><a href="https://medium.com/dev-genius/hosting-node-js-backend-in-azure-using-windows-part-01-33d09803fc72">Hosting Node.js Backend in Azure using Windows (Part 01)</a></li></ul><p>by, <strong>Heshan Wickramaratne</strong>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=60d6216967cd" width="1" height="1" alt=""><hr><p><a href="https://blog.devgenius.io/hosting-node-js-backend-in-azure-using-windows-part-02-60d6216967cd">Hosting Node.js Backend in Azure using Windows (Part 02).</a> was originally published in <a href="https://blog.devgenius.io/">Dev Genius</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Hosting Node.js Backend in Azure using Windows (Part 01).]]></title>
            <link>https://blog.devgenius.io/hosting-node-js-backend-in-azure-using-windows-part-01-33d09803fc72?source=rss-336c28b6feda------2</link>
            <guid isPermaLink="false">https://medium.com/p/33d09803fc72</guid>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[git]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[virtual-machine]]></category>
            <category><![CDATA[azure]]></category>
            <dc:creator><![CDATA[Heshan Wickramaratne]]></dc:creator>
            <pubDate>Wed, 05 Apr 2023 12:29:26 GMT</pubDate>
            <atom:updated>2023-04-12T06:33:48.223Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sw8Yf8XDcorMMqzWHJd8YQ.png" /></figure><p>I will be explaining 2 easy ways you can host your <strong>Node.js</strong> back end in <strong>Azure </strong>using your Microsoft <strong>Windows </strong>Computer. I will walk you through on how you can use…</p><ol><li>Azure Virtual Machines.</li><li>Azure Container Instances</li></ol><p>… to achieve this. Both methods require an Azure account so you can log into your <a href="https://portal.azure.com/">Azure Portal</a> using it 😉. Part 01 of this article which you are currently reading is focused on how you can deploy your Node js application in a Virtual machine hosted in Azure. Part 02 which you can find <strong>here </strong>explains how you can host your Node js application in a Container Instance.</p><p>Also, if you want to find out how you can Export your local MySQL database to your Virtual machine and set it up there, you can read the article right <strong>here</strong>. 🙌</p><h3>Hosting in a Virtual Machine.</h3><h4>Step 01 — Create a new Virtual Machine.</h4><ul><li>In your Azure portal, go to <strong>Create a resource</strong> Option and find the <strong>Virtual Machine</strong> Service</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_aMRYgXsHdt_jdUMoayS9w.png" /></figure><ul><li>Then click <strong>Create</strong> in Virtual Machine.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kvrewGX6eSn0wUmqwIkQNg.png" /></figure><ul><li>Complete the needed information for creating a new Virtual Machine.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QkVC0DDOKV7NRJyHzbnUHA.png" /></figure><ul><li><strong>Resource Group: </strong>is a way for you to group your services in Azure. Say that you have two virtual machines for some project that you are doing. then you can create a new Resource Group with a <strong>name</strong>. Then you can select the same Resource group in all the services you create for this project.</li><li><strong>Virtual Machine Name:</strong> Put a name for you Virtual machine. I have named mine as “UserService”.</li><li><strong>Region</strong>: Select the one closest to where you intend to use you node.js server from.</li><li><strong>Image:</strong> This is what your VM is going to use as the Operating system. So select a Linux based one like Ubuntu.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jNUN8QHiium6wS_7KwZCow.png" /></figure><ul><li><strong>Authentication Type:</strong> Select SSH for this.</li><li><strong>Username:</strong> This will be the username when you connect to the VM.</li><li><strong>SSH Public key source:</strong> Select “generate new key pair”.</li><li><strong>Inbound Ports:</strong> keep the SSH 22 port. DO NOT REMOVE IT.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lM8Wob4w2M8UWXcEnoAwhg.png" /></figure><ul><li>Keep the defaults in the Network tab unless you are serious on what you are doing 😉.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7YotVruJ74kCRfYdn-GMNw.png" /></figure><ul><li>Select a timezone and put your email if you are planning on configuring auto shutdown.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dyydBekbBtnGMcc8yDlsGg.png" /></figure><ul><li>Finally <strong>Create</strong> the VM 🙌.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*V2lq3lClEJr2LNeQ-v0Tiw.png" /></figure><ul><li>You will get a popup modal like this. Click <strong>Download private key and create resource</strong>.</li><li>Give a few seconds for the resource to be created.</li></ul><h4>Step 02 —Configure the VM.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GvjvJueG4qOQFjbxA6wu3g.png" /></figure><ul><li>Then <strong>Go to resource</strong>.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0jRjoKSuYWfWls8YbRyLvA.png" /></figure><ul><li>You should be seeing something like this. Go to <strong>DNS name</strong> and put a unique name you can identify from. This will be part of the Base URL once the server is hosted.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kFFjx6obd_JHJQRnDqaZAA.png" /></figure><ul><li>So put something meaningful like this.</li><li>Go to the <strong>Network </strong>aside menu.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*w6UoO1zwEnfrPI67OGYJgw.png" /></figure><ul><li>Now check whether you have the port defined in you node.js project present here. If you are using Express (Highly unlikely you are not), this would be the port defined to listen on. So g<strong>o back to your code and make sure you copy the correct port number</strong> :)</li><li>Click on <strong>Add inbound port rule</strong>.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*e7uq2fTh8ny88Zh0XxJ4bQ.png" /></figure><ul><li>Configure as seen in the picture and add the port number under <strong>Destination port ranges</strong> :)</li></ul><h4>Step 03— Connect to the VM from your local machine.</h4><ul><li>Now, remember the key file we downloaded ?. Cut and paste that file in a new folder. name the folder something like “Connect to VM” :). Just a suggestion.</li><li>Then create a <strong>.bat </strong>file. I named mine as “connect”</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Zy6RbOMWSHFbdWoAbvHubQ.png" /></figure><ul><li>If you are not familiar with creating bat files. you can easily create one by creating a new .txt file (Notepad file) then rename the .txt extension as .bat 😉.</li><li>Right click and click “edit” option of the bat file.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qXgJR75SRk95ulD27T_QTA.png" /></figure><ul><li>From you VM’s <strong>Connect </strong>aside tab. copy the last command.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*e8w68nh2QqqPUS0sibflog.png" /></figure><ul><li>Paste that inside the .bat file and replace &lt;private key path&gt; with your key file name like this. Save it.</li><li><strong>Double click the connect.bat</strong> file to run it and see if it works. If you get a terminal with information about your VM, then all is good you can skip to Step 04. But if you get an error saying “Bad Permissions” or if the terminal suddenly closes, then read on 😉.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PYcAtQ0K1f8qcL_Plelr0Q.png" /></figure><ul><li>Right click on the <strong>key file → properties → security tab → Advanced</strong>.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7B4-rTr1jQVbv57_7Tw95Q.png" /></figure><ul><li>then <strong>Disable Inheritance</strong>.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*34XGQYMS97di4fy6DZTTAQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VvRUjytwIG6UZPTiNo5zPg.png" /></figure><ul><li>Click on each Principal on the list <strong>EXCEPT ADMINISTRATORS</strong> and remove each entry.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RB7knpk3A7ndxOfCBE50fg.png" /></figure><ul><li>Click <strong>Add </strong>to create a new Principal.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VwboLIYIqjhOCzHxMwe59Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uN9ISD8w19caxC8SfoXvcg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-Wh89LJOtQxf0KhtRuhgow.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RaKyC8UHFtl-YOYUnCLRVA.png" /></figure><ul><li>Find you <strong>current windows account</strong> that you are logged in.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IWbgNCBn_oxxCbXdy9DdzA.png" /></figure><ul><li>Give full control over the file and hit OK.</li><li>Now Double click on the key.bat file. You will get a message like this when you click for the first time.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xGpK-RDkgVeIWN1L9TRxNQ.png" /></figure><ul><li>Type “<strong>yes</strong>” and continue.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EHKWlTesYQMv1hhLcIPZvA.png" /></figure><ul><li>You should get a terminal like this if you followed the steps properly. You are now connected to the VM from you local machine 🔥.</li></ul><h4>Step 04 —Installing required modules in your VM.</h4><ul><li>Now for some familiar work 😉.</li><li>Update the OS: sudo apt-get update</li><li>Install Node Js: sudo apt-get install nodejs</li><li>Install npm: sudo apt-get install npm</li><li>Install git: sudo apt-get install git</li><li>Install Nodemon: sudo npm install -g nodemon</li><li>Now check you Node.js version in your local machine. because you did your development in that version right. so it’s better to update the version in your VM to that same version. you can find your node version if you open CMD and type node -v</li><li>Then globally install “n” in the VM: sudo npm install -g n</li><li>the update the node version by sudo n &lt;desired_node_version&gt;</li></ul><h4>Step 05 — Getting you project files in the VM.</h4><ul><li>There are different ways of doing it, but the easiest way is with Git and GitHub. <strong>This might not be the most ideal or the SAFEST way, but it IS the fastest </strong>😉.</li><li>Now you might be working on a Private Git repo with .env files and secrets etc. So what you can do is quickly create a <strong>temp Public GitHub Repo</strong>.</li><li>Make a copy of your entire Node project,initialize an empty repo, add remote origin of the temp GitHub repo, add, commit and Push your code do it. Copy the URL.</li><li>In you VM terminal, do a git clone &lt;repo URL&gt;.</li><li>Then <strong>DELETE THE TEMP REPO</strong> 😉</li><li>Voilà! you have your node project in your VM now.</li><li>Go into the project and do an npm i to install the modules.</li><li>Then start the server with node index.js, node server.js or npm run dev for nodemone etc. What ever your poison is 😄.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qLOL7TOwvypThOmMfB48Mw.png" /></figure><ul><li>Now your ealier Local hosted URL for accessing your server was something like <a href="https://localhost:3001/api/deliverJoke/">https://localhost:3000/api/</a> right.</li><li>Instead, Copy the DNS you configured for the VM and the port to change the URL like this.</li><li>https://<strong>&lt;dns_configured_for_your_vm&gt;</strong>:<strong>&lt;inbound_port_we_created_in_the_vm&gt;</strong>/api</li><li>That’s it. you have now deployed your node project to a Virtual Machine hosted in Azure 🍹.</li></ul><blockquote>Note: I installed “Nodemon” because i needed it for something I was doing. You don’t have to install it in your VM unless you require it for something :)</blockquote><blockquote>Also note that configuring the DNS is not required. You can also connect to you backend using you public Ip address like, https://<strong>&lt;public_ip&gt;</strong>:<strong>&lt;inbound_port_we_created_in_the_vm&gt;</strong>/api</blockquote><blockquote>I am using <strong>https </strong>requests since I have configured my node server to use that by installing the “https module”. If you are only using express for the routes, then the URL would be <strong>http </strong>:)</blockquote><h4>Step 06 — Wait, I though it was over in Step 05 😉.</h4><p>Nope. There is one last thing we have to do. With the configuration we have now, you will always have to connect to your Virtual machine and execute the Run command (Ex: node index.js etc.) everytime you restart or stop and start the server. Which is a nuisance. You should be able to just start the Virtual machine from the Azure portal and the Node js application hosted there should start automatically right after. Lets configure that.</p><ul><li>Connect to your VM. (Use the bat file if that wasn’t obvious 😉)</li><li>Globally Install pm2. npm i pm2</li><li>Change directory into you project source.</li><li>Start pm2. pm2 start index.js or pm2 start server.js or pm2 start &lt;what_ever_you_named_your_file.js&gt;</li><li>Type pm2 startup</li><li>Copy the command you get in the next line as a result from the previous command.</li><li>Execute that command.</li><li>Finally synchronize everything by pm2 save</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4EfyIn4WTs3sf4Eu3m8AWg.png" /></figure><ul><li>You should see a screen like this if everything went smooth :)</li></ul><h4>Conclusion.</h4><p>That is pretty much it. Few things to remember. If you are not using your Virtual machine, you can stop it from the Azure portal. This will reduce the billing cost though it does not completely stop billing. This is because you are still billed for other resources allocated for the VM like Disks.</p><p>The key.pm files and the bat file we used to connect to the VM should be in a secure place. Secure as in it should only be used by YOU. If someone else gets hold of it, they can pretty much do anything with your Virtual machine and the code hosted there.</p><p>Thanks for reading, see you in the next article 👋.</p><h4>Related Articles.</h4><ul><li><a href="https://medium.com/dev-genius/hosting-node-js-backend-in-azure-using-windows-part-02-60d6216967cd">Hosting Node.js Backend in Azure using Windows (Part 02)</a></li><li><a href="https://blog.devgenius.io/hosting-your-mysql-database-in-an-azure-virtual-machine-f09d40bbb242">Hosting your MySQL database in an AZURE Virtual Machine.</a></li></ul><p><em>by, </em><strong><em>Heshan Wickramaratne</em></strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=33d09803fc72" width="1" height="1" alt=""><hr><p><a href="https://blog.devgenius.io/hosting-node-js-backend-in-azure-using-windows-part-01-33d09803fc72">Hosting Node.js Backend in Azure using Windows (Part 01).</a> was originally published in <a href="https://blog.devgenius.io/">Dev Genius</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>