<?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 Linu Bajy on Medium]]></title>
        <description><![CDATA[Stories by Linu Bajy on Medium]]></description>
        <link>https://medium.com/@linumary?source=rss-4241788cb946------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*HMdERTXSeTPyQFI4YnjGJA.jpeg</url>
            <title>Stories by Linu Bajy on Medium</title>
            <link>https://medium.com/@linumary?source=rss-4241788cb946------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 14:55:12 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@linumary/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[Local Setup and Implementation of SonarQube]]></title>
            <link>https://linumary.medium.com/local-setup-and-implementation-of-sonarqube-23bdd326f387?source=rss-4241788cb946------2</link>
            <guid isPermaLink="false">https://medium.com/p/23bdd326f387</guid>
            <category><![CDATA[sonarqube]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[sonarscanner]]></category>
            <dc:creator><![CDATA[Linu Bajy]]></dc:creator>
            <pubDate>Sat, 09 Sep 2023 21:21:34 GMT</pubDate>
            <atom:updated>2023-09-09T21:36:11.032Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rcgFBRVRHLXqxL_0wj0J4Q.png" /><figcaption><a href="https://www.sonarqube.org/logos/">https://www.sonarqube.org/logos/</a></figcaption></figure><p>Hi all,</p><p>Today, we are discussing about a Static code Analysis Tool called SonarQube.This tool enables us to measure the quality of code. Taking a close look into the logo, see what they’ve done? Nicely put.</p><p><em>So, why is it necessary ?</em></p><ul><li>Ensure that good quality of code goes into Production</li><li>Enables to enforce rules using Quality Gate</li><li>Helps to identify Security Vulnerabilities, Duplications etc.</li><li>Generates a report on the code quality</li></ul><p>Now , lets see how we can do a local setup of Sonarqube and Sonar Scanner.</p><h4>Prerequisites:</h4><ul><li>Java</li></ul><p>Link — <a href="https://www.oracle.com/java/technologies/javase/jdk17-archive-downloads.html">https://www.oracle.com/java/technologies/javase/jdk17-archive-downloads.html</a></p><p>MSI Installer — <a href="https://download.oracle.com/java/17/archive/jdk-17.0.8_windows-x64_bin.exe">https://download.oracle.com/java/17/archive/jdk-17.0.8_windows-x64_bin.exe</a></p><p>Ensure that the Java path is added to the Environment Variables.</p><p>Go to Settings &gt; Edit Environment variables &gt; Add &gt; {path}</p><p>In my case it was : C:\Program Files\Java\jdk-17\bin</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/601/1*tCXTrvF8v0eeYUpvHq-BDg.png" /></figure><h4>Installation Steps — High Level</h4><ul><li>Install SonarqQube — For multiple project reports in a single place</li><li>Install Sonar Scanner — Scanning code</li></ul><p><strong>SonarQube installation</strong></p><p>SonarQube is a software that enables us to view multiple projects along with their Scan Reports. We can setup various Quality gates, fancy term which is basically to setup rules.</p><p>URL :</p><p><a href="https://www.sonarqube.org/downloads/">Download | SonarQube</a></p><p>Once Sonarqube is installed, extract it to a folder :</p><p>sonarqube-10.2.0.77647\bin\windows-x86–64</p><p>Run StartSonar.bat</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4BI1UKbQh5tQuOibA-b2qQ.png" /></figure><p>Now we can see that Sonarqube is up on localhost:9000 , 9000 being the default port.</p><p>For testing, I have added a sample python file to a new directory to store the code. Path — C:\Users\Linu\sonar-python\main.py</p><p><strong>SonarScanner Installation</strong></p><p>Install Sonar Scanner from here :</p><p><a href="https://docs.sonarsource.com/sonarqube/latest/analyzing-source-code/scanners/sonarscanner/">SonarScanner CLI</a></p><p>I have installed it for Windows.</p><p>Now , we need to add the environment variable for sonar-scanner. Just like we did for Java earlier.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/601/1*tCXTrvF8v0eeYUpvHq-BDg.png" /></figure><p>To verify, do <em>sonar-scanner -h</em> from any directory.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/704/1*8gNsTG9u5ZM850OcYnpU3g.png" /></figure><p>In Sonar Scanner, we can see a folder — conf which has a <em>sonar-scanner.properties file</em>. Suppose we want to override some values, we can update the file there.</p><p>For now, I have just added some properties with respect to my Project.</p><p>For sonar.sources , Replace &quot;\&quot; by &quot;/&quot; on Windows.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/537/1*Jq2Ga7xKq6OQF6V-sxOVrg.png" /></figure><p>Now that we have setup SonarQube and sonar scanner, lets go to the SonarQube URL by typing localhost:9000 on the browser.</p><p>It brings up to the homepage of SonarQube. As a first time activity, it will ask us to update password . Next, lets create a project. Select Create Locally option.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HJgjOYL_qIGe7ax09AUjmA.png" /></figure><p>I have given as test-app for both. Ideally you should be giving a meaningful name, but since this was for demo purpose, I am giving as test-app. We can give our custom rule on when the code has to be scanned (based on dates or when new version is uploaded)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EloujQB_NUVLe2FLCRLL1Q.png" /></figure><p>Further on , it would ask for the OS type and the Language used for the code. It then generates a command that you can directly run on the directory where the code is stored. This is an alternative , where you specify the arguments on CLI .</p><p>Next , lets run the sonar scanner.</p><p>Since we have already specified the sonar properties , we can just run sonar-scanner</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-rR8VWKl1jMOqdL2tmAtVA.png" /></figure><p>We can see the code quality output as shown below. Since I have used a simple code just for test purpose , it passed without any issues or vulnerabilities.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CCzk7dm_hTFgAbmqDd02lg.png" /></figure><p>By default sonar way is the default quality gate created and used. Sonar way uses ‘Clean as you Code’ , ensuring highest level of code quality , which is ideal. However, if you want to cut some slack during the initial runs of code, we can create a custom Quality Gate like so. It can even be set to default.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fTSNSlwX3ZdgTDYOWcLljg.png" /></figure><p>Now we know the basics of SonarQube. That’s all for this week . Until next post :)</p><p>Cheers!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=23bdd326f387" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Linux Administration 101]]></title>
            <link>https://linumary.medium.com/linux-administration-101-210f13f36f2c?source=rss-4241788cb946------2</link>
            <guid isPermaLink="false">https://medium.com/p/210f13f36f2c</guid>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[linux]]></category>
            <category><![CDATA[linux-tutorial]]></category>
            <dc:creator><![CDATA[Linu Bajy]]></dc:creator>
            <pubDate>Fri, 25 Aug 2023 20:07:48 GMT</pubDate>
            <atom:updated>2023-08-25T20:07:48.037Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/833/1*oPv7fpC1ogvce7KfRwG4Og.png" /></figure><p>Its been a while! I’m glad to have got some time to get back to blogging :)</p><p>Recently I had a tech task where I wanted to create users in my Linux Server. The user was created in such a way that it has to be part of a group. Now, why do we need groups? Is there other benefits we can have while adding users, other than giving access ? Lets find out.</p><h4>So now, how can I find the list of existing users/groups ?</h4><p>We have a file: <strong>/etc/passwd</strong> . This file stores the list of the existing users.</p><p>The same follows for groups where the file would be <strong>/etc/group.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/487/1*mMqIVbsB-3MDRWovBXEZ9A.png" /></figure><p>Now lets take each record and understand what it really means:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/961/1*paO72ppLkYR_Muj4e_Bkcw.png" /></figure><p><strong>User</strong> : The existing user present in the server.</p><p><strong>Password </strong>: The ‘x’ represents the hidden password.</p><p><strong>UID</strong> : User ID is a value unique to each user.</p><p>Its interesting to note that 0 to 99 is reserved for the system for static allocation. For root user, it would be 0. UID 100 to 499 is reserved for dynamic allocation for system admins.</p><p><strong>GID</strong> : Group ID is a value unique for groups.</p><p><strong>Comment</strong>: Comments for better clarity.</p><p><strong>Home Directory </strong>: For the Linux Newbies, a Home Directory is the root folder path from which a user can navigate to various other Directory. This will serve as the absolute path. So when a user connects to the server, this is the folder where the user will land.</p><p><strong>Shell</strong> : The most commonly used shell is /usr/bin , where the executables are store. This will enable normal user to execute commands.</p><p>Here is an interesting observation I made for FTP servers. The requirement was that the disable access via SSH to server. This was done by giving the shell as <strong>/usr/sbin/nologin — which disables access for security reasons. However to enable SFTP access for the users that are part of a specific group , we can simply modify the sshd_config file. [1]</strong></p><p>Now that we know what each parameter means, lets get into the implementation part of it. Here are some of the most used Linux commands for Users/Groups :</p><p><strong>NB : Make sure you have root privilege and that you run as a root user. <em>NB2 : Anything between &lt;&gt; is a custom name provided and not part of the syntax.</em></strong></p><h4>Creating a User</h4><pre>useradd linu             ### useradd &lt;user&gt;  </pre><h4>Creating a user with a specific UID</h4><pre>useradd -u 1152 linu          ###useradd -u &lt;UID&gt; &lt;user&gt;</pre><h4>Modifying the username</h4><p>We are <strong>modifying</strong> the name of the current user and anything to be modified on user is done using the keyword <strong>usermod(User-Modify)</strong></p><pre>usermod -l linu mary      ### usermod -l &lt;current_user&gt; &lt;new_user&gt;</pre><h4>Creating a password for the user</h4><pre>passwd linu      ### passwd &lt;user&gt;<br># This prompts us to create a password for the user</pre><p><em>What happens without password ?</em></p><p>They will still be able to gain shell access to the server, without the need for any password</p><p><em>Where are passwords stored?</em></p><p>The passwords are stored in an encrypted format in <strong>/etc/shadow</strong> file. However, to clarify, there is no way to see an existing users password in plain text .Storing it in plain text will pose a security threat by unauthorized user.</p><h4>Creating a group</h4><pre>groupadd devops     ### groupadd &lt;group&gt;</pre><h4>View groups the current user is assigned to:</h4><pre>groups         #(Notice the plural!)</pre><h4>View all groups in the server</h4><pre>getent group</pre><h4>Adding new user to the group</h4><pre>useradd -g steve devops      ###useradd -g &lt;name&gt; &lt;group&gt;</pre><h4>Adding existing user to the group</h4><p>We are effectively modifying the group of the current user and anything to be modified on user is done using the keyword <strong>usermod(User-Modify)</strong></p><pre><br>usermod -g devops mary    ###usermod -g &lt;group&gt; &lt;name&gt;<br><br>#Now you give sudo access to mary bu adding her to sudo group<br>usermod -aG sudo mary     ### -a for append -G for group</pre><h4>Adding a comment for existing user</h4><pre>usermod -c &quot;Adding Mary to devops group&quot; mary  ###usermod -c &quot;comment&quot; &lt;user&gt;</pre><h4>Adding a home directory</h4><pre>usermod -d /home/devops mary  ###usermod -d &lt;home dir&gt; &lt;user&gt;</pre><h4>Adding a default shell</h4><pre> usermod -s /usr/sbin/nologin steve       ###usermod -s /usr/sbin/nologin &lt;user&gt;</pre><h4>Deleting a user</h4><pre>userdel steve</pre><h4>Deleting a group</h4><p>NB : You must remove the users from the group before you remove the group. Else groupdel command will simply refuse.</p><pre>groupdel devops       ###groupdel &lt;group&gt;</pre><p>So that’s it folks! Now we have learnt Lesson 101 or maybe even more for Linux Administrators :)</p><h4>References :</h4><p>[1] <a href="https://www.digitalocean.com/community/tutorials/how-to-enable-sftp-without-shell-access-on-ubuntu-16-04">https://www.digitalocean.com/community/tutorials/how-to-enable-sftp-without-shell-access-on-ubuntu-16-04</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=210f13f36f2c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[JSON — The Final Part]]></title>
            <link>https://linumary.medium.com/json-the-final-part-abf7384513c7?source=rss-4241788cb946------2</link>
            <guid isPermaLink="false">https://medium.com/p/abf7384513c7</guid>
            <category><![CDATA[lists]]></category>
            <category><![CDATA[wildcard]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[json]]></category>
            <dc:creator><![CDATA[Linu Bajy]]></dc:creator>
            <pubDate>Fri, 30 Jun 2023 16:57:19 GMT</pubDate>
            <atom:updated>2023-06-30T16:57:19.523Z</atom:updated>
            <content:encoded><![CDATA[<h3>JSON — The Final Part</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/625/1*Zv9Xp0VkjpTLJ35C8TAfwA.png" /></figure><p>Hi everyone,</p><p>We’ve finally come to the last part of our JSON series. Catch up with the rest of the articles <a href="https://medium.com/@linumary/exploring-more-of-json-a0fc63097300"><em>here</em></a>.</p><h4>Wildcards in JSON</h4><p>Like we do for Programming Languages, we have a character that we can replace it with. This will fetch all the output , which is a good idea when we don’t know the specific outputs.</p><p>So lets go with our same previous example:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/724/1*xFX4PWWWeOX0GXBHfRY77Q.png" /><figcaption>The JSON file</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/618/1*cq4KcamlPJGK_dDEGb0tfg.png" /><figcaption>Query</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/626/1*Rhwx4xadoS2bZSh2oggi4A.png" /></figure><p>So , here’s what happened. Here I want to know the details of my parents which is in an array with the key ‘Parents’. But I wanted only the specific details (just the name).The star operator <strong>‘*’ iterates through the array</strong> and<strong> </strong>fetches just the name of all the objects present inside it and returns that as an Array. As simple as that :)</p><p>Note that all outputs of the query come as an Array.</p><p><strong>Manipulation on Lists:</strong></p><p>If you are familiar with operations on List , then this is just the same concept that’s used. Here, this List contains numbers from 0 to 10, ie 11 values. The first index is 0 and its value , for the sake of simplicity has been kept 0. The last index is 10, its value is 10.</p><p>Here is the List:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/412/1*mcIw8ks4qO357vy30TBg5g.png" /></figure><p>(i)Query to fetch the first 3 elements .</p><p>Note that the value after the colon indicates the number of values(not index)to be fetched . Hence, for index, the effective query would be for index [0:2] ie [0,1,2]</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/390/1*rfMcRB6CkLIgPWy5-vypKg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*Z0Dot_TidD96vJJo_hk2NA.png" /></figure><p>(ii)Query to fetch all values in list</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/252/1*IvgfFRXBxgco8MAfqzLs8A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/217/1*iKWfpMQhstj1CxeVv9mACA.png" /></figure><p>(iii) Query to fetch alternate values</p><p>Here the 3rd value(2) is the number of hops it should take to fetch the next value. By default , it is 1 .</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/242/1*Mwi_jU1exKIdtoGbDrFSug.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/207/1*vXba235WVZmMDBWs_wZZrQ.png" /></figure><p>(iv)Query to fetch the last value</p><p>Here , we can assume that the last value to be of index -1, second last value to be -2 …You get the gist.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/234/1*gszKoumU2hN2M-780e4nuw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/224/1*AV-tQMPZQG7hArCM2RGcig.png" /></figure><p>And that’s that. This is all we need to know for the Basics.</p><p>Until next article :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=abf7384513c7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Exploring more of JSON]]></title>
            <link>https://linumary.medium.com/exploring-more-of-json-a0fc63097300?source=rss-4241788cb946------2</link>
            <guid isPermaLink="false">https://medium.com/p/a0fc63097300</guid>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[json-query]]></category>
            <category><![CDATA[lists]]></category>
            <category><![CDATA[json]]></category>
            <category><![CDATA[arrays]]></category>
            <dc:creator><![CDATA[Linu Bajy]]></dc:creator>
            <pubDate>Fri, 19 May 2023 15:37:40 GMT</pubDate>
            <atom:updated>2023-05-19T15:37:40.341Z</atom:updated>
            <content:encoded><![CDATA[<h3>Exploring more of JSON!</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*yh9ipvLWhKMh4nAesFd3fQ.png" /><figcaption>Lessgoo!!!</figcaption></figure><p>Hi everyone,</p><p>As we looked into the <a href="https://medium.com/@linumary/json-the-what-whys-and-hows-b22939ef36b0"><strong><em>basics of JSON</em></strong></a> in my previous article, lets dive into it a bit more. Earlier ,we saw how we can develop a JSON file. Its easy if you are from the Programming background. But in most of the cases , we need to extract or query Data from JSON files. This process is called JSON Path Query.</p><h3>JSON Path Querying using Dot Notation</h3><p>For those of you who have worked using Terraform, this would be easily relatable. When you have a large file, we use ‘.’ as in we are filtering the data for the final value we need. Lets go through this, with a sample Skeleton code. JSON code is basically more or less , a complex version of this!</p><pre>{<br> &quot;name&quot;: &quot;Linu&quot;,<br> &quot;gender&quot;: &quot;Female&quot;,<br> &quot;role&quot;: &quot;Devops Engineer&quot;,<br> &quot;parents&quot;: [<br>  {<br>   &quot;name&quot;: &quot;ABC&quot;,<br>   &quot;gender&quot;: &quot;Male&quot;<br>  },<br>  {<br>   &quot;name&quot;: &quot;XYZ&quot;,<br>   &quot;gender&quot;: &quot;Female&quot;<br>  }<br> ]<br><br>}</pre><p>Now here:</p><ul><li>If I wanted to fetch my name, ie. the value in the pair, then I know that the key is to pass the key as — Query -&gt;name =&gt; The output would be -&gt; Linu</li><li>The output comes within ” [ ]” .</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/733/1*8oGh1VvZEmB1M5gvvR_jnQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/732/1*FnjDJE4UpExUf8IVGhuzCg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/762/1*_unoUq4-2hW0TWEQnzSZjQ.png" /></figure><p><em>Now lets see into a much more complex example.</em></p><h3>Arrays and Lists in JSON</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/292/1*h4HfeKDpoIBR61MNIajSUQ.jpeg" /><figcaption>:P</figcaption></figure><p>Lets take the same example:</p><pre>{<br> &quot;name&quot;: &quot;Linu&quot;,<br> &quot;gender&quot;: &quot;Female&quot;,<br> &quot;role&quot;: &quot;Devops Engineer&quot;,<br> &quot;parents&quot;: [<br>  {<br>   &quot;name&quot;: &quot;ABC&quot;,<br>   &quot;gender&quot;: &quot;Male&quot;<br>  },<br>  {<br>   &quot;name&quot;: &quot;XYZ&quot;,<br>   &quot;gender&quot;: &quot;Female&quot;<br>  }<br> ]<br><br>}</pre><p>For the object “parents”, It is an array of objects. Each object has got 2 attributes for it as well. So how do call the objects in an array. Its just as easy as calling the object name.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/726/1*ijTULY--CZ-HH-C4Hl_lXA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/732/1*bsROXlC211JrAE4cKGsVEw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/739/1*A1GKd9EaBpuwOW_bgJ-HSA.png" /></figure><p>Here, it returns an Array of objects , which is fine. But what if we want to fine tune it based on some filters maybe? . In that case, we would have to go through the objects in the Array.</p><p>Continuing with the complex example, I want to find the name of my Male parent. So definitely multiple things required here.</p><p>One, we need to <strong>iterate through all the objects of the Array —</strong></p><h4>This can be achieved using ‘ @ ’</h4><p>Two, we need to find the gender by passing the name attribute —</p><h4>This can be done using a<strong> filter object like ‘?’</strong></h4><p>To combine both of these we do a query like :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/726/1*ijTULY--CZ-HH-C4Hl_lXA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/740/1*7VBQ0NarcBExzmd99eOHEw.png" /></figure><h4>So what exactly happens here?</h4><ul><li>parent is an array , which return the respective objects.</li><li>To use some filters on the parent object, we pass it as an argument — Starts with ‘?’ and passing the parameter based on which we want to filter.</li><li>To filter objects, we need to iterate through all objects of the Array , which is done using ‘ @ ‘ and then using DOT notation, we check if the key is ‘name’ has the value “ABC”.</li><li>Once it identifies the object , it filters out the gender of that particular object. Fine tuning done!</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/743/1*tSJVSu6fLduZbY896V-gvw.png" /></figure><p>There are plenty of options to filter out or even manipulate the output. For a later time :)</p><p>Kindly let me know if you enjoyed this and any other suggestions that you have so that I can work on it :)</p><p>Too-da-loo!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a0fc63097300" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[JSON — The What, Whys’ and Hows’]]></title>
            <link>https://linumary.medium.com/json-the-what-whys-and-hows-b22939ef36b0?source=rss-4241788cb946------2</link>
            <guid isPermaLink="false">https://medium.com/p/b22939ef36b0</guid>
            <category><![CDATA[xml]]></category>
            <category><![CDATA[json]]></category>
            <category><![CDATA[json-query]]></category>
            <dc:creator><![CDATA[Linu Bajy]]></dc:creator>
            <pubDate>Fri, 12 May 2023 16:01:02 GMT</pubDate>
            <atom:updated>2023-05-12T16:01:02.855Z</atom:updated>
            <content:encoded><![CDATA[<h3>JSON — The What, Whys’ and Hows’</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/542/1*oGOp4U4uVELOYSDmHrS4Gw.png" /></figure><p>Hello Everyone,</p><p>Let me introduce to The JSON Format!</p><h3><strong>Why do we need JSON?</strong></h3><p>We all know the importance of Data right! The world runs on Data. Let me give you a simple example, how do u think AI models are trained? Yup, its Data or to be more specific, its called a Dataset. So now I hope you get a better perspective of how useful data can turn into, or more importantly how the data is stored.</p><p>Before JSON, we had XML , or the eXtensible Markup Language. This is a format in which data is stored , that can be read and interpreted.</p><p>XML was used for web service responses , but JSON was preferred for multiple reasons:</p><ul><li>Lightweight- Significantly reduced the size</li><li>Easy to read and write</li><li>Used for various collection objects like Array, Dictionaries etc. XML used just strings</li></ul><p>However, XML was better in terms of security perspective , than JSON . And Hence these are preferred for Production Servers.</p><p><strong>Taking a snippet out of Wikipedia</strong></p><p><em>JSON grew out of a need for a real-time server-to-browser session communication protocol without using browser plugins such as Flash or Java applets, the dominant methods used in the early 2000s.</em></p><p><em>The co-founders agreed to build a system that used standard browser capabilities and provided an abstraction layer for Web developers to create stateful Web applications that had a persistent duplex connection to a Web server by holding two Hypertext Transfer Protocol (HTTP) connections open and recycling them before standard browser time-outs if no further data were exchanged.</em></p><p>So basically, they needed a format that was quicker and wasn’t dependent on the browser plugins or <strong>any language for that matter</strong>.</p><pre>XML code snippet<br>-----------------<br>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;<br>&lt;obj&gt;<br>  &lt;to&gt;ABC&lt;/to&gt;<br>  &lt;from&gt;XYZ&lt;/from&gt;<br>  &lt;heading&gt;Intro to JSON&lt;/heading&gt;<br>  &lt;body&gt;Lets get going!!!&lt;/body&gt;<br>&lt;/obj&gt;<br><br>PS: Notice the tags!! </pre><pre>JSON code snippet<br>------------------<br>{ &quot;obj&quot; : <br>  { <br>    &quot;to&quot;: &quot;ABC&quot;,<br>    &quot;from&quot;: &quot;XYZ&quot;,<br>    &quot;heading&quot;: &quot;Intro to JSON&quot;,<br>    &quot;body&quot;: &quot;Lets get going!!!&quot;<br>  }<br>}<br></pre><h3>What is JSON?</h3><p>Now that we know why XML was replaced, lets dive into what it was actually replaced <strong>with.</strong></p><p>JSON is JavaScript Object Notation. Its a way through which programs in an Application can communicate with each other. [1]</p><p>Like mentioned earlier, JSON can have multiple object types like Arrays etc.</p><p>An object in JSON is enclosed within “{ }” — parenthesis. The values within it can be in key value pairs. The value could be a collection of objects as well.</p><p>Say if I need an object called name, I can write a JSON file , with the content something like this- { “name”: “Linu” }. Each key value pairs are separated by colon “:”.</p><p>Note:</p><ul><li>If I have multiple key value pairs, they need to be separated by a comma,<strong> except for the last pair.</strong></li><li><strong>Also remember to put a space after every “:”</strong></li><li>Indentation doesn’t matter as long as you’ve closed all brackets!</li></ul><p>A much more complex example for JSON</p><pre>{<br> &quot;name&quot;: &quot;Linu&quot;,<br> &quot;gender&quot;: &quot;Female&quot;,<br> &quot;role&quot;: &quot;Devops Engineer&quot;,<br> &quot;parents&quot;: [<br>  {<br>   &quot;name&quot;: &quot;ABC&quot;,<br>   &quot;gender&quot;: &quot;Male&quot;<br>  },<br>  {<br>   &quot;name&quot;: &quot;XYZ&quot;,<br>   &quot;gender&quot;: &quot;Female&quot;<br>  }<br> ]<br><br>}</pre><p>So , from this example, parent is key which has an array of 2 objects. Taking the real life example, I think its self explanatory. In this way multiple object can be added as much as needed.</p><h3>Now Why is JSON important?</h3><p>Going with the current trend, we see Docker and Kubernetes tools. These tools make use of some configuration files for creating and deploying containers and other objects. It alternatively uses YAML as well .</p><p>The responses that we get from kubectl ( Kubernetes API ) is in JSON format. Hence it is important to know how to query from JSON path.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/348/1*Pf49mOXx358yeiizg2Mprg.jpeg" /></figure><p>Now , we know the What and Whys of JSON , and maybe just a bit of the Hows’ , (its just the tip of the Iceberg!). Lets explore more of this, in the upcoming posts!</p><h3>References :</h3><p>[1] <a href="https://www.geeksforgeeks.org/communication-between-two-programs-using-json/">https://www.geeksforgeeks.org/communication-between-two-programs-using-json/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b22939ef36b0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[AWS RDS-Relational Database Service]]></title>
            <link>https://linumary.medium.com/aws-rds-relational-database-service-fe2f8e104886?source=rss-4241788cb946------2</link>
            <guid isPermaLink="false">https://medium.com/p/fe2f8e104886</guid>
            <category><![CDATA[aws-rds-snapshot]]></category>
            <category><![CDATA[rds]]></category>
            <category><![CDATA[aws]]></category>
            <dc:creator><![CDATA[Linu Bajy]]></dc:creator>
            <pubDate>Fri, 05 May 2023 15:47:16 GMT</pubDate>
            <atom:updated>2023-05-06T13:30:45.733Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/457/1*DCJvUJNgbqLM1Dd9UdqS8A.png" /></figure><p>Hi everyone,</p><p>As you probably saw from the title (:P) , I was very keen to know about Databases , since we all know the importance of Data. Hence , we should find a way to securely store and retrieve when needed. And so here comes RDS- a service provided by AWS that enables you to not just store data , but to manage the way that its stored.</p><h3>The ‘What’</h3><p>RDS stands for Relational Database Service. Its provided by AWS to store data into Databases, within an EC2 instance that will be managed by AWS.</p><h3>The ‘Why’</h3><p>Lets go through the usual routine — The existing system before RDS. Traditionally , we had a system where we would have to install the packages for DB server engine , say Mysql, MariaDB etc. So , now that we have installed it , we need to install other dependencies as well, like any firewalls and other configs.</p><p>And not just that, whenever a new patch is released , we need to apply the patches as well. And this is a trouble that will have to be handled every once in a while.</p><p>So, now comes AWS RDS , a managed service, where AWS takes care of the infrastructure . We just have to configure the other things, like the connectivity, DB engine , security aspects of the data etc.</p><h3>RDS Service advantages over traditional systems</h3><ul><li>Schedule backup of Data</li><li>Resiliency of Data- multiple instances being deployed at multiple Availability Zone to be protected from Disaster Zones.</li><li>Storage Autoscaling — Scaling the instance storage size based on requirement.</li></ul><h3>The ‘How’</h3><p>Go to AWS RDS where we configure the following parameters:</p><ul><li>Engine — Aurora, Postgresql etc.</li><li>Templates- To manage infra, there are some standard templated created by AWS . It can be an instance based on Environment</li><li>Availability &amp; Durability- to configure multiple AZ</li><li>Settings for basic Authentication of DB</li><li>Instance configuration for the EC2 instance</li><li>Storage configurations for Storage Type, Storage Autoscaling etc.</li><li>Connectivity — Manage security aspects on who can access the DB Instance from the Internet. We configure VPC, Subnets, Security Groups etc.</li><li>Optional Monitoring of instances</li><li>Backup of Database- We can schedule Backups based on the number of days by adding a value to <strong>Backup retention period. </strong>Say we give 2 , it takes backup every 2 days. However backups can happen only if it is in <strong>available</strong> state. It will be stored in S3.</li></ul><h3>Creating and restoring DB Snapshots</h3><p>Even though there are automated backups that are available, there might be instances when you want to take a DB snapshot and restore it to that particular point of time, could be due to inconsistent data .</p><p>RDS Snapshot creates a <strong>storage volume snapshot</strong> of your DB instance.</p><p>To create an RDS DB snapshot → Go to AWS RDS and choose the DB → Select Actions → Take Snapshot → Provide a name → Done</p><p>To restore a DB from Snapshot → Go to AWS RDS → Snapshots → Select snapshot → Actions → Restore Snapshots → Select name of the DB instance to be restored along with other storage configs → Done</p><p>And that’s all the basics you need to know to get started on AWS RDS.</p><p>Happy learning! :)</p><h4>References for fun facts:</h4><ul><li><a href="https://www.sqlshack.com/understanding-database-snapshots-vs-database-backups-in-sql-server/">https://www.sqlshack.com/understanding-database-snapshots-vs-database-backups-in-sql-server/</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fe2f8e104886" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Jinja2 Basics]]></title>
            <link>https://linumary.medium.com/jinja2-basics-2b0bd283f6a?source=rss-4241788cb946------2</link>
            <guid isPermaLink="false">https://medium.com/p/2b0bd283f6a</guid>
            <category><![CDATA[jinja2]]></category>
            <dc:creator><![CDATA[Linu Bajy]]></dc:creator>
            <pubDate>Fri, 28 Apr 2023 15:51:47 GMT</pubDate>
            <atom:updated>2023-04-28T15:51:47.329Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/539/1*yB_gVIg3uRG5VpzfSdkMog.jpeg" /></figure><p>Hi everyone,</p><p>I wanted to write this blog about a simple yet immensely productive tool. Let me introduce you to — The Jinja2 templates. It is a Python based template engine. I have used it on Ansible as well as Python scripts. By default , it is present in Ansible and in case on Python scripts, we just need to import the necessary packages/modules.</p><h3>Use Case:</h3><p>Have you ever had situations, where you need to update just certain values in a file and the rest remains the same? Here, we create a template and provide some variables, where we supply each values to be replaced. This is done in a certain format as we see later on.</p><h3>How to use :</h3><p>This is used just as expected — we need 2 things , a variable definition and a placeholder . So lets say ‘name’ is the placeholder and ‘linu’ is the variable definition. Then , the placeholder could look something like this :</p><pre>name = &#39;linu&#39;<br>printf(&quot; My name is {{ name }} .&quot;) </pre><p>Ofcourse , its not just as it seems. We need to add some statements to import the values — either using some packages or some statements</p><h3>Sample script Ansible script:</h3><pre>---<br>- name: Sample script for Jinja2<br>  hosts: localhost<br>  vars: <br>    - text : jinja2<br>  tasks : <br>    - name: Print a sample text<br>      debug:<br>        msg: &quot;This is a line using {{ text }} template.&quot;<br>   <br><br><br></pre><p>Output:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/871/1*o17TX4bAcQouHLnHO_56Ew.png" /></figure><h3>Sample script using Python Script:</h3><p>In python , we require certain built in methods for replacing values in the placeholder.</p><pre># jinja2_sample.py<br>from jinja2 import Template<br>variable_name = &quot;Jinja2&quot;<br>template = Template(&quot;This is a line using {{ name }} template.&quot;)<br>msg = template.render(name=variable_name)<br>print(msg)<br><br>Output:<br>This is a line using Jinja2 template</pre><pre>Output:<br>This is a line using Jinja2 template</pre><h3>String manipulation</h3><p>String manipulation, as the name suggest, enables us to transform the string to a variation of itself. Say we have a string , that accepts name from the user. But what if I need to use the same string which has to be used in a Template in all caps, we could do this with a minor change on the script. Lets see how.</p><p>We use a pipe ( | ) symbol and provide the modifications needed. So now if we have name which is defined by the user , to modify it, we do —</p><pre><br>name = &quot;Linu&quot;<br>t = Template(&quot; My name in CAPS is {{ name | upper }} .&quot;)<br>msg = t.render(name=name)<br>print(msg)<br><br>Output : <br>My name is LINU .</pre><p>Similarly, we have other build in keywords :</p><ul><li><strong>lower</strong> — for lowercase letters</li><li><strong>title</strong> — for capitalising first letter of each word</li><li><strong>replace </strong>(“old_word”,”new_word”) — replaces the 1st string with the 2nd string</li><li><strong>default</strong>(“default_word”) — Uses the default word if no word was initialized.</li></ul><p>Similarly, we have operations that we can perform on lists :</p><ul><li><strong>min/max</strong> — To fetch the minimum/max value</li><li><strong>unique</strong> — To fetch the unique value</li><li><strong>random</strong> — To fetch random values</li></ul><p>We can also perform mathematical operations on list like :</p><ul><li><strong>union</strong></li><li><strong>intersection</strong></li></ul><h3>Loops</h3><p>Loops concepts , like in all other programming languages, is very productive in terms of execution and well as to decrease the number of code lines.</p><p>In Jinja2 templates, we utilize it for the same.</p><h4>If-else Loop :</h4><ul><li>Notice that we open and close with {% and %} resp.</li><li>Like in Bash, we need to close for the if condition, which is by using <em>endif</em> keyword.</li></ul><pre>{% if &lt;cond&gt; %}<br>    &lt;stmt1&gt;<br>{% elif &lt;cond&gt; %}<br>    &lt;stmt2&gt;<br>{% else %}<br>   &lt;stmt3&gt;<br>{% endif %}<br></pre><h4>For Loop :</h4><ul><li>We need to close for the for condition, which is by using <em>endfor</em> keyword.</li></ul><pre># Sample template to print numbers in a list<br><br>{% for n in [1,2,3] %}<br>{{ n }}<br>{% endfor %} </pre><p>And that’s a wrap on the Basics of Jinja2 Template!</p><p>Cheers!!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2b0bd283f6a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[AWS —  Elastic Container Service]]></title>
            <link>https://linumary.medium.com/aws-elastic-container-service-1a8a94aa485f?source=rss-4241788cb946------2</link>
            <guid isPermaLink="false">https://medium.com/p/1a8a94aa485f</guid>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[ecs-fargate]]></category>
            <dc:creator><![CDATA[Linu Bajy]]></dc:creator>
            <pubDate>Wed, 19 Apr 2023 18:21:32 GMT</pubDate>
            <atom:updated>2023-04-19T18:21:32.089Z</atom:updated>
            <content:encoded><![CDATA[<h3>AWS — Elastic Container Service</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/836/1*JellCmMsNdOhvMjFvpcNbA.png" /></figure><p>Hi Everyone,</p><p>Continuing with the AWS Series , I want to discuss on a very hot topic in the current trend. This is one of the popular services that AWS provides for deploying and managing containers.</p><h3>What is AWS ECS?</h3><ul><li>ECS — Elastic Container Service</li><li>Released on 2015, just a year later after Kubernetes was released. You can see how agile the IT Domain is!</li><li>It acts as an orchestrator to manage containers and its lifecycle — ie. easy rollout of new containers whenever container fails/ container rolls out new update.</li></ul><h3>Why AWS ECS ?</h3><p>To understand what problem AWS ECS solves, lets look at how containers were managed before this came into picture.</p><p>Before ECS, we had Docker to create images and build container. The images were pushed to DockerHub.</p><p>Now all good once the containers are brought up, but what happens if one of the containers fail? We bring a new one. Good enough. But what if there are multiple containers (say 100s) that fail at a point. It would be ridiculously hard to bring up the containers manually.</p><p>Let me give you another scenario. What if the traffic increases ? Too much traffic into a single container can result in slow response, or even worse, bring down the container!</p><p>So now that ECS comes into picture, it solves both of these . And even more, by providing some server-less options :)</p><h3>ECS Launch Types</h3><p>ECS has 2 launch types in general :</p><h4>a. EC2 Launch Type</h4><p>On an EC2 launch type, we manage all things infra related. That could be anything from security patches to security of the instance. This has 2 flavors — Linux and Windows. Not just that, we would have to install everything from scratch — Docker, ECS Agents to connect to AWS etc.</p><h4>b. Fargate Launch Type</h4><p>This is the server-less option provided by AWS for container management. Here, we do not manage anything about infra. We give that responsibility to AWS :)</p><h3>ECS Concepts</h3><h4>ECS Cluster</h4><p>An ECS cluster acts like how VPC works. Its purpose is to provide isolation from other instances/containers for a possibly different application. A cluster contains instances/containers.</p><h4>ECS Task Definition File</h4><p>This file contains all the details of container that we want to bring up. In Docker terms, it translates to all the YAML files that we create.</p><h4>ECS Task</h4><p>This is the number of containers that we want . So if we have a YAML file to bring up an nginx running image , and if we need 3 containers, we create 3 tasks.</p><h4>ECS Services</h4><p>This is a service for ECS , that ensures a certain number of tasks are running at all times. So we can provide the min number of containers that should be running at all times.</p><p>This service is responsible for restarting or bringing up a new instance incase the container crashes.</p><h3>Deploying an Application on ECS</h3><h4>1.Create a Cluster:</h4><p>On the AWS Console → (Left) Cluster → Create Cluster.</p><p>Provide the cluster name, VPC and Subnet details (Also a good idea to create one)</p><p>By default, ECS Fargate is chosen- with 2 capacity providers. We can add additional EC2 instances, if needed.</p><h4>2.Create a Task Definition</h4><p>A single task definition would essentially be for a single application.</p><p>On the AWS Console → (Left) Task Definition→ Create Task Definition.</p><p><strong>a. Configure task definition and containers</strong></p><p>Provide the Task Definition name. (say TODO-List-App)</p><p>We provide the container(s) details like Name, Image URI(from DockerHub), port mappings, Environment variables, Health check (provide the root path) and optional Docker Configurations.</p><p><strong>b. Configure environment, storage, monitoring, and tags</strong></p><p>Here, we provide details such as :</p><p>(i) Launch Type, OS, CPU, Memory.</p><p>(ii) Task Role — This provides details about the IAM role that enables ECS to execute onto instances on our behalf.</p><p>(iii) Storage option for mounting Volumes onto containers for data persistence.</p><p>(iv) Monitoring tools.</p><p>Now that we have the application configurations ready, let’s create the services.</p><h4>3.Create a service</h4><p>On Clusters → Go to Service Tab → Create</p><p>(i) Environment — Select the Launch Type that you prefer. Now , it also allows you to specify configurations if you select Capacity provider strategy — to distribute tasks evenly</p><p>(ii) Deployment Configurations — Application type- Service / Tasks(for batch jobs), the name and desired number of tasks</p><p>(iii) Networking settings- VPC and subnet configs.</p><p>(iv) Load Balancing — taking it to the next level with ASG</p><p>Now that we have created a service, we can check our application on the Public IP address on the exposed Port.</p><p>Now, this article comes from Operations Team perspective, where we configure application details and configs. And just like that, we have learnt to deploy an application on ECS ! Stay tuned for more such intriguing topics!</p><p>Cheers, Linu :D</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1a8a94aa485f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Boto3 Concepts]]></title>
            <link>https://linumary.medium.com/boto3-concepts-4b06b330b547?source=rss-4241788cb946------2</link>
            <guid isPermaLink="false">https://medium.com/p/4b06b330b547</guid>
            <category><![CDATA[boto3-waiters]]></category>
            <category><![CDATA[boto3]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[paginator]]></category>
            <dc:creator><![CDATA[Linu Bajy]]></dc:creator>
            <pubDate>Sun, 02 Apr 2023 17:37:41 GMT</pubDate>
            <atom:updated>2023-04-02T17:43:13.984Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/573/1*J0em1O1f5DGsrNTav9AEIQ.png" /></figure><p>Hi everyone,</p><p>In the<a href="https://linumary.medium.com/python-sdk-for-aws-boto3-494a268741b4"> previous</a> article, we saw the <a href="https://linumary.medium.com/python-sdk-for-aws-boto3-494a268741b4">basics of Boto3</a>. Now exploring more important and may I say, luxury concepts of Boto3 :D</p><h3>Waiters</h3><h4>Why do we need waiters ?</h4><p>Suppose we have a service that we not just want to use but want to know the status of it , like if its in progress/completed. So, some of the AWS Resources have an object called Waiters. These waiters have various methods that can help us identify if the particular task is completed, by waiting for the<strong> task to wait until its completed</strong>. This helps to move onto next tasks in a synchronous matter.</p><h4>What if it didn’t exist ?</h4><p>Imagine we need to deploy EC2 instances and add into the Auto Scaling Group . We could write a script to first bring up an instance and add them to the ASG group. During the execution, after we run the command, it would obviously take some bring up the instances. But , as these commands run one after the another, it would not wait for the other command to finish and move to the command that we defined to add instances to the ASG. But, since the instances are just being bought up, it would result into an error . That’s the kind of impact, that this command can make.</p><h4>Demonstrating Waiter concept</h4><p>Here is a sample code to create a snapshot from an EC2 and wait until it has been created .</p><pre>import boto3 <br><br>client = boto3.client(&#39;ec2&#39;, region_name=&#39;eu-west-1&#39;)<br>snapshot = client.create_snapshot(VolumeId=&#39;vol-xxxx&#39;)<br><br>snapshot_id = snapshot[&#39;SnapshotId&#39;]<br># Create a reusable Waiter and pass the waiter operation<br>snapshot_waiter = client.get_waiter(&#39;snapshot_completed&#39;)<br><br>&quot;&quot;&quot;<br> Pass the configurations for the Waiter object ( using wait() )<br> created above so that the script knows who it needs to keep a check on :)<br>&quot;&quot;&quot;<br>snapshot_waiter.wait(<br>  SnapshotIds=[snapshot_id],<br>  WaiterConfig={<br>          &#39;Delay&#39;: 123,<br>          &#39;MaxAttempts&#39;: 123<br>      }<br>)<br></pre><p>Here, we create a snapshot using the client object. The ‘create_snapshot’ is a method to create snapshot from the Volume ID .</p><ul><li><strong>‘get_waiter’</strong> is a method that creates a waiter object for client object. Here , the name of the created waiter is ‘snapshot_waiter’ , which is a custom name that I have provided.</li><li>A waiter object can have many methods under it. This particular waiter method <strong>‘snapshot_completed’ </strong>waits until the snapshot is created.</li><li>Here, the ‘<strong>wait’ </strong>method is associated with the custom waiter object that I have created and passes some parameters and configurations associated with it.</li><li><strong>WaiterConfig</strong> is A dictionary that provides parameters to control waiting behavior. Its an optional argument to have a controlled execution time.</li></ul><p>Notes:</p><ul><li>Its good to implement this under try/catch block for Error Handling.</li><li>There are N number of methods for waiters and hence its always best to refer the Documentation ,given you have a good understanding of the Skeleton of the Script.</li></ul><h3>Paginators</h3><h4>Why Paginators?</h4><p>Let me tell you a use-case that we had to implement for Paginators. We had a CloudWatch Log Group and Log Streams. When we view the page from AWS Console, remember how we scroll down to view more logs? Well, to do it through API calls, Paginators come into picture :) As simple as that, but the impact it has is huge!</p><p>Just like Waiter objects, Paginator objects also needs to be created and can be given custom names, and can be passed with Arguments for the same.</p><ul><li><strong>‘get_paginator’</strong> is a method that creates a paginator object for client object. Here , the name of the created paginator is ‘page_iterator’, which is a custom name that I have provided.</li></ul><p>Here’s a sample code that iterates through the pages in the S3 bucket objects.</p><pre>import boto3<br><br>client = boto3.client(&#39;s3&#39;, region_name=&#39;us-west-2&#39;)<br><br># Create a reusable Paginator and pass the paginator operation<br>paginator = client.get_paginator(&#39;list_objects&#39;)<br><br><br>operation_parameters = {&#39;Bucket&#39;: &#39;my-bucket&#39;,<br>                        &#39;Prefix&#39;: &#39;foo/baz&#39;}<br><br># Create a PageIterator from the Paginator<br>page_iterator = paginator.paginate(**operation_parameters)<br><br>for page in page_iterator:<br>    print(page[&#39;Contents&#39;])</pre><p>Just like waiters, these are also available, only to a few resources in AWS.</p><h3>Meta Objects</h3><h4>Why Meta Objects ?</h4><p>Like I discussed in my previous article , there are 2 main types of object creation ie. either Client or Resources.</p><p>A major drawback of Resource object is that it may not have all the functionalities of a Client Object.</p><ul><li>The Resource version of the code is much simpler, more compact, and has more capability. It does <strong>pagination</strong> for you and it exposes properties (Hight level Abstraction)</li><li>The Client has more methods for operating onto AWS Resources. It also prints output as dictionary(Low Level Abstraction)</li></ul><p>So , as you can see, each has its benefits based on the use case.</p><p>So, there might be cases when you want to <strong>convert Resource object to Client , </strong>since Client provides a lower level abstraction and there are methods which might not be available for Resource.</p><p>Here is an example for it. Suppose we want to turn a Resource object to client:</p><pre>import boto3 <br># Creating Session<br>client = boto3.session.Session(profile=&#39;xxx&#39;)<br><br># Creating a Resource Object<br>resource = session.resource(&#39;ec2&#39;)<br><br>#Converting a Resource to Client using meta <br>client= resource.meta.client.&lt;client method&gt;</pre><p>Now, this goes without saying, but , the other way wouldn’t make sense since the Client provides the Low Level Abstraction , and it has methods to perform more operations , compared to the Resource.</p><p>That’s about it for now. You now must have a strong basics on Boto3. We’ve looked into the greener side of coding. But there could be chances that , maybe, an S3 bucket that you’re trying to fetch files from, doesn’t exist . So how do we handle such cases? You’ll get to know about it very soon!</p><h3>References:</h3><ol><li>Client vs Resource — <a href="https://www.learnaws.org/2021/02/24/boto3-resource-client/#:~:text=To%20summarize%2C%20resources%20are%20higher,Resources%20tends%20to%20be%20simpler">https://www.learnaws.org/2021/02/24/boto3-resource-client</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4b06b330b547" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Python SDK for AWS — Boto3]]></title>
            <link>https://linumary.medium.com/python-sdk-for-aws-boto3-494a268741b4?source=rss-4241788cb946------2</link>
            <guid isPermaLink="false">https://medium.com/p/494a268741b4</guid>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[boto3]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Linu Bajy]]></dc:creator>
            <pubDate>Sat, 25 Mar 2023 18:06:24 GMT</pubDate>
            <atom:updated>2023-03-25T18:06:24.312Z</atom:updated>
            <content:encoded><![CDATA[<h3>Python SDK for AWS — Boto3</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/573/1*J0em1O1f5DGsrNTav9AEIQ.png" /></figure><p>Hi Everyone,</p><p>In this article , I want to write about Boto3 and how super useful it is , using a case study.</p><p>Suppose you have a task to download a file from S3 bucket in Account A and upload it to another S3 bucket on a different Account B on AWS. There are 2 ways to do it, the Hard way and the Smart way.</p><h4>The Hard Way -</h4><p>Login to AWS Account A and download the file to your Local. Next log out of Account A and login to Account B on AWS . We upload the file that was download and voila , its done. But what if this has to be done on a daily basis? Lets assume this process takes 10 mins everyday. So on a week , you are wasting about an hour of your time. So definitely , lets AUTOMATE !</p><h4>The Smart Way -</h4><p>We write a script that tells the AWS to do the exact same task for us! But wait, how do we communicate with the AWS account via Scripts?</p><h3>Boto3</h3><p>Boto3 is the Python SDK for AWS. So what it essentially means is that , the Boto3 package from Python contains APIs that helps to communicate with AWS.</p><p>Fun Fact : Boto was <strong>named after the fresh water dolphin native to the Amazon river</strong>.</p><h3>Prerequisites:</h3><ul><li>Install boto3 package using the command</li></ul><pre>pip install boto3</pre><ul><li>Make sure the current folder has a hidden directory ‘.aws ‘ . This directory must have 2 files — config and credentials, to store info about AWS accounts.</li></ul><p>and that’s it!</p><h3>Basic Components of Boto3</h3><ul><li>A Session will be created , for the operations to take place. Unlike the usual process, we do not have to close the session. Typically, the profile information is passed to create a session. Keyword “Session”</li><li>Client/Resource — Both of these objects gets the job done. <strong>Resource</strong> can only be used for<strong> limited services of AWS.</strong> Client gives the response in JSON(dictionary) format and hence a bit more complicated. Keyword “client”/”resource”</li></ul><h3>Example File using Client Object</h3><p>I had a use case where I wanted to download the latest file from an S3 bucket in Account A and upload it to an S3 bucket in Account B.</p><p>Lets see how we can achieve this.</p><p>Firstly, we need to check if boto3 is installed in our system. This can be verified using the command</p><pre>boto3 --version</pre><p>Next , we check for .aws folder. Ensure that the profile credentials are configured on credentials file , and configurations (like region and profile name ) is configured inside config file. Both these files should be present inside .aws folder.</p><p>Next , the very interesting Scripting part , s3_transfer.py :</p><pre>import boto3<br><br>#Creating a session<br>session = boto3.Session(profile_name=&#39;&lt;name&gt;&#39;)<br>s3_source = session.client(&#39;s3&#39;)<br><br>#fetching latest file from source S3 Bucket using a lambda <br>get_last_modified = lambda obj: int(obj[&#39;LastModified&#39;].strftime(%s))<br>objs= s3_source.list_objects_v2(Bucket=&#39;&lt;source bucket&gt;&#39;)[&#39;Contents&#39;]<br><br>#fetching filename <br>last_added_file = [obj[&#39;Key&#39;] for obj in sorted(objs, key=get_last_modified)][0]<br><br>#downloading file from S3<br>s3_source.download_file(&#39;&lt;source bucket&gt;&#39;,&lt;filename&gt; last_added_file,&lt;path in s3&gt;<br>print (&quot;Downloaded the file to local&quot;)<br><br>#creating a new session and uploading the file<br>session2 = boto3.Session(profile_name=&#39;&lt;name&gt;&#39;)<br>s3_dest = session2.client(&#39;s3&#39;)<br>with open(&#39;&lt;filename&#39;,&quot;rb&quot;) as f:<br>  s3_dest.upload_fileobj(f, &lt;destination bucket&gt; , filename)<br><br><br></pre><p>Once the script is ready, you run the file using the simple command</p><pre>python3 s3_transfer.py</pre><p>And there you have it! Automation has saved much of your time!!</p><p>Next part will include my favorite part about Paginators :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=494a268741b4" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>