<?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: Mariano Calandra</title>
    <description>The latest articles on DEV Community by Mariano Calandra (@marianocalandra).</description>
    <link>https://dev.to/marianocalandra</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%2F571351%2F9c617abe-589b-46a0-9d79-8360a5bf6b1f.jpeg</url>
      <title>DEV Community: Mariano Calandra</title>
      <link>https://dev.to/marianocalandra</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/marianocalandra"/>
    <language>en</language>
    <item>
      <title>Five tools to deliver stunning online presentations and courses</title>
      <dc:creator>Mariano Calandra</dc:creator>
      <pubDate>Fri, 30 Apr 2021 08:58:00 +0000</pubDate>
      <link>https://dev.to/aws-builders/five-tools-to-deliver-stunning-online-presentations-and-courses-2ocd</link>
      <guid>https://dev.to/aws-builders/five-tools-to-deliver-stunning-online-presentations-and-courses-2ocd</guid>
      <description>&lt;p&gt;In the early days of 2020, when Coronavirus starts hitting the world of businesses, the first job activities that have been stopped was the so-called &lt;em&gt;workplace learning.&lt;/em&gt; According to a study by McKinsey:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;As of early March 2020, roughly one-half of in-person programs through June 30, 2020, have been postponed or canceled in North America; in parts of Asia and Europe, the figure is closer to 100 percent.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;A terrible loss of knowledge.&lt;/p&gt;

&lt;p&gt;Luckily the industry recovered quickly through &lt;em&gt;remote training&lt;/em&gt; and applications like Zoom and Teams have been essential tools in our daily job.&lt;/p&gt;

&lt;p&gt;Unluckily, &lt;strong&gt;good public speaking skills are no longer sufficient&lt;/strong&gt;. Today, to bring out these skills &lt;strong&gt;you also need the right tools&lt;/strong&gt; or your presentations will lose their effectiveness, no matter your elocution.&lt;/p&gt;

&lt;p&gt;In this article, I have put together five fundamental tools that you must have if you want to deliver stunning online courses and presentations.&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Microphone
&lt;/h3&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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1619772027203%2FV_2Jm_5oO.jpeg" 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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1619772027203%2FV_2Jm_5oO.jpeg" alt="The Blue Yeti Nano micrphone"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you are using your laptop microphone in your courses, chances are that your audio doesn’t sound really enjoyable to the students. So the first step is to buy a decent microphone, like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;a href="https://amzn.calandra.me/yeti-nano" rel="noopener noreferrer"&gt;Blue Yeti Nano&lt;/a&gt; (desktop)&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://amzn.calandra.me/rode-smartlav" rel="noopener noreferrer"&gt;Rode SmartLav+&lt;/a&gt; (clip)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The first is a desktop microphone (but can be mounted on a stand); the other one is a lavalier microphone with a handy clip to fix it on your shirt.&lt;/p&gt;

&lt;p&gt;What’s the best? It depends on your presentation style: if you tend to move easily, Rode is fine, otherwise, Nano sounds slightly better.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;ProTip #1:&lt;/strong&gt; To have the best possible result you should be able to calibrate your mic on your voice. &lt;a href="https://www.youtube.com/watch?v=IMP-IEfg-yg" rel="noopener noreferrer"&gt;This&lt;/a&gt; video explains thoroughly how to set Blue Yeti using a well-known free tool called VoiceMeter.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Drawing tablet
&lt;/h3&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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1619772085441%2FvBqrJoD85.jpeg" 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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1619772085441%2FvBqrJoD85.jpeg" alt="The XP-PEN Artist 12 PRO"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In a real class, usually, you have a whiteboard or a flipchart where you can draw a sketch. Now you are alone, and if slides aren’t enough, you are in big troubles.&lt;/p&gt;

&lt;p&gt;A &lt;em&gt;drawing tablet&lt;/em&gt; can be considered the remote version of a flipchart. There are various types to choose from. The &lt;a href="https://amzn.calandra.me/xp-pen-a12pro" rel="noopener noreferrer"&gt;XP-PEN Artist 12 PRO&lt;/a&gt;, for instance, has a good value for money.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;ProTip #2:&lt;/strong&gt; Use your tablet to enrich slides with extra contents (do not overdo it), or open a site like &lt;a href="https://app.ziteboard.com" rel="noopener noreferrer"&gt;Ziteboard&lt;/a&gt; to draw something from scratch.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Webcam or DSLR camera
&lt;/h3&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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1619772119195%2FJG3C9LM_R.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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1619772119195%2FJG3C9LM_R.png" alt="The Logitech Brio wecam"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;A &lt;a href="https://www.ncbi.nlm.nih.gov/pubmed/27128822" rel="noopener noreferrer"&gt;study&lt;/a&gt; published in &lt;em&gt;Cognitive Science&lt;/em&gt; decyphers how gestures improve the effectiveness of teaching. For this, of course, you will need a good webcam like &lt;a href="https://amzn.calandra.me/logi-brio" rel="noopener noreferrer"&gt;Logitech Brio&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;ProTip #3:&lt;/strong&gt; Logitech Brio has a wide-angle lens, so it can better capture your gesture.&lt;/p&gt;

&lt;p&gt;If you have a greater budget consider a DSLR camera like &lt;a href="https://amzn.calandra.me/canon-m200" rel="noopener noreferrer"&gt;Canon M200&lt;/a&gt; with &lt;a href="https://amzn.calandra.me/elgato-cam-link" rel="noopener noreferrer"&gt;Elgato CamLink&lt;/a&gt; to have a stunning quality.&lt;/p&gt;

&lt;h3&gt;
  
  
  4. Lights
&lt;/h3&gt;

&lt;p&gt;Natural light is great, but if you are streaming late at night or have poor quality lights in your room then this could be a problem.&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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1619772230621%2FAVEnCYuOE.jpeg" 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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1619772230621%2FAVEnCYuOE.jpeg" alt="A streaming setup with Elgato Key Light&amp;lt;br&amp;gt;
"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In this case, a classic lamp may not be useful as it would create strong shadows on the face, and therefore a set of soft-dimmable lights such as the &lt;a href="https://amzn.calandra.me/elgato-key-light" rel="noopener noreferrer"&gt;Elgato Key Light&lt;/a&gt; set may be better.&lt;/p&gt;

&lt;h3&gt;
  
  
  5. Presenter
&lt;/h3&gt;

&lt;p&gt;If during your class you are sitting at a desk, having your computer handy, you could skip this tool. On the contrary, if you like to deliver your presentation standing then a presenter, like the &lt;a href="https://amzn.calandra.me/logi-spotlight" rel="noopener noreferrer"&gt;Logitech Spotlight&lt;/a&gt;, is mandatory.&lt;/p&gt;

&lt;p&gt;It works as a normal presenter (next slide, previous slide,…) but, as a plus, it allows you to darken your screen, casting a spot of light just on the point of the discussion.&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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1619772314372%2FOggGgFjbC.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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1619772314372%2FOggGgFjbC.png" alt="An example of the spotlight effect"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The spot can be driven through hand movement and, if you are a traditionalist, can be replaced with a classic laser pointer effect.&lt;/p&gt;

&lt;p&gt;A great boon for online presentation!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;ProTip #4:&lt;/strong&gt; The &lt;em&gt;spotlight&lt;/em&gt; effect is fancy and cool but sometimes the thing that you want to highlight is bigger (or much smaller) than the spot of light; this will give an awkward sensation and, for this reason, the &lt;em&gt;virtual laser&lt;/em&gt; effect could be a better choice.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusions
&lt;/h2&gt;

&lt;p&gt;Tools hardly change the matter of things. A good trainer will be a good trainer even in a virtual classroom; a bad trainer will be a bad trainer even with better gears.&lt;/p&gt;

