<?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: Asaju Enitan</title>
    <description>The latest articles on DEV Community by Asaju Enitan (@x1k).</description>
    <link>https://dev.to/x1k</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%2F165920%2F5fa7b542-80a6-48d2-ad58-c0a2e8721c95.png</url>
      <title>DEV Community: Asaju Enitan</title>
      <link>https://dev.to/x1k</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/x1k"/>
    <language>en</language>
    <item>
      <title>I want a divorce</title>
      <dc:creator>Asaju Enitan</dc:creator>
      <pubDate>Thu, 28 Sep 2023 07:04:37 +0000</pubDate>
      <link>https://dev.to/x1k/i-want-a-divorce-20pp</link>
      <guid>https://dev.to/x1k/i-want-a-divorce-20pp</guid>
      <description>&lt;p&gt;that's it... I want a divorce.&lt;/p&gt;

</description>
      <category>relationships</category>
      <category>marriage</category>
    </item>
    <item>
      <title>Configuring Github on your Dev Environment Part One</title>
      <dc:creator>Asaju Enitan</dc:creator>
      <pubDate>Wed, 01 Sep 2021 09:58:26 +0000</pubDate>
      <link>https://dev.to/x1k/configuring-github-on-your-dev-environment-part-one-gl6</link>
      <guid>https://dev.to/x1k/configuring-github-on-your-dev-environment-part-one-gl6</guid>
      <description>&lt;h2&gt;
  
  
  Configuring Github on your Dev Environment Part One
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;&lt;code&gt;$&lt;/code&gt; means running the command as a normal user but make sure to remove it from your command as it already exists on your terminal&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Setup
&lt;/h2&gt;

&lt;p&gt;The first step in setting up git on your dev environment is installing the git to your environment. Although you can use Git with the web version with &lt;a href="https://github.com"&gt;https://github.com&lt;/a&gt;, most of the time you will be interacting with Github from within your dev environment using either Terminal and/or applications.&lt;br&gt;
First go to &lt;a href="https://git-scm.com/"&gt;https://git-scm.com/&lt;/a&gt; and install for your OS.&lt;br&gt;
For Windows user, using the installer will also install the git bash application which you can use to run &lt;code&gt;git&lt;/code&gt; commands.&lt;br&gt;&lt;br&gt;
Linux users will have to download for their distribution &lt;a href="https://git-scm.com/download/linux"&gt;https://git-scm.com/download/linux&lt;/a&gt;&lt;br&gt;&lt;br&gt;
While MacOS users can use &lt;a href="https://brew.sh"&gt;Homebrew&lt;/a&gt; to install by running &lt;code&gt;brew install git&lt;/code&gt;. Make sure to install &lt;a href="https://brew.sh"&gt;Homebrew&lt;/a&gt; if you don't have it already.&lt;br&gt;&lt;br&gt;
If you like living on the edge, you can build from source with the tarballs from &lt;a href="https://www.kernel.org/pub/software/scm/git"&gt;kernel.org&lt;/a&gt;.&lt;/p&gt;
&lt;h2&gt;
  
  
  Basic Configuration
&lt;/h2&gt;

&lt;p&gt;After going through the installation process for your OS, you will need to make configurations. But before that, you should make sure that &lt;code&gt;git&lt;/code&gt; installed successfully on your environment. For Windows users, during installation, you will be asked if you want to install to path, if you didn't check the box, you will need to add it to your environment variables.&lt;br&gt;&lt;br&gt;
Git comes with a tool called &lt;code&gt;git config&lt;/code&gt; that lets add and read configuration variables that control how you use Git. These variables can be saved in three different places;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;/etc/gitconfig&lt;/code&gt; file: The variables saved in this location applies to every user on your system and all the repositories. To save configuration variables to this file you must pass &lt;code&gt;--system&lt;/code&gt; flag to the &lt;code&gt;git config&lt;/code&gt; command. You will need administrative or superuser privilege to use this command because it writes to a system file.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;$HOME/.gitconfig&lt;/code&gt; or &lt;code&gt;$HOME/.config/git/config&lt;/code&gt; file: The configuration variables saved to this file apply only to a single user, You. You can save configuration variables to this file by passing &lt;code&gt;--global&lt;/code&gt; flag to the &lt;code&gt;git config&lt;/code&gt; command. The variables in this file affects only the repositories that you manage.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;config&lt;/code&gt; file in the Git directory i.e &lt;code&gt;.git/&lt;/code&gt; in your project directory. To know if you have this directory in your project folder, you can run &lt;code&gt;ls -al&lt;/code&gt; which displays all the hidden files/folders in your project, you can also access see this by checking &lt;strong&gt;Show hidden files&lt;/strong&gt; in your OS's file explorer.
Now that you know where to store files. Let's add some configuration variables. You will be going with the second option because you will want to apply to yourself and all the repositories you own.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  Setting Your Identity
&lt;/h3&gt;

