<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Armando Serna Gutiérrez</title>
    <description>The latest articles on DEV Community by Armando Serna Gutiérrez (@armandosg).</description>
    <link>https://dev.to/armandosg</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F678338%2Fafadeeee-637c-4f59-983a-8af537e59ed9.jpeg</url>
      <title>DEV Community: Armando Serna Gutiérrez</title>
      <link>https://dev.to/armandosg</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/armandosg"/>
    <language>en</language>
    <item>
      <title>How git manages versions of our files</title>
      <dc:creator>Armando Serna Gutiérrez</dc:creator>
      <pubDate>Fri, 14 Jan 2022 18:42:44 +0000</pubDate>
      <link>https://dev.to/armandosg/how-git-works-under-the-hood-223b</link>
      <guid>https://dev.to/armandosg/how-git-works-under-the-hood-223b</guid>
      <description>&lt;p&gt;Hi everyone 👋 &lt;/p&gt;

&lt;p&gt;I recently watched a section of the course &lt;a href="https://www.udemy.com/course/git-and-github-complete-guide"&gt;The Complete Git Guide by Bogdan Stashchuk&lt;/a&gt;, where he explains the internals of how git versions our project files and I think it really helped me to understand this tool. So that's why I want to share with you this knowledge in this blog post.&lt;/p&gt;

&lt;h2&gt;
  
  
  Git commands used in this tutorial
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;git ls-files -s&lt;/strong&gt;: List the objects that are on the staging area&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;git cat-file -p&lt;/strong&gt;: Get the contents of a git object&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;git cat-file -t&lt;/strong&gt;: Get the type of a git object&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Diagram of our git repository
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--v0pS0TyJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lh0mtrr4h4td74tj0zyh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--v0pS0TyJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lh0mtrr4h4td74tj0zyh.png" alt="Diagram of our git repository" width="247" height="395"&gt;&lt;/a&gt; &lt;/p&gt;

&lt;h2&gt;
  
  
  Diagram after committing a new file
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--0um-oDVd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/q53vff57ha5oz591x6dn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--0um-oDVd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/q53vff57ha5oz591x6dn.png" alt="Diagram after committing a new file" width="478" height="391"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Object types in git
&lt;/h2&gt;

&lt;p&gt;Before going straight into details on how git saves the version of our files, let's first understand the 4 object types of git:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Blobs&lt;/strong&gt;: this are like files. A blob is composed by the type of object, the size of the object, a delimiter, and the contents of the file.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Trees&lt;/strong&gt;: this are like directories. A tree is composed by a list of blobs and trees that the project has.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Commits&lt;/strong&gt;: the commits are like special snapshot of a repository.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Tags&lt;/strong&gt;: We will not cover this object type in this post.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Git stores all of this objects in the &lt;code&gt;.git/objects&lt;/code&gt; directory of every repository as files compressed in binary format.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--8kDjZ7nR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mz1wxypq775h3p5mimw9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--8kDjZ7nR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mz1wxypq775h3p5mimw9.png" alt="Example contents of .git/objects directory" width="760" height="273"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  How does git version a single file?
&lt;/h2&gt;

&lt;p&gt;Each time we make a commit of some changes on a repository, git automatically creates the necessary blobs, trees and commits to save the version of our files.&lt;/p&gt;