&lt;p&gt;Nevertheless, even the best trainer will lose part of effectiveness by moving from a real to a virtual class. The tips in this article are just an attempt to reduce this gap.&lt;/p&gt;

&lt;p&gt;Hope that helps. If you like this story and want to support click here and &lt;a href="https://goto.calandra.me/support" rel="noopener noreferrer"&gt;&lt;strong&gt;buy me a coffee&lt;/strong&gt;&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Take care and never stop teaching.&lt;br&gt;&lt;br&gt;
And learning!&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;em&gt;Note:&lt;/em&gt;&lt;/strong&gt; &lt;em&gt;Commissions may be earned from some of the links above.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;em&gt;Cover photo by &lt;a href="https://unsplash.com/@farber?utm_source=unsplash&amp;amp;utm_medium=referral&amp;amp;utm_content=creditCopyText" rel="noopener noreferrer"&gt;Jonathan Farber&lt;/a&gt; on &lt;a href="https://unsplash.com/s/photos/cables-microphone?utm_source=unsplash&amp;amp;utm_medium=referral&amp;amp;utm_content=creditCopyText" rel="noopener noreferrer"&gt;Unsplash&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

</description>
      <category>speaking</category>
      <category>trainers</category>
      <category>leadership</category>
    </item>
    <item>
      <title>Five books every serverless developer must read</title>
      <dc:creator>Mariano Calandra</dc:creator>
      <pubDate>Mon, 15 Mar 2021 09:41:26 +0000</pubDate>
      <link>https://dev.to/aws-builders/five-books-every-serverless-developer-must-read-3ioi</link>
      <guid>https://dev.to/aws-builders/five-books-every-serverless-developer-must-read-3ioi</guid>
      <description>&lt;h3&gt;
  
  
  Five books every serverless developer must read
&lt;/h3&gt;

&lt;p&gt;So here’s the thing: you are an experienced developer thrilled by the opportunities of serverless architectures. You read books, watch any possible video courses but when it comes to starts building a real serverless solution you feel completely naked; like if you are missing something.&lt;/p&gt;

&lt;p&gt;Over the years I have taught many developers and architects who had the same problem as you and all did one thing, apparently sensible but useless in practice. All of them focused (erroneously) on serverless, but &lt;strong&gt;serverless is just an execution model&lt;/strong&gt;, things that matter are elsewhere.&lt;/p&gt;

&lt;h3&gt;
  
  
  So what is serverless?
&lt;/h3&gt;

&lt;p&gt;Serverless is many things. It could be a serverless database, serverless storage, serverless runtime, and so on. It goes without saying that the latter represents the glue that binds any other serverless component together, so this is where we have to start.&lt;/p&gt;

&lt;p&gt;In this scenario, we have mainly two options: &lt;em&gt;serverless runtime based on containers&lt;/em&gt; (e.g. AWS Fargate) or &lt;em&gt;serverless runtime based on functions&lt;/em&gt; (e.g. AWS Lambda or Azure Functions). Despite differences, they have one thing in common: to work at their best, the applications hosted should be made of many small services rather than a single monolithic one.&lt;/p&gt;

&lt;h3&gt;
  
  
  Welcome Microservices
&lt;/h3&gt;

&lt;p&gt;Microservices architectures are an architectural style that structures the &lt;strong&gt;application as a collection of small services&lt;/strong&gt;. These services can communicate with each other so they can resolve a more complex business scenario.&lt;/p&gt;

&lt;p&gt;When these microservices have to be deployed, we can do so using containers or, if we prefer, using functions.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Microservices is a design concept.&lt;br&gt;
Containers or functions are just deployments offers.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;If you want to be successful in serverless adoption, you will first need solid microservices’ knowledge&lt;/strong&gt;. Only in this way you can be prepared and avoid the common pitfalls of serverless adoption.&lt;/p&gt;

&lt;p&gt;For this reason, I grouped together five books that every good serverless developer must read, and surprise, these books are mostly about microservices, rather than AWS, Azure, or serverless.&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Eric Evans — Domain-Driven Design: Tackling Complexity in the Heart of Software
&lt;/h3&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%2F0a5j4cs35mofz36z31l7.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%2F0a5j4cs35mofz36z31l7.png" alt="Eric Evans — Domain-Driven Design: Tackling Complexity in the Heart of Software"&gt;&lt;/a&gt;&lt;br&gt;
We said that microservices are a collection of small services. But does that means that microservices have to be small? How small they need to be?&lt;/p&gt;

&lt;p&gt;To answer these questions properly, we need to understand the business capabilities and design accordingly and that’s all this book is about.&lt;/p&gt;

&lt;p&gt;The volume is full of information and insight that would worth reading at least twice. People usually tend to focus on chapters 5 and 6 where the author defines the concept of Entities, Value Objects, and Aggregates, commonly known even outside the DDD community today.&lt;/p&gt;

&lt;p&gt;Even though these components are crucial I strongly suggest focusing attention on &lt;strong&gt;Ubiquitous Language and Bounded Contexts&lt;/strong&gt;. These concepts are core to our needs because can help to answer the question: how small a microservice should be?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href="https://amzn.calandra.me/ddd" rel="noopener noreferrer"&gt;Click here to buy Domain-Driven Design by Eric Evans&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Sam Newman — Building Microservices: Designing Fine-Grained Systems
&lt;/h3&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%2Fb1yfxsrhs3mmdt7c09vq.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%2Fb1yfxsrhs3mmdt7c09vq.png" alt="Sam Newman — Building Microservices: Designing Fine-Grained Systems"&gt;&lt;/a&gt;&lt;br&gt;
If you are new to microservices this is where you have to start. The book is generic enough and doesn’t require any knowledge of a particular programming language, that’s why I love it at first.&lt;/p&gt;

&lt;p&gt;The first three chapters start with a great introduction about the software world and microservices, then the book is well divided into categories (one for each chapter): Integration, Deployments, Testing, and so on, which makes it handy to find and (re)read a concept in the future.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href="https://amzn.calandra.me/building-microservices" rel="noopener noreferrer"&gt;Click here to buy Building Microservices by Sam Newman&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Richard Rodger — The Tao of Microservices
&lt;/h3&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%2F88gd14r0diq5s9g57xkl.jpg" 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%2F88gd14r0diq5s9g57xkl.jpg" alt="Richard Rodger — The Tao of Microservices"&gt;&lt;/a&gt;&lt;br&gt;
I fell in love with this book at the time because it explicitly talks about messages. The author invites the reader to avoid the temptation to design systems start thinking about services; rather he suggests starting from messages as their flow well describes the system behaviour.&lt;/p&gt;

&lt;p&gt;This way of thinking allows us to feed two birds with one scone. First, it naturally drives you into event-driven applications. Second, it &lt;strong&gt;simplifies the design of your system&lt;/strong&gt; (in this regard, I strongly suggest taking a look at&lt;br&gt;
Alberto Brandolini’s Event Storming workshop).&lt;/p&gt;

&lt;p&gt;Back to the book, as microservices completely change the way we think of data, Chapter 4 is essential, as you may discover a lot of things that will be useful when you are building serverless applications.&lt;/p&gt;

&lt;p&gt;Same for Chapter 6 (i.e. Measurement) which talks about the limits of traditional monitoring when it comes to microservices and FaaS.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href="https://amzn.calandra.me/tao-microservices" rel="noopener noreferrer"&gt;Click here to buy The Tao of Microservices by Richard Rodger&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  4. Chris Richardson — Microservices Patterns
&lt;/h3&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%2Ftbku8z2b9snxjk9ucst9.jpg" 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%2Ftbku8z2b9snxjk9ucst9.jpg" alt="Chris Richardson — Microservices Patterns"&gt;&lt;/a&gt;&lt;br&gt;
After a first introduction to the world of microservices, we can see in detail what are the industry best practices that we should adopt.&lt;/p&gt;