&lt;p&gt;The first thing you should do when you install Git is to set your user name and email address. Git uses this to bind every commit towards you. This is important so that you will be able to keep track of every commit you make.&lt;br&gt;
Open your preferred terminal and type the following;&lt;br&gt;
&lt;code&gt;$ git config --global user.name "John Happer"&lt;/code&gt; This command sets the user name. Replace the &lt;code&gt;John Happer&lt;/code&gt; with your full name.&lt;br&gt;&lt;br&gt;
&lt;code&gt;$ git config --global user.email "johnhapper@example.com"&lt;/code&gt; This commands sets the email address. Make sure you replace &lt;code&gt;johnhapper@example.com&lt;/code&gt; with the email you registered your github account with. Using the &lt;code&gt;--global&lt;/code&gt; flag makes sure to set these variables to only you but affects all the repositories.  &lt;/p&gt;
&lt;h3&gt;
  
  
  Editor
&lt;/h3&gt;

&lt;p&gt;You have set up your identity, you can configure the default text editor that will be used when you need to type messages or make amends to commits. It is not a must though as Git will make use of your system's default editor.&lt;br&gt;&lt;br&gt;
But if you want to use a different editor, for example VSCode, you can run the command like this&lt;br&gt;
&lt;code&gt;$ git config --global core.editor code&lt;/code&gt;. This will use the VSCode executable &lt;code&gt;code&lt;/code&gt;. For windows users, you will need to specify the full path to the editor you want to use. For example, if you want to use VSCode on windows, you will need to type something like this;&lt;br&gt;&lt;br&gt;
&lt;code&gt;$ git config --global core.editor "C:/Program Files/Visual Studio Code/code.exe"&lt;/code&gt;&lt;br&gt;&lt;br&gt;
Make sure you get the correct path as this can cause issues when Git attempts to open the executable.&lt;/p&gt;
&lt;h3&gt;
  
  
  Default Branch
&lt;/h3&gt;

