<?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: Enrique Riesgo</title>
    <description>The latest articles on DEV Community by Enrique Riesgo (@eriesgo).</description>
    <link>https://dev.to/eriesgo</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%2F466727%2F30261b90-189a-478f-a884-6a18576fd236.jpeg</url>
      <title>DEV Community: Enrique Riesgo</title>
      <link>https://dev.to/eriesgo</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/eriesgo"/>
    <language>en</language>
    <item>
      <title>Back to Java</title>
      <dc:creator>Enrique Riesgo</dc:creator>
      <pubDate>Wed, 03 Nov 2021 08:50:54 +0000</pubDate>
      <link>https://dev.to/eriesgo/back-to-java-8lg</link>
      <guid>https://dev.to/eriesgo/back-to-java-8lg</guid>
      <description>&lt;p&gt;I stopped learning and programming Java and JEE 12 years ago. Since then, too many things had happened in the field and today I am starting a collection of posts trying to refresh my knowledge about the technology that was revolutionary in the 90's and mainstream in the 00's.&lt;/p&gt;

&lt;p&gt;So today, I will start with the basics.&lt;/p&gt;

&lt;h1&gt;
  
  
  What is the current version of Java
&lt;/h1&gt;

&lt;p&gt;According to &lt;a href="https://dev.java/" rel="noopener noreferrer"&gt;dev.java&lt;/a&gt; latest version of Java is &lt;strong&gt;17&lt;/strong&gt;. Wow! I was once certified in JSE 1.4 👴🏻 There is a good collection of articles &lt;a href="https://dev.java/learn/" rel="noopener noreferrer"&gt;there&lt;/a&gt; about how to learn Java in that web page, that covers from the basics to the JVM. If I finally want to fully refresh my Java dev skills probably I would start there.&lt;/p&gt;

&lt;p&gt;However, I was more interested in understanding the history and evolution of Java since version 1.4 to nowadays to catch up fast on the features that were added and how to leverage them. So the answer is in the &lt;a href="https://en.wikipedia.org/wiki/Java_version_history" rel="noopener noreferrer"&gt;Wikipedia's article about version history&lt;/a&gt;. If you are planning to recycle yourself, it is worth to spend some time to see the evolution and features that were added in every version. And probably you will need a bit more time to understand the impact of every feature.&lt;/p&gt;

&lt;p&gt;I found the following as the most relevant features introduced during these years:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;J2SE 5.0: introduction of generics and metadata (aka annotations)&lt;/li&gt;
&lt;li&gt;Java SE 6: Support for pluggable annotations &lt;/li&gt;
&lt;li&gt;Java SE 7: JVM support for dynamic languages&lt;/li&gt;
&lt;li&gt;Java SE 8: Language-level support for lambda expressions and default methods, Project Nashorn (which I know that is now depretated)&lt;/li&gt;
&lt;li&gt;Java SE 9: Modularization of the JDK under Project Jigsaw&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In my light reading exercise I did not find any deep transformation in the language after Java SE 10, but I may be completely wrong.&lt;/p&gt;

&lt;p&gt;BTW, Oracle is still the owner of the Java trademark.&lt;/p&gt;

&lt;h1&gt;
  
  
  What about Java Enterprise Edition
&lt;/h1&gt;

&lt;p&gt;This will be covered in a future blog entry, but let's anticipate a few spoilers:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Java Platform, Enterprise Edition (Java EE) was maintained by Oracle until &lt;a href="https://www.oracle.com/java/technologies/java-ee-glance.html" rel="noopener noreferrer"&gt;version 8&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;On September 12, 2017, Oracle Corporation announced that it would submit Java EE to the Eclipse Foundation. Oracle owns the trademark for the name "Java" and renamed the Java EE platform to &lt;a href="https://jakarta.ee/" rel="noopener noreferrer"&gt;Jakarta EE&lt;/a&gt;. Latest version of Jakarta EE is 9.1 (May 25 2021), with JDK 11 support&lt;/li&gt;
&lt;li&gt;In parallel, &lt;a href="https://microprofile.io/" rel="noopener noreferrer"&gt;Microprofile&lt;/a&gt; project was created as an open forum to optimize Enterprise Java for a microservices architecture by innovating across multiple implementations and collaborating on common areas of interest with a goal of standardization.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;What do you think? Any important topic I am missing? I appreciate your feedback&lt;/p&gt;