&lt;p&gt;In addition to a ritual introduction, the book focuses on what are the decomposition strategies, or how to think in terms of microservices and here Domain-Driven Design and its teachings come useful.&lt;/p&gt;

&lt;p&gt;Do you have a doubt about testing? Want to learn more about deployment strategies? Have you heard of patterns like circuit-breakers or saga but you don’t know what they are for? Then this book is the most authoritative source in&lt;br&gt;
which to find the answers.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href="https://amzn.calandra.me/microservices-patterns" rel="noopener noreferrer"&gt;Click here to buy Microservices Patterns by Chris Richardson&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  5. Ethan Garofolo — Practical Microservices: Build event-driven architectures with Event Sourcing and CQRS
&lt;/h3&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%2Fx5v6awd6w4hgy569b4lw.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%2Fx5v6awd6w4hgy569b4lw.png" alt="Ethan Garofolo — Practical Microservices: Build event-driven architectures with Event Sourcing and CQRS"&gt;&lt;/a&gt;&lt;br&gt;
After four books of theory, we close the series with a practical book, a real hands-on tutorial.&lt;/p&gt;

&lt;p&gt;The thing I like most about it is that, like for the Tao of Microservices, it too focuses on messages. It starts with these two hot topics — CQRS and Event Sourcing.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href="https://amzn.calandra.me/practical-microservices" rel="noopener noreferrer"&gt;Click here to buy Practical Microservices by Ethan Garofolo&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;We often read posts about the benefits of serverless; as I’m a strong advocate for serverless adoption I like to share these posts. However, the problem with this type of post is the illusion of having a silver bullet in your gun. This is&lt;br&gt;
not true as silver bullets do not exist.&lt;/p&gt;

&lt;p&gt;Serverless is a powerful weapon but you need to be trained or the recoil could hurt you. This post would like to prevent the problem.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Commissions may be earned from some of the links above.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>microservices</category>
      <category>serverless</category>
      <category>books</category>
      <category>aws</category>
    </item>
    <item>
      <title>How Chaos Engineering Practices Will Help You Design Better Software</title>
      <dc:creator>Mariano Calandra</dc:creator>
      <pubDate>Thu, 25 Feb 2021 06:16:43 +0000</pubDate>
      <link>https://dev.to/aws-builders/how-chaos-engineering-practices-will-help-you-design-better-software-4nfi</link>
      <guid>https://dev.to/aws-builders/how-chaos-engineering-practices-will-help-you-design-better-software-4nfi</guid>
      <description>&lt;blockquote&gt;
&lt;h3&gt;
  
  
  Wind extinguishes a candle and energizes fire.
&lt;/h3&gt;
&lt;h3&gt;
  
  
  Likewise with randomness, uncertainty, chaos; you want to use them, not hide from them.
&lt;/h3&gt;
&lt;/blockquote&gt;

&lt;p&gt;Thus begins the prologue to &lt;a href="https://amzn.calandra.me/antifragile" rel="noopener noreferrer"&gt;Antifragile by Nassim Nicholas Taleb&lt;/a&gt;, one of the most popular authors of recent years.&lt;/p&gt;

&lt;p&gt;What does the randomness have to do with our work as engineers? &lt;strong&gt;What does chaos have to do with cloud computing?&lt;/strong&gt; Much more than you can imagine and in this story, we will understand why.&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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1614109134979%2FZGO0fu6QD.jpeg" 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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1614109134979%2FZGO0fu6QD.jpeg" alt="Antifragile — Nassim Nicholas Taleb"&gt;&lt;/a&gt;&lt;em&gt;Fig.1 – Antifragile — Nassim Nicholas Taleb&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Generally, a cloud application is composed of various components: virtual machines, databases, load balancers and other services that by communicating with each other support our business. Complex and distributed systems which, as such, could suddenly fail.&lt;/p&gt;

&lt;p&gt;The answer to this type of problem has often resulted in a greater number of tests; mostly &lt;em&gt;end-to-end&lt;/em&gt; tests that stimulate all the layers of an application. A sort of &lt;em&gt;black-box testing&lt;/em&gt; where, in front of an input &lt;em&gt;A&lt;/em&gt;, an output &lt;em&gt;B&lt;/em&gt; is expected. If the answer is &lt;em&gt;C&lt;/em&gt;, &lt;em&gt;somewhere&lt;/em&gt; in the system &lt;em&gt;something&lt;/em&gt; went wrong.&lt;/p&gt;

&lt;p&gt;In some cases, such tests are stimulated at regular intervals on production systems to verify them over a 24-hour period, but in case of a failure, we won’t know much about the error.&lt;br&gt;
Even worse, this practice exposes us to another risk: &lt;em&gt;the&lt;/em&gt; &lt;em&gt;illusion of control&lt;/em&gt;. Each time a test is successfully completed, we become more and more convinced of the robustness of the system; day after day we become more and more proud of the excellent work done.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Black Swan
&lt;/h2&gt;

&lt;p&gt;A metaphor by Bertrand Russell, later &lt;a href="https://amzn.calandra.me/the-black-swan" rel="noopener noreferrer"&gt;adapted by the Taleb himself&lt;/a&gt;, tells the &lt;em&gt;“great turkey problem”&lt;/em&gt;:&lt;/p&gt;

&lt;blockquote&gt;
&lt;h3&gt;
  
  
  A turkey is fed for a thousand and more days; every day together with the other turkeys they takes pleasure in comfort of their life. Then comes Thanksgiving and being a turkey won’t have been cool at all.
&lt;/h3&gt;
&lt;/blockquote&gt;

&lt;p&gt;This &lt;em&gt;surprise&lt;/em&gt; represents what is called a &lt;em&gt;Black Swan&lt;/em&gt;: an unexpected event, with catastrophic effects.&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%2Fcdn-images-1.medium.com%2Fmax%2F3840%2F1%2AB_oyZAOL96_Va5follv-rA.jpeg" 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%2Fcdn-images-1.medium.com%2Fmax%2F3840%2F1%2AB_oyZAOL96_Va5follv-rA.jpeg" alt="Until 1697, when *Cygnus atratus* was discovered, no one thought black swans could exist. (photo [Holger Detje](https://cdn.hashnode.com/res/hashnode/image/upload/v1614109136294/cPHLvSBoJ.html) from [Pixabay](https://pixabay.com/?utm_source=link-attribution&amp;amp;utm_medium=referral&amp;amp;utm_campaign=image&amp;amp;utm_content=122983))"&gt;&lt;/a&gt;&lt;em&gt;Fig.2 – Until 1697, when Cygnus atratus was discovered, no one thought black swans could exist. (photo &lt;a href="https://pixabay.com/users/holgi-5825/?utm_source=link-attribution&amp;amp;utm_medium=referral&amp;amp;utm_campaign=image&amp;amp;utm_content=122983" rel="noopener noreferrer"&gt;Holger Detje&lt;/a&gt; from &lt;a href="https://pixabay.com/?utm_source=link-attribution&amp;amp;utm_medium=referral&amp;amp;utm_campaign=image&amp;amp;utm_content=122983" rel="noopener noreferrer"&gt;Pixabay&lt;/a&gt;)&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The (&lt;em&gt;fake) illusion of control&lt;/em&gt; forced the turkey to revise his beliefs about the comfort of his life, just as they were at their peak.&lt;br&gt;
Likewise, &lt;strong&gt;repeated positive end-to-end tests could lead us to the equally fallacious conclusion that our systems are indeed foolproof&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;This &lt;em&gt;superficiality of judgment&lt;/em&gt;, to use a lexicon dear to Taleb, exposes us to the Black swan: the possibility that an unforeseen problem could ruin our plans for the weekend.&lt;/p&gt;