&lt;p&gt;By default, when you run &lt;code&gt;git init&lt;/code&gt; to initialize a new repository for your project, Git will create a branch called &lt;strong&gt;master&lt;/strong&gt;. But you can set a different name for the initial branch. For example to set &lt;strong&gt;main&lt;/strong&gt; as the default branch name, type&lt;br&gt;
&lt;code&gt;$ git config --global init.defaultBranch main&lt;/code&gt; and it will set &lt;strong&gt;main&lt;/strong&gt; as your default initial branch every time you run &lt;code&gt;git init&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Phew!, you have done a lot. To check the current variables you have set, you can use the &lt;code&gt;git config --list&lt;/code&gt; to show the list of everything Git has set. This command reads from all the Git &lt;code&gt;config&lt;/code&gt; files.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ git config --list
user.name=John Happer
user.email=johnhapper@example.com
core.editor=vim
color.status=auto
color.branch=auto
...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;...&lt;/code&gt; The rest of the variables have been truncated.&lt;br&gt;
At any point if you forgot a command, you can run &lt;code&gt;$ git help &amp;lt;verb&amp;gt;&lt;/code&gt; to get a comprehensive manual for that command. For example you can get the documentation for &lt;code&gt;git commit&lt;/code&gt; by running &lt;code&gt;$ git help config&lt;/code&gt;. For short and concise help options, you can use the &lt;code&gt;$ git &amp;lt;verb&amp;gt; -h&lt;/code&gt; for example &lt;code&gt;$ git add -h&lt;/code&gt; to get help for the github add command.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;usage: git add [&amp;lt;options&amp;gt;] [--] &amp;lt;pathspec&amp;gt;...

    -n, --dry-run         dry run
    -v, --verbose         be verbose

    -i, --interactive     interactive picking
    -p, --patch           select hunks interactively
    -e, --edit            edit current diff and apply
    -f, --force           allow adding otherwise ignored files
    -u, --update          update tracked files
    --renormalize         renormalize EOL of tracked files (implies -u)
    -N, --intent-to-add   record only the fact that the path will be added later
    -A, --all             add changes from all tracked and untracked files
    --ignore-removal      ignore paths removed in the working tree (same as --no-all)
    --refresh             don't add, only refresh the index
    --ignore-errors       just skip files which cannot be added because of errors
    --ignore-missing      check if - even missing - files are ignored in dry run
    --chmod (+|-)x        override the executable bit of the listed files
    --pathspec-from-file &amp;lt;file&amp;gt;
                          read pathspec from file
    --pathspec-file-nul   with --pathspec-from-file, pathspec elements are separated with NUL character
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And that's all about basic setup for your github. Next up, we will look at setting up your git commit messages.&lt;/p&gt;

&lt;h3&gt;
  
  
  Adding Files
&lt;/h3&gt;

&lt;p&gt;You have made changes to your code, and now you need to push to the remote repository. To do that, you will use the &lt;code&gt;git add&lt;/code&gt; command. You can add files in several ways. Running &lt;code&gt;git add .&lt;/code&gt; will add all modified and new files and stage them for commit and push. But you can also specify which file you want to add by running &lt;code&gt;git add path/to/file/in/the/repositiry&lt;/code&gt; i.e &lt;code&gt;git add app/controllers/user.js&lt;/code&gt; will add only the &lt;code&gt;user.js&lt;/code&gt; file and stage it.&lt;/p&gt;

&lt;h3&gt;
  
  
  Removing Files
&lt;/h3&gt;

&lt;p&gt;You can also remove files i.e unstage them from commits by running &lt;code&gt;git rm path/to/file/in/the/repository&lt;/code&gt;. The &lt;code&gt;git rm .&lt;/code&gt; also unstages all files and folders. Not to be confused with &lt;code&gt;git stash&lt;/code&gt;, this command clears the current commit and reverts to the last push commit in the log which can be accessed using the &lt;code&gt;git log&lt;/code&gt; command.&lt;/p&gt;

&lt;h3&gt;
  
  
  Commit Messages
&lt;/h3&gt;

&lt;p&gt;Commit messages are a way to keep note tracks of your project updates. It is very important because it helps when you revisit the codebase or share the repository with someone else. It is very important to make sure your commit messages as descriptive as possible. Avoid short messages such as &lt;em&gt;updated app.js&lt;/em&gt;, &lt;em&gt;the change here is now working&lt;/em&gt;, these kind of messages leave little space for understanding your code and can waste productive time.&lt;br&gt;&lt;br&gt;
That being said, how should you write a good commit message. A good commit message needs to follow a good idea of what the update is about, a summary or it and full text explaining to an extent what the update to the commit is.&lt;br&gt;&lt;br&gt;
An example of this is &lt;code&gt;&amp;lt;scope&amp;gt; &amp;lt;summary&amp;gt; &amp;lt;full text&amp;gt;&lt;/code&gt;.  &lt;/p&gt;

&lt;h4&gt;
  
  
  Scope
&lt;/h4&gt;