&lt;p&gt;To demonstrate you this, Let's create a new git repository.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--mVXqyQvj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qhbv0k64712idtccjpxh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--mVXqyQvj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qhbv0k64712idtccjpxh.png" alt="Create a new repository with git init" width="564" height="78"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now, if we take  look into our &lt;code&gt;.git/objects&lt;/code&gt; directory, we'll see that there are any objects in the repo. (Ignore the info and pack directories)&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--gZTE0Vq2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/y5srhjl5ttqqqj20umjm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--gZTE0Vq2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/y5srhjl5ttqqqj20umjm.png" alt="Contents of .git/objects directory from new repo" width="324" height="50"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Next, to see some objects, let's add a new file and stage the changes.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--KsEHnB2m--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7tjg07mhjyjkbp31nbay.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--KsEHnB2m--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7tjg07mhjyjkbp31nbay.png" alt="New file added to the working directory" width="577" height="55"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The action of adding changes to the staging area, created a new blob object. To see this new object we can either run &lt;code&gt;git ls-files -s&lt;/code&gt; command.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--2Xa-RXjo--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qkr8lwosph1jienzrzft.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--2Xa-RXjo--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qkr8lwosph1jienzrzft.png" alt="List objects in staging area" width="509" height="48"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If we take a closer look to the output of this command we will find that we have hash for this object. This hash serves as a unique identifier for this version of the file, and we actually get can the contents of this file just by appending this hash to the &lt;code&gt;git cat-file -p &amp;lt;hash&amp;gt;&lt;/code&gt; command.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--VzgYW8Ww--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tdfvz09fb23tseo1ocge.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--VzgYW8Ww--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tdfvz09fb23tseo1ocge.png" alt="Running git cat-file to get contents of new blob object" width="617" height="51"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Also we can get the type of the object by using the &lt;code&gt;-t&lt;/code&gt; flag. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--nXNpYT3f--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6ofmsygo12lqjewvzivo.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--nXNpYT3f--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6ofmsygo12lqjewvzivo.png" alt="Getting the type of the object" width="621" height="48"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We can even take another look into &lt;code&gt;.git/objects&lt;/code&gt; and we'll see a new file and folder has been created for this blob object.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--_loF2wS9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/x8c1mnriyvwk0xmvc0w7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--_loF2wS9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/x8c1mnriyvwk0xmvc0w7.png" alt="New file for new blob object" width="477" height="178"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--JTw2Oc4W--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ddycysrje9hp1mmfsrrg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--JTw2Oc4W--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ddycysrje9hp1mmfsrrg.png" alt="New file for new blob object" width="484" height="183"&gt;&lt;/a&gt;  &lt;/p&gt;

&lt;h2&gt;
  
  
  What about trees and commits?
&lt;/h2&gt;

&lt;p&gt;We have seen how git creates a version of the file just by adding a new file to the staging area.&lt;/p&gt;

&lt;p&gt;Now, to see how git creates a new tree and associate this to a commit.&lt;/p&gt;

&lt;p&gt;To do so we only need to run &lt;code&gt;git commit&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--_k1QNKsO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nf9cg19sp5vp40o5g905.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--_k1QNKsO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nf9cg19sp5vp40o5g905.png" alt="Git commit" width="427" height="82"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We can see from the output that a new hash for the commit has been created. That means we can use &lt;code&gt;git cat-file -p&lt;/code&gt; to examine the contents of this new commit object.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--nm6-exSY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gw8env0x190z84twi5bv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--nm6-exSY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gw8env0x190z84twi5bv.png" alt="Examine contents of new commit" width="490" height="106"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now we see that git created not only a new object for our repository, but also a new tree. Let's now get the contents of this tree.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--SC09hgsu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dmtn7bldutpp5r9dlrq1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--SC09hgsu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dmtn7bldutpp5r9dlrq1.png" alt="Examine contents of new tree" width="613" height="46"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;There we can see a list of all blobs and trees that has this project version. For now, we can only see one blob object is listed, but as we continue adding more files, we will see more in that list.&lt;/p&gt;

&lt;p&gt;It is important to note that every time we make a change to the current state of the project and commit those changes, git will automatically create a new commit and tree with new hashes and may create new blob objects if there were files modified or added.&lt;/p&gt;

</description>
      <category>git</category>
      <category>programming</category>
      <category>devops</category>
    </item>
    <item>
      <title>AWS: How to schedule launch and termination of an EC2 instance</title>
      <dc:creator>Armando Serna Gutiérrez</dc:creator>
      <pubDate>Wed, 08 Sep 2021 00:59:51 +0000</pubDate>
      <link>https://dev.to/armandosg/aws-how-to-schedule-launch-and-termination-of-an-ec2-instance-1fa4</link>
      <guid>https://dev.to/armandosg/aws-how-to-schedule-launch-and-termination-of-an-ec2-instance-1fa4</guid>
      <description>&lt;h2&gt;
  
  
  A common scenario