&lt;p&gt;Possible examples of Black swans:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;server’s shutdown;&lt;/li&gt;
&lt;li&gt;database fail;&lt;/li&gt;
&lt;li&gt;CPU overhead;&lt;/li&gt;
&lt;li&gt;memory exhaustion;&lt;/li&gt;
&lt;li&gt;disk-space exhaustion;&lt;/li&gt;
&lt;li&gt;high network latencies;&lt;/li&gt;
&lt;li&gt;misconfigurations;&lt;/li&gt;
&lt;li&gt;insufficient permissions;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To protect your system from these and other issues, a cloud provider offers various possibilities. In AWS, to counter the sudden shutdown of a machine, the potentialities of the EC2 Auto Scaling service could be exploited; to mitigate the impact of a database fail, you could take advantage of Amazon RDS’s automatic failover mechanism, and so on.&lt;/p&gt;

&lt;p&gt;These tricks will certainly make our application less fragile, but will they reduce the chance of a Black Swan?&lt;/p&gt;

&lt;h2&gt;
  
  
  Antifragile
&lt;/h2&gt;

&lt;p&gt;By the term &lt;em&gt;«fragile»&lt;/em&gt;, in general, we mean an object that could be damaged – even irremediably – due to random events (e.g. a crystal glass that breaks after accidentally falling on the floor).&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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1614109137727%2FYdwQqhRHh.jpeg" 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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1614109137727%2FYdwQqhRHh.jpeg" alt="Copyright Elnur Amikishiyev"&gt;&lt;/a&gt;&lt;em&gt;Fig. 3 – Copyright Elnur Amikishiyev&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;On the contrary, terms such as &lt;em&gt;«robust»&lt;/em&gt; or &lt;em&gt;«resistant»&lt;/em&gt; are used to define objects which, upon the occurrence of random events, maintain the exact same initial properties.&lt;br&gt;
Randomness has made these objects neither better nor worse.&lt;/p&gt;

&lt;p&gt;With the term &lt;em&gt;«antifragile»&lt;/em&gt;, however, Taleb refers to everything that benefits from randomness and stress factors. The muscles of our body, for example, benefit from the right amount of stress, as this is a prerequisite for their growth.&lt;/p&gt;

&lt;p&gt;Returning to our systems, if everything we have done to counteract their fragility has ended with configuring the Auto Scaling feature, we will be &lt;em&gt;robust&lt;/em&gt; but not yet &lt;em&gt;antifragile&lt;/em&gt;; therefore still exposed to a Black Swan.&lt;/p&gt;

&lt;blockquote&gt;
&lt;h3&gt;
  
  
  If you want to become antifragile, place yourself in the “love error” position.
&lt;/h3&gt;
&lt;/blockquote&gt;

&lt;p&gt;Taleb offers us the main suggestion to avoid nasty surprises. To be antifragile, and reduce the chances of a Black Swan as much as possible, we have to crave for error.&lt;br&gt;
But what if we are in a situation where our end-to-end tests keep running smoothly and the error just doesn’t come?&lt;/p&gt;

&lt;h2&gt;
  
  
  Chaos engineering
&lt;/h2&gt;

&lt;p&gt;By &lt;em&gt;«chaos engineering»&lt;/em&gt; we mean the practice of deliberately injecting an error into a system, in order to observe, in vivo, the consequences.&lt;/p&gt;

&lt;blockquote&gt;
&lt;h3&gt;
  
  
  What would happen if, one of the production web servers, suddenly goes down?
&lt;/h3&gt;
&lt;/blockquote&gt;

&lt;p&gt;The main advantage of this approach, compared to the more classic &lt;em&gt;end-to-end test&lt;/em&gt;, comes from no longer having to depend on our assumptions. The impact of the mistake will be right before our eyes. By doing so, we will have the opportunity to highlight aspects of the system that we were not aware of: chain reactions, performance problems, metrics that escaped the monitoring tools and so on.&lt;/p&gt;

&lt;p&gt;Knowing the weak points of the system is already a great start, as it forces us not to let our guard down; what we will have to aim for, however, will be the resolution of those weaknesses. This improvement will make systems a little more &lt;em&gt;«antifragile»&lt;/em&gt;.&lt;br&gt;
The greater the error cases that we will be able to inject – and solve – the lower the chance of a Black Swan.&lt;/p&gt;

&lt;h3&gt;
  
  
  The process of chaos
&lt;/h3&gt;

&lt;p&gt;The choice of the word &lt;em&gt;«engineering»&lt;/em&gt; next to the word &lt;em&gt;«chaos»&lt;/em&gt; might sound like an oxymoron, but it isn’t; indeed, it well represents the essence of the process underlying the practice itself. Just as a scientific experiment has its well-coded phases, the chaos engineering experiment has its own.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Definition of the steady-state&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In this phase, we are going to make it clear what should be the &lt;em&gt;capacity&lt;/em&gt; of the system when there are no errors. This step is crucial and it will be essential to have monitoring infrastructures that allow us to accurately collect the metrics useful to define it. System metrics (e.g. CPU, memory) are certainly useful, but it would be even more useful to get business metrics:&lt;/p&gt;

&lt;blockquote&gt;
&lt;h3&gt;
  
  
  «Between 10am and 11am, an average of 100 orders per minute is handled»
&lt;/h3&gt;
&lt;/blockquote&gt;

&lt;p&gt;Or:&lt;/p&gt;

&lt;blockquote&gt;
&lt;h3&gt;
  
  
  «Between 8pm and 9pm the homepage is requested 1000 times»
&lt;/h3&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Formulation of a hypothesis&lt;/strong&gt;&lt;br&gt;
Once this is done we will formulate a hypothesis; that is, we will try to imagine what the system behaviour might be following a specific error.&lt;/p&gt;

&lt;blockquote&gt;
&lt;h3&gt;
  
  
  «What would happen if a webserver fails?»
&lt;/h3&gt;
&lt;/blockquote&gt;

&lt;p&gt;Or:&lt;/p&gt;

&lt;blockquote&gt;
&lt;h3&gt;
  
  
  «What if communication with the database suddenly had an extra 100ms latency?»
&lt;/h3&gt;
&lt;/blockquote&gt;

&lt;p&gt;A useful exercise at this stage would be to ask each team member for answers to the above questions. This practice should not have the purpose of finding the first or last of the class but, simply, to show how, in some cases, the knowledge of the system can vary between members of the same team.&lt;/p&gt;

&lt;p&gt;Another way to remind everyone to stay prepared.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Definition of a &lt;em&gt;stop-condition&lt;/em&gt;&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;It will be crucial to understand when and how to stop the experiment.&lt;/p&gt;

&lt;p&gt;The &lt;em&gt;when&lt;/em&gt; can be manual, timed or dynamic. We will resort to manual blocking if we realize that the experiment is having unexpected consequences. Time, on the other hand, is the &lt;em&gt;upper limit&lt;/em&gt;, that is the maximum time within which, for better or for worse, the experiment will have to end. Finally, a &lt;em&gt;dynamic stop-condition&lt;/em&gt; will block the experiment if our monitoring tool signals an alarm situation (eg: the average of orders has fallen by 70% for more than five minutes).&lt;/p&gt;