&lt;p&gt;Where &lt;code&gt;&amp;lt;scope&amp;gt;&lt;/code&gt; is the feature/function of the commit, i.e is it a feature, a test, a breaking change or a fix.&lt;br&gt;
A way you can do this is using keywords, these keywords has to be descriptive enough, listed below are some examples;  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;feat&lt;/li&gt;
&lt;li&gt;fix&lt;/li&gt;
&lt;li&gt;breaking changes&lt;/li&gt;
&lt;li&gt;new&lt;/li&gt;
&lt;li&gt;improve&lt;/li&gt;
&lt;li&gt;refactor, 
etc...&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Summary
&lt;/h4&gt;

&lt;p&gt;Where &lt;code&gt;&amp;lt;summary&amp;gt;&lt;/code&gt; shows the TL;DR version of the commit. For example, what function was refactored or what issue was resolved. It is advisable to keep this at 20 words max as you will still give a detailed explanation in the &lt;code&gt;&amp;lt;full text&amp;gt;&lt;/code&gt;. Example might be, &lt;em&gt;Added validator to the create user endpoint&lt;/em&gt;.&lt;/p&gt;

&lt;h4&gt;
  
  
  Full Text
&lt;/h4&gt;

&lt;p&gt;The &lt;code&gt;&amp;lt;full text&lt;/code&gt; contains the full detailed explanation of the explanation, will it affect any other commit?, is there a command that must be run for it work?. You can type as much as you want here since it will help you or anyone checking the code to grasp a full explanation of the commit.&lt;/p&gt;

&lt;p&gt;So a full commit message will be something like &lt;code&gt;$ git commit -m "UPDATE(Added validator to the create user endpoint): To avoid a security issue, user registration now requires the email to be of the email format, username must be more than 3 characters and password must be at least 8 characters. This is going to affect the registration endpoint which might generate error."&lt;/code&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Alias
&lt;/h4&gt;

&lt;p&gt;That being said, typing all these for every commit can be sometimes very tiring 😫. That being said, Git has a tool to exactly help with that and that is the &lt;code&gt;git config --global alias&lt;/code&gt;🙂. With this command, you can set at much as aliases as you want. Let\'s set an alias to make an set a commit message for the &lt;em&gt;initial&lt;/em&gt; commit.&lt;br&gt;&lt;br&gt;
&lt;code&gt;git config --global alias.int '!f() { git commit -m "🎊 INITIAL COMMIT($1): $2; }; f'&lt;/code&gt; Running this command will add the alias command to your &lt;code&gt;config&lt;/code&gt; file. Then when you run &lt;code&gt;git int "Project Setup" "Setting up the base files, we will be using this technology etc..."&lt;/code&gt; it will translate to &lt;code&gt;$ git commit -m "🎊 INITIAL COMMIT(Project Setup): Setting up the base files, we will be using this technology etc..."&lt;/code&gt; which looks cool and you get to type less.&lt;br&gt;&lt;br&gt;
You can add more of these alias and more with the &lt;code&gt;git config --global alias.&amp;lt;keyword&amp;gt;&lt;/code&gt; command. I will share my &lt;code&gt;config&lt;/code&gt; file so you can see how I did mine and edit according to your preference.&lt;/p&gt;

&lt;p&gt;With this all set up, you are well on your way of becoming adept at using git. This is the first in the series and I will be updating as soon as I can.&lt;/p&gt;

&lt;p&gt;Link to my &lt;a href="https://gist.github.com/en1tan/9b9a9c13878aa76c40f0de35bd46539e#file-gitconfig"&gt;config&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;See you next time 😉❤️&lt;/p&gt;

</description>
      <category>github</category>
      <category>environment</category>
      <category>os</category>
      <category>programming</category>
    </item>
    <item>
      <title>Migrating existing REST API Server to Serverless with AWS Lambda, MongoDB and Serverless Framework</title>
      <dc:creator>Asaju Enitan</dc:creator>
      <pubDate>Sat, 24 Jul 2021 23:57:54 +0000</pubDate>
      <link>https://dev.to/x1k/migrating-existing-rest-api-server-to-serverless-with-aws-lambda-mongodb-and-serverless-framework-3jge</link>
      <guid>https://dev.to/x1k/migrating-existing-rest-api-server-to-serverless-with-aws-lambda-mongodb-and-serverless-framework-3jge</guid>
      <description>&lt;p&gt;With the increased interest in serverless backend development, companies, startups have began to look towards migrating their exiting projects from using a server to essentially a &lt;strong&gt;serverless&lt;/strong&gt; &lt;em&gt;server*&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;Serverless has different meanings depending on the context. It could be a third party managed services like Firebase or an event driven service.&lt;/p&gt;