&lt;/h2&gt;

&lt;p&gt;After deploying application to an dev/testing server hosted in EC2, you may find that the developers only need access to this servers during their work hours. &lt;/p&gt;

&lt;p&gt;So having your instances active during hours that you know the users don't really need access to that servers may represent an unnecessary waste of money.&lt;/p&gt;

&lt;h2&gt;
  
  
  The solution: Schedule actions on auto-scaling groups.
&lt;/h2&gt;

&lt;p&gt;The solution I'm going show you in this post uses the &lt;strong&gt;schedule actions&lt;/strong&gt; of the auto-scaling groups. &lt;/p&gt;

&lt;p&gt;You will see that with this approach you will be able to adjust the &lt;em&gt;Desired Capacity&lt;/em&gt;, &lt;em&gt;Minimum Capacity&lt;/em&gt; and &lt;em&gt;Maximum Capacity&lt;/em&gt; of the group of instances you're working with at certain hours of the day.&lt;/p&gt;

&lt;p&gt;For this example the &lt;em&gt;Desired Capacity&lt;/em&gt; will be set to 1 instances during work hours, and for inactive hours it will be again adjusted but now to 0 instances.&lt;/p&gt;

&lt;p&gt;You can see in the following image the architecture of the solution:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--qqDs3o0I--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/s83dbbhgz1snwzs57vum.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--qqDs3o0I--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/s83dbbhgz1snwzs57vum.png" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To create this solution you need to follow the next steps.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Create an AMI of the instance&lt;/li&gt;
&lt;li&gt;Create a launch template using the AMI created&lt;/li&gt;
&lt;li&gt;Add your launch template to a load balancer&lt;/li&gt;
&lt;li&gt;Add your launch template to an auto-scaling group&lt;/li&gt;
&lt;li&gt;Add an schedule action to scale-up and another to scale-in&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Full explanation step by step.
&lt;/h2&gt;

&lt;p&gt;I will explain how to create this solution using the AWS web console. In a later tutorial I will explain how to create this same solution bit using an IaC tool like Terraform.&lt;/p&gt;

&lt;p&gt;For this example I created a t2.micro instance and installed an apache web server on it. In the following image you can see the web server is running on port 80.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--HVbQEInA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8sb6a2uj9xg93i34mh2l.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--HVbQEInA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8sb6a2uj9xg93i34mh2l.png" alt="image"&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;This instance executes the web server on each startup. This come will come in handy since we will be creating and terminating new instances every day.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 1: Create an &lt;em&gt;AMI&lt;/em&gt; of the instance
&lt;/h3&gt;

&lt;p&gt;Now using AWS web console, go to the instance of the EC2 service. Right click on the instance you want to work with and choose &lt;em&gt;Create image&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Krg5YqTK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/t45fqftrm0befi8byl6f.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Krg5YqTK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/t45fqftrm0befi8byl6f.png" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the next page give a name to your image and click on &lt;em&gt;Create image&lt;/em&gt;.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--TpHAqWBp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wfva6qipq1y814wfxqoq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--TpHAqWBp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wfva6qipq1y814wfxqoq.png" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now if you navigate to the AMI section you will see a new image is created and is on pending status.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--saWkZseV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8gn7mbfdywu5m22nywzr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--saWkZseV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8gn7mbfdywu5m22nywzr.png" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 2: Create a Launch Template using the AMI created
&lt;/h3&gt;

&lt;p&gt;Navigate to the &lt;em&gt;Launch Template&lt;/em&gt; section and click on &lt;em&gt;Create Launch Template&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ZeC0zNyb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8ntjw7fkgum1yg5ow86g.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ZeC0zNyb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8ntjw7fkgum1yg5ow86g.png" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the Amazon machine image section search for the name of the image and select it. Also select the Latest version of the image.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--nRB2fZZe--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l8gwgerqo2o2h164hqlx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--nRB2fZZe--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l8gwgerqo2o2h164hqlx.png" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Ensure to choose the same security group that your existing instance has.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--37TSGzqp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/71q3yhnj7mm0jjik2nit.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--37TSGzqp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/71q3yhnj7mm0jjik2nit.png" alt="image"&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Click on Create launch template&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 3: Add your launch template to a load balancer
&lt;/h3&gt;