&lt;p&gt;&lt;em&gt;How&lt;/em&gt; to stop the experiment is a bit more complex and depends on the available tool.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Run the experiment&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Once this is done, we just have to launch our experiment and inject the errors we had foreseen when defining the hypotheses. Easy to say, a little less to do. Until recently, the practice of chaos engineering required good scripting skills to make the occurrence of the error programmatic.&lt;/p&gt;

&lt;p&gt;This made chaos engineering less accessible to unstructured teams, reducing the practice to the prerogative of a bunch of large groups. Not surprisingly, some of the most famous chaos engineering scripts were those created within Netflix in the Simian Army project, such as &lt;em&gt;chaos monkey:&lt;/em&gt; a script that randomly knocked down production machines.&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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1614109139878%2FiP_8Ly90b.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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1614109139878%2FiP_8Ly90b.png" alt="The Netflix Simian Army logo."&gt;&lt;/a&gt;&lt;em&gt;Fig. 4 – The Netflix Simian Army logo.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Nowadays, the need for this type of practice is raising and advanced tools for chaos engineering are starting to become available. At re:Invent 2020, AWS unveiled Fault Injection Simulator (FIS) a fully-managed service for injecting errors into our systems.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;System improvement&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The most interesting work comes after the experiment. There we can learn more about our system by asking ourselves questions like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;how did our system behave?&lt;/li&gt;
&lt;li&gt;the countermeasures (ex: autoscaling, failover, circuit-breaker) have managed the error?&lt;/li&gt;
&lt;li&gt;Were there any unexpected errors in other parts of the system?&lt;/li&gt;
&lt;li&gt;Were there any performance problems?&lt;/li&gt;
&lt;li&gt;Was the error detected by our monitoring tools?&lt;/li&gt;
&lt;li&gt;How long did it take to get restored?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The answers and any solutions to these questions will then be prioritized and applied as soon as possible. By doing this we will be a little safer from a Black Swan.&lt;/p&gt;

&lt;h3&gt;
  
  
  Chaos Engineering in production (?)
&lt;/h3&gt;

&lt;p&gt;To take advantage of chaos engineering as much as possible, the experiments must be launched into production. Point.&lt;/p&gt;

&lt;p&gt;However, this practice carries its own risks and thinking of starting &lt;em&gt;directly&lt;/em&gt; from production would be a bit risky. Better to start with experiments in development scenarios, and then, as soon as we feel a little more confident and practical, move towards staging and, why not, production.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;The conclusions to this article are obvious and can be summarized once again by quoting Taleb’s words: &lt;em&gt;«Don’t be a turkey!»&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;That is, &lt;strong&gt;we have to avoid simplistically believing that, in the absence of errors for an extended period, we are safe from any risk&lt;/strong&gt;. A Black Swan can always be on the prowl and show up as soon as we let our guard down.&lt;/p&gt;

&lt;p&gt;Instead, we have to try to stress our system, injecting the most probable errors, observing its behaviour in search of any unpredictable behaviour. Only in this way will we be able to truly know our system and be a little more confident in its ability to withstand error and our ability to know how to manage it properly.&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%2Fcdn-images-1.medium.com%2Fmax%2F10944%2F1%2Aiu1-OWC0n0hTicIP7jzp4w.jpeg" 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%2Fcdn-images-1.medium.com%2Fmax%2F10944%2F1%2Aiu1-OWC0n0hTicIP7jzp4w.jpeg" alt="Photo by [Andrew Gaines](https://cdn.hashnode.com/res/hashnode/image/upload/v1614109141743/DGA-e4Svf.html) on [Unsplash](https://unsplash.com/s/photos/firefighter?utm_source=unsplash&amp;amp;utm_medium=referral&amp;amp;utm_content=creditCopyText)"&gt;&lt;/a&gt;&lt;em&gt;Fig. 5 – Photo by &lt;a href="https://unsplash.com/@shotbygaines?utm_source=unsplash&amp;amp;utm_medium=referral&amp;amp;utm_content=creditCopyText" rel="noopener noreferrer"&gt;Andrew Gaines&lt;/a&gt; on &lt;a href="https://unsplash.com/s/photos/firefighter?utm_source=unsplash&amp;amp;utm_medium=referral&amp;amp;utm_content=creditCopyText" rel="noopener noreferrer"&gt;Unsplash&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;In a 2011 talk, Jesse Robbins, a volunteer firefighter then hired at AWS with the title of &lt;em&gt;Master of Disaster&lt;/em&gt;, reported the phrase they teach every firefighter on the first day of training school:&lt;/p&gt;

&lt;blockquote&gt;
&lt;h3&gt;
  
  
  You don’t choose the moment, the moment chooses you.
&lt;/h3&gt;
&lt;h3&gt;
  
  
  You only choose how prepared you are when it does.
&lt;/h3&gt;
&lt;h3&gt;
  
  
  — Fire Chief Mike Burtch
&lt;/h3&gt;
&lt;/blockquote&gt;

&lt;p&gt;Let’s never forget that.&lt;/p&gt;

&lt;h2&gt;
  
  
  Further reading
&lt;/h2&gt;

&lt;p&gt;The ideas, the concepts and this article itself would not have seen the light without the precious insights mentioned below.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Books&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://amzn.calandra.me/the-black-swan" rel="noopener noreferrer"&gt;Nassim Nicholas Taleb – The Black Swan&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://amzn.calandra.me/antifragile" rel="noopener noreferrer"&gt;Nassim Nicholas Taleb – Antifragile&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://amzn.calandra.me/chaos-engineering" rel="noopener noreferrer"&gt;Casey Rosenthal &amp;amp; Nora Jones – Chaos Engineering&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Web&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://principlesofchaos.org/" rel="noopener noreferrer"&gt;Principle of Chaos Engineering&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;AWS Blog – &lt;a href="https://aws.amazon.com/blogs/opensource/building-resilient-services-at-prime-video-with-chaos-engineering/" rel="noopener noreferrer"&gt;Building Resilient services at Prime Video with Chaos Engineering&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://twitter.com/adhorn" rel="noopener noreferrer"&gt;Adrian Hornsby&lt;/a&gt; – Chaos Engineering pt.1&lt;/li&gt;
&lt;li&gt;Pavlos Ratis – &lt;a href="https://github.com/dastergon/awesome-chaos-engineering" rel="noopener noreferrer"&gt;Chaos Engineering resources&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Jesse Robbins – &lt;a href="https://www.youtube.com/watch?v=zoz0ZjfrQ9s" rel="noopener noreferrer"&gt;GameDay: Creating Resiliency Through Destruction&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;If you liked this post, please consider to &lt;a href="https://goto.calandra.me/support" rel="noopener noreferrer"&gt;support me&lt;/a&gt;&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Commissions may be earned from some of the link above.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>aws</category>
      <category>distributedsystems</category>
      <category>chaosengineering</category>
      <category>microservices</category>
    </item>
    <item>
      <title>Why do we need the JSON Web Token (JWT) in the modern web?</title>
      <dc:creator>Mariano Calandra</dc:creator>
      <pubDate>Mon, 15 Feb 2021 09:21:19 +0000</pubDate>
      <link>https://dev.to/aws-builders/why-do-we-need-the-json-web-token-jwt-in-the-modern-web-5702</link>
      <guid>https://dev.to/aws-builders/why-do-we-need-the-json-web-token-jwt-in-the-modern-web-5702</guid>
      <description>&lt;p&gt;Hold on tight: the &lt;strong&gt;HTTP protocol is terribly flawed&lt;/strong&gt; and when it comes to user authentication this &lt;em&gt;problem&lt;/em&gt; screams loudly.&lt;/p&gt;