</description>
      <category>todayilearned</category>
      <category>java</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Performance vs unit tests: An AWS SDK for JavaScript dilemma</title>
      <dc:creator>Enrique Riesgo</dc:creator>
      <pubDate>Wed, 21 Oct 2020 13:07:44 +0000</pubDate>
      <link>https://dev.to/eriesgo/performance-vs-unit-tests-an-aws-sdk-for-javascript-dilemma-7h9</link>
      <guid>https://dev.to/eriesgo/performance-vs-unit-tests-an-aws-sdk-for-javascript-dilemma-7h9</guid>
      <description>&lt;p&gt;When &lt;a href="https://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/creating-and-calling-service-objects.html" rel="noopener noreferrer"&gt;using AWS SDK for JavaScript service objects&lt;/a&gt; we are typically facing two contradictory recommendations.&lt;/p&gt;

&lt;p&gt;In one hand, as recommended by &lt;a href="https://docs.aws.amazon.com/lambda/latest/dg/gettingstarted-features.html" rel="noopener noreferrer"&gt;AWS Lambda Developer Guide&lt;/a&gt;, we want to create service objects during initialization of the lambda, so they stay in memory and we can reuse them in every invocation, and we then avoid the associated and hidden overhead of creating new objects for every request/response. Quoting original text:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;When the handler finishes processing the first event, the runtime sends it another. The function's class stays in memory, so clients and variables that are declared outside of the handler method in initialization code can be reused. To save processing time on subsequent events, &lt;strong&gt;create reusable resources like AWS SDK clients during initialization&lt;/strong&gt;. Once initialized, each instance of your function can process thousands of requests. &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;On the other hand, if you are unit testing your services, and using &lt;a href="https://www.npmjs.com/package/aws-sdk-mock" rel="noopener noreferrer"&gt;aws-sdk-mock&lt;/a&gt; for doing so, we have probably noticed that you have to initialize the AWS service you are mocking inside the function being tested. Otherwise, that service is not mocked. Official documentation is very clear on that:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;NB: The AWS Service needs to be initialized inside the function being tested in order for the SDK method to be mocked&lt;br&gt;
e.g for an AWS Lambda function example 1 will cause an error region not defined in config whereas in example 2 the sdk will be successfully mocked.&lt;/p&gt;

&lt;p&gt;Example 1:&lt;/p&gt;


&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;AWS&lt;/span&gt;      &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;aws-sdk&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;sns&lt;/span&gt;      &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;AWS&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;SNS&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;dynamoDb&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;AWS&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;DynamoDB&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="nx"&gt;exports&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;handler&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;context&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
 &lt;span class="c1"&gt;// do something with the services e.g. sns.publish&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;Example 2:&lt;/p&gt;


&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;AWS&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;aws-sdk&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;exports&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;handler&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;context&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
 &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;sns&lt;/span&gt;      &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;AWS&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;SNS&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
 &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;dynamoDb&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;AWS&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;DynamoDB&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
 &lt;span class="c1"&gt;// do something with the services e.g. sns.publish&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/blockquote&gt;

&lt;h1&gt;
  
  
  Any caveout?
&lt;/h1&gt;

&lt;p&gt;In order to cope with this two somehow incompatible requirements I found a valid pattern that seems to accommodate both requirements: the creation of a Singleton object that conditionally creates new clients when you are (unit) testing your code and you need those clients to be created in every test, BUT creates and reuses the client in other cases, as AWS recommends for general use in Lambda functions.&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;enableLoggingDebug&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Boolean&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;EnableLoggingDebug&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;true&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;enableAwsMocking&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Boolean&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;EnableAwsMocking&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;true&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;REGION&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;REGION&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;AWS&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;aws-sdk&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;lambdaClient&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;dynamoDBdocumentClient&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;exports&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;SmartLambda&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;
  &lt;span class="nx"&gt;enableAwsMocking&lt;/span&gt;
    &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;AWS&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Lambda&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;typeof&lt;/span&gt; &lt;span class="nx"&gt;lambdaClient&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="k"&gt;typeof&lt;/span&gt; &lt;span class="kc"&gt;undefined&lt;/span&gt;
    &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;lambdaClient&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;AWS&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Lambda&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
    &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;lambdaClient&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;exports&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;SmartDocumentClient&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;
  &lt;span class="nx"&gt;enableAwsMocking&lt;/span&gt;
    &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;AWS&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;DynamoDB&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;DocumentClient&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;region&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;REGION&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt;
    &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;typeof&lt;/span&gt; &lt;span class="nx"&gt;dynamoDBdocumentClient&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="k"&gt;typeof&lt;/span&gt; &lt;span class="kc"&gt;undefined&lt;/span&gt;
    &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;dynamoDBdocumentClient&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;AWS&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;DynamoDB&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;DocumentClient&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
        &lt;span class="na"&gt;region&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;REGION&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="p"&gt;}))&lt;/span&gt;
    &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;dynamoDBdocumentClient&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;AWS&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;logger&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;enableLoggingDebug&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;AWS&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;logger&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So, with this sample Singleton object, every time you have to invoke a Lambda function or get a document from DynamoDB you just need to use &lt;code&gt;SmartLambda&lt;/code&gt; or &lt;code&gt;SmartDocumentClient&lt;/code&gt; and do the expected function call.&lt;/p&gt;