&lt;p&gt;Select Application Load Balancer&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--frAnxUuV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/iyrka9rppswsn7vsqifa.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--frAnxUuV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/iyrka9rppswsn7vsqifa.png" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Give a name to the load balancer&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--sRLwwMV6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/azfbvihwfh3oa4beml5n.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--sRLwwMV6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/azfbvihwfh3oa4beml5n.png" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Select at least two availability zones&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--DY2B8cKQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4ymrlw0qma480rhsrzcf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--DY2B8cKQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4ymrlw0qma480rhsrzcf.png" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Use the default listener and click on create target group&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--bxkO4m64--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yp44bbvtvr1l0tdc4ryw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--bxkO4m64--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yp44bbvtvr1l0tdc4ryw.png" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It will open a new browser tab to create the target group. Give a name and choose Instances for the instance type.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--8jsJXmv7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/oogy96zk0jt5rw8kmm7r.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--8jsJXmv7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/oogy96zk0jt5rw8kmm7r.png" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Leave all the other options as default, click next and click on Create target group. Return to the tab of the load balancer creation.&lt;/p&gt;

&lt;p&gt;Search for the target group in the default listener and select it.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--fepsKEFZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ff1v1hpka4gzfw4bxh5x.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--fepsKEFZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ff1v1hpka4gzfw4bxh5x.png" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Click on Create load balancer.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 4: Add your launch template to an auto-scaling group
&lt;/h3&gt;

&lt;p&gt;Navigate to the Auto-scaling group section and click on Create auto-scaling group.&lt;/p&gt;

&lt;p&gt;Give a name to the Auto-scaling group and choose the launch template we have created. Click on next.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--j9EsGbvm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bsc88ycukmqtathb3pcr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--j9EsGbvm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bsc88ycukmqtathb3pcr.png" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Select the two Availability zones we choose on the creation of the load balancer. Click on next.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Pqj57hod--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/65bqemawy56zw8osx04o.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Pqj57hod--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/65bqemawy56zw8osx04o.png" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the next section choose Attach to an existing load balancer and select the load balancer we created in the previous step. Click on next.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--cj8YpNLF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cxevl0wnpxwl704340e3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--cj8YpNLF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cxevl0wnpxwl704340e3.png" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For the group size I will set the values as showed in the image. Click on next.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--YcNtmSlX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8weot6p4zzn55b6bqhpw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--YcNtmSlX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8weot6p4zzn55b6bqhpw.png" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For Add notification and Add tags just click next. To finish, click Create auto scaling group.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 5: Add an schedule action to scale-up and another to scale-in
&lt;/h3&gt;

&lt;p&gt;Navigate to the Load balancers section, select the recently created load balancers from the list, and click on the Automatic scaling tab.&lt;/p&gt;

&lt;p&gt;Scroll down until you see schedule actions. Click on Create scheduled action&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--zndOZiT4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/f3wvohtl4v2o35zlj4h1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--zndOZiT4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/f3wvohtl4v2o35zlj4h1.png" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Give a name, set desired capacity to 1, for recurrence choose Cron, enter this cron expression &lt;code&gt;0 8 * * MON-FRI&lt;/code&gt;, choose your timezone and select the start time of your action.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--tFbm8kWL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gpxr88r84u8qivf4nuvy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--tFbm8kWL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gpxr88r84u8qivf4nuvy.png" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This configuration will set the desired capacity to 1 from monday to friday at 8 am.&lt;/p&gt;

&lt;p&gt;Now to scale-in create another schedule action but now setting the desired capacity to 0.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--fk1lKBei--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/chalmrs5ucgi6tq9hbl6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--fk1lKBei--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/chalmrs5ucgi6tq9hbl6.png" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Terminate the existing instance
&lt;/h3&gt;