&lt;p&gt;For a long time we, as developers, fought with it: sometimes with good results, sometimes not, but we thought we were happy.&lt;br&gt;
Unfortunately, the web moves fast and many of these solutions were getting old too quickly.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;He who hesitates is lost…&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Later on, a group of people realised that it was time to stop fighting with the &lt;em&gt;“problem”&lt;/em&gt; and try to embrace it. The result of that epiphany is called JSON Web Token (JWT for short) and here we will try to tell its story…&lt;/p&gt;
&lt;h2&gt;
  
  
  Once upon a time
&lt;/h2&gt;

&lt;p&gt;Suppose you have a &lt;a href="https://en.wikipedia.org/wiki/Representational_state_transfer"&gt;REST API&lt;/a&gt; (e.g. &lt;code&gt;GET /orders&lt;/code&gt;) and you want to restrict access to authorized users only. &lt;br&gt;
In the most naïve approach, the API would ask for a username and password; then it will be searched in a database for whether those credentials really exist. We check for &lt;em&gt;authenticity&lt;/em&gt;. Finally, it will be checked if the &lt;em&gt;authenticated&lt;/em&gt; user is also &lt;em&gt;authorized&lt;/em&gt; to perform that request. If both checks pass, the real API will be executed. It seems logical.&lt;/p&gt;
&lt;h3&gt;
  
  
  A problem of state
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;The HTTP protocol is *stateless&lt;/strong&gt;&lt;em&gt;, this means a new request (e.g. &lt;code&gt;GET /order/42&lt;/code&gt;) won’t know anything about the previous one, **so&lt;/em&gt;* &lt;strong&gt;we need to reauthenticate for each new request&lt;/strong&gt; (fig.1).&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--aaezMsg3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1612451487539/TB1-a3nba.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--aaezMsg3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1612451487539/TB1-a3nba.png" alt="Fig. 1 — Due to the stateless nature of HTTP protocol, every new API request needs a complete authentication."&gt;&lt;/a&gt;&lt;em&gt;Fig. 1 — Due to the stateless nature of HTTP protocol, every new API request needs a complete authentication.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The traditional way of dealing with this is the use of *Server Side Sessions *(SSS).&lt;/strong&gt; In this scenario, we first check for username and password; if they are authentic, the server will save a &lt;em&gt;session id&lt;/em&gt; in memory and return it to the client. From now on, the client will just need to send its *session id *to be recognized (fig.2).&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--koZxv8OS--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1612451489436/3Yl-YBQVS.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--koZxv8OS--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1612451489436/3Yl-YBQVS.png" alt="Fig. 2–Using SSS, we reduce the number of authentications towards the Credentials database."&gt;&lt;/a&gt;&lt;em&gt;Fig. 2–Using SSS, we reduce the number of authentications towards the Credentials database.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;This solution will fix a problem but it will create another one. &lt;br&gt;
Probably bigger.&lt;/p&gt;
&lt;h3&gt;
  
  
  A problem of scale
&lt;/h3&gt;

&lt;p&gt;In the IT world, time goes fast and a solution that yesterday was commonly used, might be outdated now. Server Side Sessions are one of these.&lt;/p&gt;

&lt;p&gt;In the API era, our endpoints can face a huge amount of requests, so our infrastructures needs to scale. There are two types of scaling:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;*vertical scaling – *scaling up your infrastructure merely means adding more resources to a server. This is an expensive solution with a low upper limit (i.e. the server’s maximum allocation of resources);&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;*horizontal scaling – *scaling out your infrastructure is simpler and more cost-effective as it only involves adding a new server behind a &lt;a href="https://en.wikipedia.org/wiki/Load_balancing_(computing)"&gt;load balancer&lt;/a&gt;;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now it’s seems pretty clear that the second approach will be far most beneficial; but let’s take a look at what may happen.&lt;/p&gt;

&lt;p&gt;In the initial scenario, behind the load balancer, there’s just one server. When a client performs a request, using session id &lt;code&gt;xyz&lt;/code&gt;, its record will surely be found in the server’s memory (fig.3).&lt;/p&gt;

&lt;p&gt;So far, so good.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--970it_mi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1612451491936/SZF9eQ7Jf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--970it_mi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1612451491936/SZF9eQ7Jf.png" alt="Fig. 3–One single server behind the load balancer. The session id of the request will be found in memory."&gt;&lt;/a&gt;&lt;em&gt;Fig. 3–One single server behind the load balancer. The session id of the request will be found in memory.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Now imagine that the above infrastructure needs to scale. A new server (i.e. &lt;em&gt;Server 2:2&lt;/em&gt;) will be added behind the load balancer and this brand new server will handle the next request issued by &lt;code&gt;xyz&lt;/code&gt; client…&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--OjoSIwZg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1612451493694/t9zeNzwYN.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--OjoSIwZg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1612451493694/t9zeNzwYN.png" alt="Fig.4–A new server is behind the LB, it knows nothing about the previous session so the user won’t be recognized."&gt;&lt;/a&gt;&lt;em&gt;Fig.4–A new server is behind the LB, it knows nothing about the previous session so the user won’t be recognized.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Unauthenticated! The brand new server has no &lt;code&gt;xyz&lt;/code&gt; sessions in its memory, so the authentication process will fail. To fix this, we have three main &lt;em&gt;workarounds&lt;/em&gt; that can be used:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;*Synchronize sessions between server*s — tricky and error-prone;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;em&gt;Use an external in-memory database&lt;/em&gt; — good solution, but it will add another component to the infrastructure;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Third: &lt;strong&gt;embrace the stateless nature of HTTP&lt;/strong&gt; and search for a better solution!&lt;/p&gt;
&lt;h2&gt;
  
  
  The better solution
&lt;/h2&gt;

&lt;p&gt;JSON Web Token (JWT) is an open standard (&lt;a href="https://tools.ietf.org/html/rfc7519"&gt;RFC 7519&lt;/a&gt;) that defines a way for transmitting information –like authentication and authorization facts– between two parties: an &lt;em&gt;issuer&lt;/em&gt; and an &lt;em&gt;audience&lt;/em&gt;. Communication is safe because each token issued is digitally signed, so the consumer can verify if the token is authentic or has been forged.&lt;/p&gt;

&lt;p&gt;Each token is &lt;em&gt;self-contained&lt;/em&gt;, this means it contains all information needed to allow or deny any given requests to an API. To understand how we can verify a token and how authorization happens, we need to take a step back and look into a JWT.&lt;/p&gt;
&lt;h3&gt;
  
  
  Anatomy of a JWT
&lt;/h3&gt;

&lt;p&gt;A JSON Web Token is essentially a long encoded text string. This string is composed of three smaller parts, separated by a dot sign. These parts are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;the header;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;a payload or body;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;a signature;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Therefore, our tokens will look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;header.payload.signature
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Header
&lt;/h4&gt;

&lt;p&gt;The header section contains information about the token itself.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"kid"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"ywdoAL4WL...rV4InvRo="&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"alg"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"RS256"&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The following JSON explains which algorithm has been used to sign the token (&lt;code&gt;alg&lt;/code&gt;) and which is the key (&lt;code&gt;kid&lt;/code&gt;) that we need to use to validate it. One moment of patience, please, we will look into this soon. :)&lt;/p&gt;

&lt;p&gt;The JSON is finally encoded as Base64URL:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;eyJraWQiOiJ -TRUNCATED- JTMjU2In0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Payload or body
&lt;/h4&gt;