&lt;p&gt;In this tutorial, you will learn how to migrate your existing project to a serverless approach using AWS Lambda, MongoDB, and Serverless Framework.&lt;/p&gt;

&lt;h2&gt;
  
  
  Table of Contents
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
Table of Contents

&lt;ul&gt;
&lt;li&gt;Application: A Movie App&lt;/li&gt;
&lt;li&gt;Prerequisites&lt;/li&gt;
&lt;li&gt;Terms&lt;/li&gt;
&lt;li&gt;Yosh! Show me dah Code!&lt;/li&gt;
&lt;li&gt;Step 1:&lt;/li&gt;
&lt;li&gt;Step 2:&lt;/li&gt;
&lt;li&gt;Step 4:&lt;/li&gt;
&lt;li&gt;Step 5:&lt;/li&gt;
&lt;li&gt;Step 6:&lt;/li&gt;
&lt;li&gt;Step 7:&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;h3&gt;
  
  
  Application: A Movie App
&lt;/h3&gt;

&lt;p&gt;The movie app is a simple CRUD based application that stores, retrieves, updates and deletes movies from a MongoDB database. The application is written in Fastify but the process is the same for every other NodeJS Framework e.g, Express, Hapi, Koa.&lt;/p&gt;

&lt;h3&gt;
  
  
  Prerequisites
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;AWS Account&lt;/li&gt;
&lt;li&gt;Node.js&lt;/li&gt;
&lt;li&gt;Configured AWS CLI &lt;em&gt;(for deployment)&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;Serverless CLI &lt;em&gt;(we will be running it locally)&lt;/em&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Terms
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Serverless Framework&lt;/strong&gt;: The &lt;a href="https://serverless.com" rel="noopener noreferrer"&gt;Serverless&lt;/a&gt; Framework is a framework that allows you to build Serverless applications. It is provider-agnostic meaning it you can use it to build quite a number of serverless providers. Read more on their.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;AWS Lambda&lt;/strong&gt;: &lt;a href="https://aws.amazon.com" rel="noopener noreferrer"&gt;AWS&lt;/a&gt; Lambda is and event-driven serverless computing platform, meaning, it executes your code in response to event. It is the third compute service from Amazon. The others being EC2 (Elastic Compute Cloud) and ECS (Elastic Container Service).&lt;/p&gt;

&lt;p&gt;Enough talk. Let's get into the code&lt;/p&gt;

&lt;h3&gt;
  
  
  Yosh! Show me dah Code!
&lt;/h3&gt;

&lt;p&gt;Alright alright, even I am getting tired of talk. Let's code&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;This is might be a given, but be sure to clone your code and not edit the original one, &lt;br&gt;&lt;br&gt;
It may not affect but it's makes for freedom to edit to satisfaction&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h4&gt;
  
  
  Step 1:
&lt;/h4&gt;

&lt;blockquote&gt;
&lt;p&gt;NOTE: As of this writing &lt;strong&gt;serverless&lt;/strong&gt; is only supported up to node v15.4.0 &lt;a href="https://github.com/dherault/serverless-offline/issues/1150#issuecomment-750866436" rel="noopener noreferrer"&gt;details&lt;/a&gt;.&lt;br&gt;&lt;br&gt;
You can use your node version manager to install the specific node version. I use &lt;a href="https://github.com/nvm-sh/nvm" rel="noopener noreferrer"&gt;nvm&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Install Serverless CLI&lt;br&gt;&lt;br&gt;
&lt;em&gt;(Recommended to install system wide, makes for easy cli usage outside your current project)&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;$ npm install -g serverless
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;(if you are not interested in installing system wide)&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;$ cd your-project-directory
$ npm install --save serverless
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command will install serverless and makes available 2 commands &lt;code&gt;serverless&lt;/code&gt; &amp;amp; &lt;code&gt;sls&lt;/code&gt;. &lt;code&gt;sls&lt;/code&gt; is an alias to &lt;code&gt;serverless&lt;/code&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Step 2:
&lt;/h4&gt;