&lt;p&gt;As said, instead of creating new objects to ensure your unit tests work, as we can see in the next piece of 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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;AWS&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Lambda&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;invoke&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;params&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;promise&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can use this singleton, so your code will look clean, will be efficient and your Jest unit tests will perfectly work:&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="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;SmartLambda&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./../../../utils/aws-clients&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// ...&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nc"&gt;SmartLambda&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;invoke&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;params&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;promise&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  One final take away
&lt;/h1&gt;

&lt;p&gt;Did you know that you can enable logging on SDK and see API calls you make with the SDK for JavaScript? Our singleton object above is conditionally activating this logging functionality based on a environment variable and sending it to console:&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;AWS&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;logger&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;enableLoggingDebug&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;AWS&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;logger&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So, for example when a Lambda function is invoked you can see response code, elapsed time and other information about the request and response.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[AWS lambda 200 3.352s 0 retries] invoke({
  FunctionName: 'arn:aws:lambda:us-east-1:123456789012:function:test-API',
  Payload: '***SensitiveInformation***',
  InvocationType: 'RequestResponse'
})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can see more information about this in the &lt;a href="https://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/logging-sdk-calls.html" rel="noopener noreferrer"&gt;AWS SDK for JavaScript Developer Guide&lt;/a&gt;&lt;/p&gt;

</description>
      <category>aws</category>
      <category>serverles</category>
      <category>lambda</category>
      <category>node</category>
    </item>
    <item>
      <title>What JavaScript features can we use with AWS lambdas</title>
      <dc:creator>Enrique Riesgo</dc:creator>
      <pubDate>Wed, 30 Sep 2020 13:37:33 +0000</pubDate>
      <link>https://dev.to/eriesgo/what-javascript-features-can-we-use-with-aws-lambdas-c8n</link>
      <guid>https://dev.to/eriesgo/what-javascript-features-can-we-use-with-aws-lambdas-c8n</guid>
      <description>&lt;p&gt;Most of you know that latest version of ECMAScript is &lt;a href="https://www.ecma-international.org/ecma-262/" rel="noopener noreferrer"&gt;2020&lt;/a&gt;, which brought us many very interesting features.&lt;/p&gt;

&lt;p&gt;One of the my favourite is &lt;a href="https://v8.dev/features/optional-chaining" rel="noopener noreferrer"&gt;optional chaining&lt;/a&gt;, a feature that saves us a lot of effort when dealing with multiple nested objects that can be nullish. As per the spec proposal, “an optional chain is a chain of one or more property accesses and function calls, the first of which begins with the token ?.”.&lt;/p&gt;

&lt;p&gt;This is, instead of a long and conditional statement like&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="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;result&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;something&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;something&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;record&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;something&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;record&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;field&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;something&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;record&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;field&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;""&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You have a more elegant&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;simpleResult&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;something&lt;/span&gt;&lt;span class="p"&gt;?.&lt;/span&gt;&lt;span class="nx"&gt;record&lt;/span&gt;&lt;span class="p"&gt;?.&lt;/span&gt;&lt;span class="nx"&gt;field&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="dl"&gt;""&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So... ready to start refactoring your old-fashined and chatty AWS lambda code with optional chaining? Stop! 🛑 Have you considered that it is a quite new feature that it may not be supported yet by the lambda AWS running engine?&lt;/p&gt;

&lt;p&gt;The question is, &lt;strong&gt;how can I know what are the JavaScript features that I can use while developing AWS Lambdas?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The answer is simple and it takes you just a couple of clicks. Let me show you how:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Check what is the NodeJS version you lambdas is running on. You can see that from the AWS console, or in the &lt;a href="https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtimes.html" rel="noopener noreferrer"&gt;AWS documentation&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Look at the greate &lt;a href="https://node.green/" rel="noopener noreferrer"&gt;node.green&lt;/a&gt; table where you can see the features that you are looking for and its compatibility with your version of NodeJS. &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Back to my "optional chain" case, I have seen that my lambdas are running on node 12, and looking at the &lt;a href="https://node.green/#ES2020-features-optional-chaining-operator-----" rel="noopener noreferrer"&gt;compatibility table for that feature&lt;/a&gt; I have saddly realized that it is not supported 😢. I will have to wait until AWS adds node 14 runtime. &lt;/p&gt;