&lt;p&gt;The payload is the most important part of a JWT. It contains information (&lt;em&gt;claims&lt;/em&gt; in JWT jargon) about the client:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="err"&gt;...&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"iss"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"https://cognito-idp.eu-west-1.amazonaws.com/XXX"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Mariano Calandra"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"admin"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;iss&lt;/code&gt; property is a &lt;a href="https://tools.ietf.org/html/rfc7519#section-4.1"&gt;registered claim&lt;/a&gt;, it represents the identity provider that issued the token — in this case, &lt;a href="https://aws.amazon.com/cognito/"&gt;Amazon Cognito&lt;/a&gt;. Finally, we can add further claims based on our needs (e.g. &lt;code&gt;admin&lt;/code&gt; claim).&lt;/p&gt;

&lt;p&gt;The payload is then encoded as Base64URL:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;eyJzdWIiOiJkZGU5N2Y0ZC0wNmQyLTQwZjEtYWJkNi0xZWRhODM1YzExM2UiLCJhdWQiOiI3c2Jzamh -TRUNCATED- hbnRfaWQiOiJ4cGVwcGVycy5jb20iLCJleHAiOjE1N jY4MzQwMDgsImlhdCI6MTU2NjgzMDQwOH0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Signature
&lt;/h4&gt;

&lt;p&gt;The third part of the token is a hash that is computed following these steps:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;join with a dot the encoded header and the encoded payload;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;hash the result using the encryption algorithm specified in &lt;code&gt;alg&lt;/code&gt; property of the header (in this case RS256) and a private key;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;encode the result as Base64URL;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Here we can look at it as pseudo-code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;base64UrlEncode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;header&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;.&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;base64UrlEncode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;payload&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;hash&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;RS256&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;private_key&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;signature&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;base64UrlEncode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;hash&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And here it is the computed signature:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;POstGetfAytaZS82wHcjoTyoqhMyxXiWdR7Nn7A29DNSl0EiXLdwJ6xC6AfgZWF1bOsS_TuYI3OG85 -TRUNCATED- FfEbLxtF2pZS6YC1aSfLQxeNe8djT9YjpvRZA
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Put everything together
&lt;/h4&gt;

&lt;p&gt;Once we have the encoded header, the encoded payload and the encoded signature, we can join everything together simply by merging every piece with a dot:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;eyJzdWIiOiJkZGU5N2Y0ZC0wNmQyLTQwZjEtYWJkNi0xZWRhODM1YzExM2UiLCJhdWQiOiI3c2Jzamh -TRUNCATED- hbnRfaWQiOiJ4cGVwcGVycy5jb20iLCJleHAiOjE1N jY4MzQwMDgsImlhdCI6MTU2NjgzMDQwOH0.eyJzdWIiOiJkZGU5N2Y0ZC0wNmQyLTQwZjEtYWJkNi0xZWRhODM1YzExM2UiLCJhdWQiOiI3c2Jzamh -TRUNCATED- hbnRfaWQiOiJ4cGVwcGVycy5jb20iLCJleHAiOjE1N jY4MzQwMDgsImlhdCI6MTU2NjgzMDQwOH0.POstGetfAytaZS82wHcjoTyoqhMyxXiWdR7Nn7A29DNSl0EiXLdwJ6xC6AfgZWF1bOsS_TuYI3OG85 -TRUNCATED- FfEbLxtF2pZS6YC1aSfLQxeNe8djT9YjpvRZA
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; Even if the above token seems encrypted, it isn’t! Unlike RS256, &lt;strong&gt;Base64URL is not an encryption algorithm&lt;/strong&gt;, so mind your payload!&lt;/p&gt;

&lt;h3&gt;
  
  
  JWT validation
&lt;/h3&gt;

&lt;p&gt;Since the token is self-contained, we own all the information needed for its validation. For example, we know the token has been signed using RS256 (&lt;code&gt;alg&lt;/code&gt; property of the header) and a private key. Now we need to know &lt;strong&gt;how to get the right public key to perform the validation&lt;/strong&gt;. Yes, the public key!&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; In asymmetric encryption, we all know that a public key is used to encrypt a message, whereas a private key is used to decrypt it.&lt;br&gt;
In a signing algorithm, this process is completely switched! Here the message (the &lt;code&gt;data&lt;/code&gt; in the pseudo-code above) is signed using the private key and the public key is used to verify that the signature is valid.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The &lt;code&gt;iss&lt;/code&gt; property of the body represents the endpoint of the issuer (Amazon Cognito in our case, but there should be no great differences with other providers), copy that URI and prepend it to the string&lt;code&gt;/.well-known/jwks.json&lt;/code&gt;. It should look something like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;https://cognito-idp.eu-west-1.amazonaws.com/XXX/.well-known/jwks.json
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Following this URL, we will find a JSON:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"keys"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"alg"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"RS256"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"e"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"AQAB"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"kid"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"ywdoAL4WL...rV4InvRo="&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"kty"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"RSA"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"n"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"m7uImGR -TRUNCATED AhaabmiCq5WMQ"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"use"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"sig"&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="err"&gt;...&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the &lt;code&gt;keys&lt;/code&gt; array, search for the element that has the same &lt;code&gt;kid&lt;/code&gt; of the token’s header. The properties &lt;code&gt;e&lt;/code&gt; and &lt;code&gt;n&lt;/code&gt; are the &lt;em&gt;public exponent&lt;/em&gt; and &lt;em&gt;modulus&lt;/em&gt; that compute the public key.&lt;/p&gt;

&lt;p&gt;Once we get it, we can verify the signature. If it’s valid, we can be sure that the information contained in the token is trusted.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; The process of public key calculation or sign verification is not easy and is beyond the scope of this post.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  A real case scenario
&lt;/h2&gt;

&lt;p&gt;At the first access, a client needs to contact the *authentication server *(Amazon Cognito here, but Microsoft, Salesforce or any other provider should be pretty similar), sending username and password to it. If credentials are valid, a JWT token will be returned to the client that will use it to request an API (in this example Amazon API Gateway endpoint).&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--lX6GQbBo--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1612451495188/9CbHXi4xM.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--lX6GQbBo--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1612451495188/9CbHXi4xM.png" alt="Fig.5 — The complete flow of a real case scenario."&gt;&lt;/a&gt;&lt;em&gt;Fig.5 — The complete flow of a real case scenario.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;In the above scenario (fig.5), API itself is the only responsible for token validation and it’s able to reject the request if the signature seems forged.&lt;/p&gt;

&lt;h4&gt;
  
  
  Going further
&lt;/h4&gt;

&lt;p&gt;Suppose a client wants to invoke a protected API to delete an order (e.g. &lt;code&gt;DELETE /order/42&lt;/code&gt;) and this action should be only performed by administrators.&lt;/p&gt;

&lt;p&gt;With a JWT in place, this operation is hard as add a custom claim to the payload body (i.e. the &lt;code&gt;admin: true&lt;/code&gt; claim of the example above). When invoked, the API will first verify the signature authenticity and afterwards, it’ll check if &lt;code&gt;admin&lt;/code&gt; claim is &lt;code&gt;true&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Summary
&lt;/h2&gt;

&lt;p&gt;In this article, we have seen many things about JWT with the aim to provide a historical and conceptual perspective of the topic. &lt;br&gt;
If you need a more hands-on guide &lt;a href="https://medium.com/swlh/how-to-protect-apis-with-jwt-and-api-gateway-lambda-authorizer-1110ff035df1"&gt;here you can read how to protect APIs with JWT and API Gateway Lambda Authorizer&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;That’s all for now but something still misses:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;How do we configure Amazon Cognito to get a JWT token?&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;How do we configure Amazon Cognito to add a custom claim?&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Don’t worry, we have room for answering this questions in a later story. For now, let’s summarise some key points:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;HTTP protocol is stateless, that means a new request won’t know anything about the previous one;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Server Side Sessions was a solution to the statelessness of HTTP, but these, in the long run, were a threat to our scaling abilities;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;JWT is &lt;em&gt;self-contained&lt;/em&gt;, that means it contains every information needed to allow or deny any given requests to an API;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;JWT is stateless by design, so we don’t have to fight with the stateless design of HTTP;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;JWT is encoded, not encrypted have it in mind;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Disclaimer
&lt;/h3&gt;

