<?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>Forem: Prabusah</title>
    <description>The latest articles on Forem by Prabusah (@prabusah).</description>
    <link>https://forem.com/prabusah</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%2F23594%2Fbab44162-2100-4b5b-9ff6-b5d923999312.png</url>
      <title>Forem: Prabusah</title>
      <link>https://forem.com/prabusah</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/prabusah"/>
    <language>en</language>
    <item>
      <title>AWS Custom Lambda Layer</title>
      <dc:creator>Prabusah</dc:creator>
      <pubDate>Sat, 11 Feb 2023 11:22:21 +0000</pubDate>
      <link>https://forem.com/prabusah/aws-custom-lambda-layer-i9g</link>
      <guid>https://forem.com/prabusah/aws-custom-lambda-layer-i9g</guid>
      <description>&lt;p&gt;&lt;strong&gt;Lambda Layer:&lt;/strong&gt;&lt;br&gt;
Used to share code between functions&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Package below into a Lambda layer:&lt;/strong&gt;&lt;br&gt;
    1. Set of reusable functions that can be used across Lambda's.&lt;br&gt;
    2. npm module that can be used across Lambda's.&lt;/p&gt;

&lt;p&gt;Consider we have set of reusable functions like below in a file named &lt;em&gt;reusable.js:&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const getCountryCode = function(countryName) {
  let countryCodeMapping = {
    "India" : "IN",
    "United States of America" : "USA",
    "United Kingdom" : "UK"  
  };
  return countryCodeMapping[countryName];
};
module.exports = { getCountryCode }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Folder structure:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;nodejs (FolderName)
    reusableCodeFiles.js
    package.json
    node_modules
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;How to zip (Windows):&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
Right click the nodejs folder -&amp;gt; 7-Zip -&amp;gt; Add to "nodejs.zip"&lt;br&gt;
    nodejs - foldername&lt;br&gt;
    nodejs.zip&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How to use the Layer reusable code from Lambda:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const reusableCode = require('/opt/nodejs/reusable');
// reusable is the name of file (.ie. reusable.js) inside nodejs zip file 

exports.handler = async (event) =&amp;gt; {
    console.log(reusableCode .getCountryCode("India"));
        //Logs IN   
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>ai</category>
      <category>productivity</category>
      <category>career</category>
      <category>refactor</category>
    </item>
  </channel>
</rss>