&lt;p&gt;Add Serverless to your current project&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ sls create --template aws-nodejs --name &amp;lt;custom-unique-name&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will create three files&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.
├── .npmignore
├── handler.js
└── serverless.yml
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Explanation time &lt;em&gt;(bear with me)&lt;/em&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;.npmignore&lt;/strong&gt;: This file tells npm which files should be kept outside of the package&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;handler.js&lt;/strong&gt;: Contains the boilerplate code.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;'use strict';

module.exports.hello = async (event) =&amp;gt; {
  return {
    statusCode: 200,
    body: JSON.stringify(
      {
        message: 'Go Serverless v1.0! Your function executed successfully!',
        input: event,
      },
      null,
      2
    ),
  };

  // Use this code if you don't use the http event with the LAMBDA-PROXY integration
  // return { message: 'Go Serverless v1.0! Your function executed successfully!', event };
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;serverless.yml&lt;/strong&gt;: The entry point file. Without it, Serverless won't run. It has three sections - &lt;strong&gt;provider&lt;/strong&gt;, &lt;strong&gt;functions&lt;/strong&gt;, &lt;strong&gt;resources&lt;/strong&gt;, &lt;strong&gt;plugins&lt;/strong&gt;, etc.&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;provider&lt;/strong&gt;: This section declares configuration specific to a cloud provider. &lt;em&gt;(in this case AWS)&lt;/em&gt;. It can also be used to specify region, stage, runtime etc.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;provider:
  name: aws
  runtime: nodejs12.x
  lambdaHashingVersion: 20201221
  stage: dev
  region: us-west-1
  ...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;functions&lt;/strong&gt;: This section is used to specify all the functions that are available for your service &lt;em&gt;(the &lt;code&gt;--name&lt;/code&gt; flag we specified when adding adding serverless)&lt;/em&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;functions:
hello:
  handler: handler.hello
  ...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;resources&lt;/strong&gt;: This section specifies all the resouces that your functions can use. They can be declared using AWS CloudFormation.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;resources:
Resources:
  NewResource:
    Type: AWS::S3::Bucket
    Properties:
      BucketName: my-new-bucket
Outputs:
   NewOutput:
     Description: "Description for the output"
     Value: "Some output value"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Step 4:
&lt;/h4&gt;

&lt;p&gt;Update serverless.yml file&lt;br&gt;
We will configure the serverless.yml file to reference your existing API endpoints and other configurations&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;I won't bore you with the details, you can update it as shown below. It should work for your application too&lt;br&gt;
&lt;/p&gt;


&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;service: &amp;lt;autogenerated&amp;gt; # Service name (must be unique for your account, no two services can share the same name)

frameworkVersion: "2" # Recommended to pin it to a working version so updates won't break your application

provider:
  name: aws # Name of the cloud provider
  runtime: nodejs14.x # node runtime that the deploy will work on, this is different from the nodejs version required for sls to run
  lambdaHashingVersion: 20201221 # Recommended (honestly, no idea why. Lemme know in the comments what it means)
  memorySize: 130 # Memory size required for lambda functions to run
  timeout: 10 # 10s timeout for a request to be cancelled
  stage: {opt:stage, 'dev'} # Stage to run the functions, it is used for development process to specify which ENV to run
  region: eu-west-1 # Optional override, it will be automatically set from AWS

functions:
  api: # can be any name, this will be mapped to the functions on lambda. It has to be unique
    handler: handler.api # The file.exportedFunction that the functions will be use when the event is created
    events:
      - http: ANY / # RegExps all the HTTP Routes GET|POST|PUT|PATCH|DELETE|OPTIONS, etc.
      - http: ANY /{proxy+} # If your routes use queries and parameters

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Oh look, I ended up adding the details. Make sure to remove the comments.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h4&gt;
  
  
  Step 5:
&lt;/h4&gt;

&lt;p&gt;Install the &lt;a href="https://github.com/fastify/aws-lambda-fastify" rel="noopener noreferrer"&gt;aws-lambda-fastify&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install aws-lambda-fastify
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Open &lt;code&gt;handler.js&lt;/code&gt; using your editor and update it as follows&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const awsLambdaFastify = require('aws-lambda-fastify');
const app = require('./app');

const proxy = awsLambdaFastify(app);

exports.api = (event, context) =&amp;gt; proxy(event, context);

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Step 6:
&lt;/h4&gt;

&lt;p&gt;Open &lt;code&gt;app.js&lt;/code&gt; and update it&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const fastify = require('fastify');
const cors = require('fastify-cors');

const mongoose = require('mongoose');
require('dotenv').config();

const controllers = require('./controllers');

const MONGO_URI = process.env.MONGO_URI || 'mongodb://localhost:27017/movie';
const PORT = process.env.PORT || 3000;

// Connect to the db
mongoose
  .connect(MONGO_URI, {
    useCreateIndex: true,
    useFindAndModify: false,
    useNewUrlParser: true,
    useUnifiedTopology: true,
  })
  .then((connection) =&amp;gt; {
    console.log(`Database connected ::: ${connection.connection.host}`);
  })
  .catch((err) =&amp;gt; {
    console.error(`Error ::: ${err.message}`);
    process.exit();
  });

// Initialize app
const app = fastify();

// CORS
app.register(cors, {
  origin: '*',
});

// Routes
app.get('/', controllers.getAll);
app.post('/create', controllers.create);
app.get('/:id', controllers.getOne);
app.put('/:id/update', controllers.updateOne);
app.delete('/:id/delete', controllers.deleteOne);

// Run as backend server if the file is called directly
if (require.main === module) {
  app.listen(PORT, (err) =&amp;gt; {
    if (err) console.error(err);
    console.log(`server running on ${PORT}`);
  });
} else {
  // Execute as aws lambda function when required as a module
  module.exports = app;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As noticed here, there's not much change except&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Run as backend server if the file is called directly
if (require.main === module) {
  app.listen(PORT, (err) =&amp;gt; {
    if (err) console.error(err);
    console.log(`server running on ${PORT}`);
  });
} else {
  // Execute as aws lambda function when required as a module
  module.exports = app;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Which runs the file as normal server if called directly &lt;code&gt;node app.js&lt;/code&gt; and runs it as a function when imported from our &lt;code&gt;handler.js&lt;/code&gt; file&lt;/p&gt;

&lt;p&gt;Another change is in the &lt;code&gt;controllers.js&lt;/code&gt; file&lt;br&gt;
we will replace &lt;code&gt;req,res&lt;/code&gt; with &lt;code&gt;event&lt;/code&gt; since our requests are now events but it works the same. &lt;a href="https://fastify.io" rel="noopener noreferrer"&gt;Fastify&lt;/a&gt; Power!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// const create = async (req,res) {
const create = async (event) =&amp;gt; {
  try {
    const newMovie = await Movie.create(event.body); // Events are sent in JSON format
    return {
      statuCode: 201,
      body: JSON.stringify(
        {
          message: 'new movie created',
          newMovie,
        },
        null,
        2
      ),
    };
  } catch (err) {
    return {
      statuCode: err.code || 500,
      message: JSON.stringify(err),
    };
  }
};
...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next is the way we return responses, we will have to stringify &lt;em&gt;(JSON.stringify(data))&lt;/em&gt; the responses &lt;em&gt;(AWS Lambda Recommended)&lt;/em&gt; and structure it as above.&lt;/p&gt;

&lt;p&gt;Phew! that was a stretch, I need a cup of coffee ....Alright, let's continue&lt;/p&gt;

&lt;h4&gt;
  
  
  Step 7:
&lt;/h4&gt;

&lt;p&gt;Now we can deploy our app to AWS!&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1627169257005%2FbfwVd5FUL.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%2Fv1627169257005%2FbfwVd5FUL.png" alt="Now we can deploy to AWS.png"&gt;&lt;/a&gt;&lt;br&gt;
Hehe, not yet young padwan.&lt;/p&gt;

&lt;p&gt;Testing our application locally (dev) is really important so we don't end up causing cataclysmic situation. That's where &lt;a href="https://www.npmjs.com/package/serverless-offline" rel="noopener noreferrer"&gt;serverless-offline&lt;/a&gt; comes in&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Explanation Time!: Serverless Offline is a Serverless plugin that emulates AWS and API Gateway on your local machine to speed up your development cycles. - Serverless&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;How do we integrate it to our application? Glad you asked. It takes two easy steps&lt;br&gt;
Install the npm package as devDependecy&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install --save-dev serverless-offline
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next we will plug-in 👓 it to our &lt;code&gt;serverless.yml&lt;/code&gt; file&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;...
plugins:
  - serverless-offline
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Yosh! let's now run it locally&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sls offline start
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;running this command will show this output&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1627168565220%2FJ0kHMDmKs.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%2Fv1627168565220%2FJ0kHMDmKs.png" alt="Screenshot 2021-07-24 at 23.20.06.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When we visit Postman &lt;em&gt;(or any REST Client you use)&lt;/em&gt; and perform the CRUD Operations&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create movie&lt;/li&gt;
&lt;/ul&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%2Fv1627168706143%2FkKY1Iwas9.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%2Fv1627168706143%2FkKY1Iwas9.png" alt="Screenshot 2021-07-24 at 23.23.10.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Get all movies&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1627168720546%2Fo62C5FI_T.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%2Fv1627168720546%2Fo62C5FI_T.png" alt="Screenshot 2021-07-24 at 23.23.29.png"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Get one movie&lt;/p&gt;&lt;/li&gt;
&lt;/ul&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%2Fv1627168848780%2FSp8HGejcD.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%2Fv1627168848780%2FSp8HGejcD.png" alt="Screenshot 2021-07-24 at 23.24.38.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Update one movie&lt;/li&gt;
&lt;/ul&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%2Fv1627168810849%2FW_kwFQl9I.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%2Fv1627168810849%2FW_kwFQl9I.png" alt="Screenshot 2021-07-24 at 23.24.15.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Delete movie&lt;/li&gt;
&lt;/ul&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%2Fv1627168826011%2FpZhymMLlo.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%2Fv1627168826011%2FpZhymMLlo.png" alt="Screenshot 2021-07-24 at 23.24.56.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now that we are done testing our app locally, time to deploy it. Ah finally!&lt;br&gt;&lt;br&gt;
First we have to configure AWS CLI. Follow the steps &lt;a href="https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-quickstart.html#cli-configure-quickstart-config" rel="noopener noreferrer"&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Done? Good, let's continue.&lt;/p&gt;

&lt;p&gt;run&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sls deploy
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;to deploy your application&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;PS: I couldn't deploy mine, for some reason, I can't access my AWS account, story for later.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;It will display the url to your application should the deploy succeed, test the endpoints and you should be good to go&lt;/p&gt;

&lt;p&gt;And that's it. You have successfully migrated your existing app to AWS Lambda using Serverless Framework.&lt;/p&gt;

&lt;p&gt;The link to the &lt;a href="https://github.com/en1tan/migrate-existing-server-to-serverless" rel="noopener noreferrer"&gt;Repository&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Was the guide straightforward enough to follow?, did you get lost somewhere?, let me know in the comments.&lt;/p&gt;

&lt;p&gt;Follow me for more &lt;strong&gt;'straightforward'&lt;/strong&gt; tutorials such as this.&lt;/p&gt;

&lt;p&gt;KodeRant](&lt;a href="https://koderant.hashnode.dev/" rel="noopener noreferrer"&gt;https://koderant.hashnode.dev/&lt;/a&gt;)&lt;/p&gt;

</description>
      <category>serverless</category>
      <category>restapi</category>
      <category>fastify</category>
      <category>awslambda</category>
    </item>
  </channel>
</rss>