&lt;p&gt;As this solution uses an image to launch new instances you can terminate the existing one and wait until the scale-out action get executed to see a new instance.&lt;/p&gt;

&lt;h3&gt;
  
  
  Accessing the application
&lt;/h3&gt;

&lt;p&gt;To access the application use the DNS name of the application load balancer.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--cN06Rfha--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qxkywkzz1az5lkcsr1w3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--cN06Rfha--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qxkywkzz1az5lkcsr1w3.png" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--0J48rBU8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dtnhymwuonbqp0p4b7w9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--0J48rBU8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dtnhymwuonbqp0p4b7w9.png" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>GIT: How to commit only parts of a file?</title>
      <dc:creator>Armando Serna Gutiérrez</dc:creator>
      <pubDate>Sat, 04 Sep 2021 18:30:20 +0000</pubDate>
      <link>https://dev.to/armandosg/git-how-to-commit-only-parts-of-a-file-4d3n</link>
      <guid>https://dev.to/armandosg/git-how-to-commit-only-parts-of-a-file-4d3n</guid>
      <description>&lt;h2&gt;
  
  
  Scenario
&lt;/h2&gt;

&lt;p&gt;It probably happened to you that after making lots of changes to some code files, you see one of those changes is ready so you decide to commit only this single change (maybe because you want to share it with other colleagues or maybe the client is asking to have this change ready).&lt;/p&gt;

&lt;p&gt;So you open your terminal and run the git diff command on the file where your change is and see the following output:&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0jtid31t8atwk1kl03kw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0jtid31t8atwk1kl03kw.png" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And there it is, the part of the file you want to commit is the where the line &lt;code&gt;font-weight: normal;&lt;/code&gt; is added. But there is also another change in this file. &lt;/p&gt;

&lt;p&gt;So using &lt;code&gt;git add style.css&lt;/code&gt; isn't an option for this scenario, as it would be introducing two different changes into the commit I want to share.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F005a0x75yc2ywizzh5fg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F005a0x75yc2ywizzh5fg.png" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  The solution: the --patch argument
&lt;/h2&gt;

&lt;p&gt;So the solution to this usual scenario (it has happened to me a million times) is adding the argument &lt;code&gt;--patch&lt;/code&gt; to the &lt;code&gt;git add&lt;/code&gt; command.&lt;/p&gt;

&lt;p&gt;Doing this will prompt us for each change (or hunk) we have in our file if it should be part of our changes to be committed. &lt;/p&gt;

&lt;p&gt;So after running &lt;code&gt;git restore style.css --staged&lt;/code&gt; to restore our previously staged changes, we run &lt;code&gt;git add style.css --patch&lt;/code&gt; and see the following output:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcrt7r3tu1de867hodq63.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcrt7r3tu1de867hodq63.png" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And as you can see, now git is asking us if the line that contains the change to the &lt;code&gt;background&lt;/code&gt; should be included or not. &lt;/p&gt;

&lt;p&gt;We can input &lt;code&gt;y&lt;/code&gt; for yes or &lt;code&gt;n&lt;/code&gt; for no, or simply input a &lt;code&gt;?&lt;/code&gt; to get a description of each option.&lt;/p&gt;

&lt;p&gt;So we decided to not include the first hunk and then include the second one as we can see in the image below:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fa5k24k9odqz6ymqh6rqg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fa5k24k9odqz6ymqh6rqg.png" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Then if we inspect our staged changes there's only the changes we want.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9wpc6rhqolayzsahz92c.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9wpc6rhqolayzsahz92c.png" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Why would I ever want to commit one part of the file?
&lt;/h2&gt;

&lt;p&gt;In git there is a concept called "atomic commits", which are commits that only contains a single logical change to a part of the code. &lt;/p&gt;

&lt;p&gt;Using atomic commits makes our repositories easy to navigate and to inspect, and has a lot of benefits for teams that needs to review older parts of the code in order to fix a bug for example.&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