&lt;p&gt;Meanwhile we can keep learning and figuring out how to improve our code. &lt;/p&gt;

&lt;p&gt;I hope this helps!&lt;/p&gt;

&lt;p&gt;Happy learning and experimentation!&lt;/p&gt;

</description>
      <category>todayilearned</category>
      <category>todayisearched</category>
      <category>aws</category>
      <category>node</category>
    </item>
    <item>
      <title>dotenv and relative paths</title>
      <dc:creator>Enrique Riesgo</dc:creator>
      <pubDate>Fri, 25 Sep 2020 17:08:30 +0000</pubDate>
      <link>https://dev.to/eriesgo/dotenv-and-relative-paths-fp2</link>
      <guid>https://dev.to/eriesgo/dotenv-and-relative-paths-fp2</guid>
      <description>&lt;p&gt;Most of you are using &lt;a href="https://www.npmjs.com/package/dotenv" rel="noopener noreferrer"&gt;dotenv&lt;/a&gt;, the famous "zero-dependency module that loads environment variables from a .env file into process.env".&lt;/p&gt;

&lt;p&gt;Although I usually work in serverless environments like the combo node.js/AWS Lambda where &lt;code&gt;dotenv&lt;/code&gt; is not required, we use it for running local Express wrappers to the node.js lambdas and to control the environment while doing unit tests.&lt;/p&gt;

&lt;p&gt;Unless you have a clear and well know pattern for using it, you can fall into the trap of thinking that &lt;code&gt;dotenv&lt;/code&gt; works like the built-in &lt;code&gt;require&lt;/code&gt; function and accepts relative paths. Proximity with with &lt;code&gt;require&lt;/code&gt; statements doesn't help. Something like:&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="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;myfunction&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;../mymodule.js&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;dotenv&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;config&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;`../.env.test`&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But, this will not work. &lt;/p&gt;

&lt;p&gt;You know why? &lt;strong&gt;Dotenv does only accept absolute paths when it is configured&lt;/strong&gt;. The &lt;a href="https://www.npmjs.com/package/dotenv" rel="noopener noreferrer"&gt;official docummentation&lt;/a&gt; is not very clear on that and you can spend a few hours trying to figure out why your environment variables are not loaded in our unit tests.&lt;/p&gt;

&lt;p&gt;So my recommendation is to ellaborate your own working &lt;code&gt;dotenv&lt;/code&gt; piece of code, save it safe, and reuse it every time you need to set the environment variables of your node.js apps. &lt;/p&gt;

&lt;p&gt;This is an example of the approach I follow.&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="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;myfunction&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;../mymodule.js&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;dotenv&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;config&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;__dirname&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="s2"&gt;`/../.env.test`&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Notice we use &lt;code&gt;__dirname&lt;/code&gt; function to get the path of the current module and then we append the relative path to the .env config file.&lt;/p&gt;

&lt;p&gt;I hope this helps you and never get stuck with this trap.&lt;/p&gt;

&lt;p&gt;Happy coding!&lt;/p&gt;

</description>
      <category>node</category>
      <category>todayilearned</category>
      <category>testing</category>
    </item>
    <item>
      <title>What do you do with our printed technical books when they get outdated?</title>
      <dc:creator>Enrique Riesgo</dc:creator>
      <pubDate>Tue, 22 Sep 2020 12:38:54 +0000</pubDate>
      <link>https://dev.to/eriesgo/what-do-you-do-with-our-printed-technical-books-when-they-get-outdated-1594</link>
      <guid>https://dev.to/eriesgo/what-do-you-do-with-our-printed-technical-books-when-they-get-outdated-1594</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;Hi, this is my very fist post here, and I wanted to try something different.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Probably we can see multiple categories like classic software engineering books that never get (very) outdated (e.g. &lt;a href="https://books.google.es/books?id=hHBf4YxMnWMC" rel="noopener noreferrer"&gt;DDD&lt;/a&gt;, XP, GOF, &lt;a href="https://books.google.es/books?id=rYiKY3mrrswC" rel="noopener noreferrer"&gt;POSA&lt;/a&gt;), but I was also thinking in those hard-cover copies of Oracle 8 or Java SE 1.2 technical books.&lt;/p&gt;

&lt;p&gt;These categories need different approach? ♼ Paper Recycling Bin? Any stories to share?&lt;/p&gt;

</description>
      <category>discuss</category>
      <category>books</category>
    </item>
  </channel>
</rss>