&lt;p&gt;Stateless nature of HTTP is clearly not a flaw. Just a provocation :)&lt;/p&gt;

&lt;p&gt;If you liked this post, please &lt;a href="https://goto.calandra.me/support"&gt;support my work&lt;/a&gt;!&lt;/p&gt;

</description>
      <category>jwt</category>
      <category>aws</category>
      <category>microservices</category>
      <category>api</category>
    </item>
    <item>
      <title>What Is Amazon Cognito User Pool and How Does It Differ From a Cognito Identity Pool</title>
      <dc:creator>Mariano Calandra</dc:creator>
      <pubDate>Mon, 01 Feb 2021 10:06:24 +0000</pubDate>
      <link>https://dev.to/aws-builders/what-is-amazon-cognito-user-pool-and-how-does-it-differ-from-a-cognito-identity-pool-4b2</link>
      <guid>https://dev.to/aws-builders/what-is-amazon-cognito-user-pool-and-how-does-it-differ-from-a-cognito-identity-pool-4b2</guid>
      <description>&lt;p&gt;Amazon Cognito is an AWS service that lets you easily add users’ management to web and mobile apps. It supports social identity providers, such as Facebook, Google and enterprise identity providers via SAML 2.0.&lt;/p&gt;

&lt;p&gt;A powerful service. &lt;/p&gt;

&lt;p&gt;At first, hard to understand.&lt;/p&gt;

&lt;p&gt;One of the things that generate the biggest confusion is the fact that Amazon Cognito comes with two main components:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Amazon Cognito User Pools&lt;/li&gt;
&lt;li&gt;Amazon Cognito Identity Pools (aka Federated Identities)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This is the first blocker because, in the common language, &lt;em&gt;users&lt;/em&gt; and &lt;em&gt;identities&lt;/em&gt; are almost the same things.&lt;br&gt;
In this brief story, we will try to clarify real differences and what scenarios can be solved using one of these components or combining the two.&lt;/p&gt;

&lt;h2&gt;
  
  
  Cognito User Pool
&lt;/h2&gt;

&lt;p&gt;According to the AWS official documentation:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;A user pool is a user directory in Amazon Cognito. With a user pool, your users can sign in to your web or mobile app through Amazon Cognito […]&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This means an anonymous user of our application (e.g. a mobile or a Single Page Application) can fill a registration form and then become a registered user. The chosen &lt;strong&gt;credentials (i.e. username and password) will be safely stored into Cognito User Pool&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;In this case, Amazon Cognito acts as an &lt;em&gt;Identity Provider (IdP)&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;When this registered user wants to log in, the &lt;strong&gt;User Pool will be used as the source of truth to assess the authenticity of provided credentials; if valid, a JSON Web Token (JWT) will be returned&lt;/strong&gt; (click here, if you want to know more about JWT).&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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1612127513013%2FlghQOam3J.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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1612127513013%2FlghQOam3J.png" alt="1.png"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Fig. 1 – During a user’s login, Cognito User Pool will handle the credential’s verification process, if valid, a JWT will be issued. This token could be eventually used to invoke protected APIs.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Eventually, if we have a protected API (e.g. &lt;code&gt;GET /orders/42&lt;/code&gt;) this token can be used to authenticate requests (fig.2) through the &lt;code&gt;Authorization&lt;/code&gt; header.&lt;/p&gt;

&lt;p&gt;If this API has been created using Amazon API Gateway, there’s the opportunity to easily protect it through the Cognito User Pool. In this scenario, API Gateway will ask Amazon Cognito User Pool to validate that token; if successful the backend Lambda function will be invoked.&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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1612127780030%2FytVYKwEd3.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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1612127780030%2FytVYKwEd3.png" alt="2.png"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Fig.2 – API Gateway can be integrated natively with Cognito User Pool to validate the provided JWT.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Easy like Sunday morning.&lt;/p&gt;

&lt;p&gt;But what if our application needs to interact &lt;em&gt;directly&lt;/em&gt; with DynamoDB (fig.3)?&lt;/p&gt;

&lt;h2&gt;
  
  
  Cognito Identity Pool
&lt;/h2&gt;

&lt;p&gt;Usually, REST APIs are protected through the use of a token – &lt;em&gt;e.g. a JSON Web Token (JWT)&lt;/em&gt; – and that’s why Amazon API Gateway with the help of Cognito User Pool supports this scenario natively.&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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1612128126932%2FYPUU3nnth.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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1612128126932%2FYPUU3nnth.png" alt="Fig.3 – Sometimes your client application may want to access directly to an AWS service (e.g. DynamoDB) without the API Gateway as a proxy. Will the JWT still be useful?"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Fig.3 – Sometimes your client application may want to access directly to an AWS service (e.g. DynamoDB) without the API Gateway as a proxy. Will the JWT still be useful?&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Alas, &lt;strong&gt;the vast majority of AWS resources, doesn’t support a JWT as a means of authentication&lt;/strong&gt;! For instance, if our application would read the order item 42 &lt;em&gt;directly&lt;/em&gt; from DynamoDB, we need an IAM Role that has the permission to read data from the &lt;em&gt;Orders&lt;/em&gt; table.&lt;/p&gt;

&lt;p&gt;And here it comes Cognito Identity Pool:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Identity pools provide AWS credentials to grant your users access to other AWS services.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Here, &lt;em&gt;“your users”&lt;/em&gt; are the users registered into our Cognito User Pool.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;To enable users in your user pool to access AWS resources, you can configure an identity pool to exchange user pool tokens for AWS credentials.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;To enable these users &lt;strong&gt;to access directly to DynamoDB and read the given order, we can’t use JWT straight; but we have to use Cognito Identity Pool to trade JWT with an access key and secret key&lt;/strong&gt; (fig.4).&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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1612128436090%2FyizTrQazH.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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1612128436090%2FyizTrQazH.png" alt="Fig. 4"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Fig.4&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Each couple of keys has an IAM role associated with the right set of permission.&lt;/p&gt;

&lt;p&gt;Here, thanks to the Identity Pool, Amazon Cognito acts as an &lt;em&gt;Identity Broker&lt;/em&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Some caveats
&lt;/h2&gt;

&lt;p&gt;In a simple scenario everything can be summarised in a general rule:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;If our application needs to access an API Gateway endpoint then, Cognito User Pool is sufficient.&lt;/p&gt;

&lt;p&gt;If our application needs to talk directly with an AWS service (DynamoDB, S3, …) we need Amazon Cognito Identity Pool too.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Unlikely, things are not necessarily black or white and real life has many nuances. For instance, our application could have users registered on a third-party Identity Provider and, in this case, we would use Cognito Identity Pool but not Cognito User Pool (more info in the &lt;em&gt;Further reading&lt;/em&gt; section).&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Even the most mundane things, if not well understood, will seem difficult. Amazon Cognito is no exception. I hope this story helps those who did not have a very clear understanding of the topic.&lt;/p&gt;

&lt;h2&gt;
  
  
  Further reading
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt; &lt;a href="https://docs.aws.amazon.com/cognito/latest/developerguide/what-is-amazon-cognito.html" rel="noopener noreferrer"&gt;What is Amazon Cognito&lt;/a&gt; &lt;/li&gt;
&lt;li&gt; &lt;a href="https://docs.aws.amazon.com/cognito/latest/developerguide/cognito-scenarios.html" rel="noopener noreferrer"&gt;Common Amazon Cognito Scenarios&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

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