{"id":6270,"date":"2018-10-30T08:00:54","date_gmt":"2018-10-30T15:00:54","guid":{"rendered":"http:\/\/softwareengineeringdaily.com\/?p=6270"},"modified":"2018-10-31T07:02:47","modified_gmt":"2018-10-31T14:02:47","slug":"serverless-backend-using-aws-lambda-hands-on-guide","status":"publish","type":"post","link":"https:\/\/softwareengineeringdaily.com\/2018\/10\/30\/serverless-backend-using-aws-lambda-hands-on-guide\/","title":{"rendered":"Serverless Backend using AWS Lambda: Hands-on Guide"},"content":{"rendered":"<section class=\"section section--body section--first\">\n<div class=\"section-content\">\n<div class=\"section-inner sectionLayout--insetColumn\">\n<p><em>This article was originally written by <a href=\"https:\/\/blog.bitsrc.io\/@geeky_writer_?source=post_header_lockup\">Rajat <\/a>S on <a href=\"https:\/\/blog.bitsrc.io\/serverless-backend-using-aws-lambda-hands-on-guide-31806ceb735e\">Medium<\/a>. Reposted with permission from <a href=\"https:\/\/blog.bitsrc.io\/\">Bits and Pieces<\/a>.<\/em><\/p>\n<hr class=\"section-divider\" \/>\n<p id=\"10e4\" class=\"graf graf--p graf-after--figure\">Serverless architecture refers to the concept where you give your backend logic to a third party vendor\u2019s server architecture. Doing this allows a developer to focus more on their app and not worry about the server at much.<\/p>\n<p id=\"53a1\" class=\"graf graf--p graf-after--p\">The word\u00a0<strong class=\"markup--strong markup--p-strong\">Serverless\u00a0<\/strong>may misguide one into thinking that there is no server attached to the app. In truth, it just means that the developer does not have to worry about maintaining the backend logic. That responsibility is handed over to the third party vendors like AWS, Azure, and Google.<\/p>\n<p id=\"1062\" class=\"graf graf--p graf-after--p\">Serverless Computing can be divided into two variants:<\/p>\n<ul class=\"postList\">\n<li id=\"97db\" class=\"graf graf--li graf-after--p\">Backend-as-a-Service (BaaS)<\/li>\n<li id=\"bb1d\" class=\"graf graf--li graf-after--li\">Function-as-a-Service (FaaS)<\/li>\n<\/ul>\n<p id=\"03b5\" class=\"graf graf--p graf-after--li\">With BaaS, the backend logic will be run on a third party vendor. The developer does not need to maintain the servers or the infrastructure which runs the backend services. The developer only needs to pay a subscription to the vendor. The BaaS runs on a shared infrastructure, and the same backend service will be used by multiple applications.<\/p>\n<p id=\"7719\" class=\"graf graf--p graf-after--p\">Technologies like AWS Lambda and Microsoft Azure Functions fall under the FaaS category. Here, the developers can implement their own backend logic and run them within the serverless framework. The vendor will handle the operation of the backend logic in a server, along with scalability, reliability, and security aspects.<\/p>\n<p id=\"c6a0\" class=\"graf graf--p graf-after--p graf--trailing\">In this post, we will use AWS Lambda to create a serverless API. We will go through the steps to build the first two endpoints of a REST API and store the data in DynamoDB.<\/p>\n<\/div>\n<\/div>\n<\/section>\n<section class=\"section section--body\">\n<div class=\"section-divider\">\n<hr class=\"section-divider\" \/>\n<\/div>\n<div class=\"section-content\">\n<div class=\"section-inner sectionLayout--insetColumn\">\n<h4 id=\"143b\" class=\"graf graf--h4 graf--leading\">Turn components into APIs with\u00a0Bit<\/h4>\n<p id=\"4083\" class=\"graf graf--p graf-after--h4\"><a class=\"markup--anchor markup--p-anchor\" href=\"https:\/\/github.com\/teambit\/bit\" target=\"_blank\" rel=\"noopener\" data-href=\"https:\/\/github.com\/teambit\/bit\">Bit<\/a>\u00a0is an open source tool that turns any reusable piece of JS code into an API which can be discovered, shared and developed from any project. Give it a try.<\/p>\n<div id=\"38f2\" class=\"graf graf--mixtapeEmbed graf-after--p graf--trailing\"><a class=\"markup--anchor markup--mixtapeEmbed-anchor\" title=\"https:\/\/bitsrc.io\" href=\"https:\/\/bitsrc.io\/\" data-href=\"https:\/\/bitsrc.io\"><strong class=\"markup--strong markup--mixtapeEmbed-strong\">Bit &#8211; Share and build with code components<\/strong><br \/>\n<em class=\"markup--em markup--mixtapeEmbed-em\">Bit helps you share, discover and use code components between projects and applications to build new features and\u2026<\/em>bitsrc.io<\/a><\/div>\n<\/div>\n<\/div>\n<\/section>\n<section class=\"section section--body\">\n<div class=\"section-divider\">\n<hr class=\"section-divider\" \/>\n<\/div>\n<div class=\"section-content\">\n<div class=\"section-inner sectionLayout--insetColumn\">\n<h3 id=\"ad30\" class=\"graf graf--h3 graf--leading\">Getting Started<\/h3>\n<p id=\"43cb\" class=\"graf graf--p graf-after--h3\">In order to interact with Amazon Web Services (AWS), we need to get an access key and a secret key along with the permissions to deploy an app.<\/p>\n<p id=\"ec23\" class=\"graf graf--p graf-after--p\">If you do not already have an account in AWS, create one\u00a0<a class=\"markup--anchor markup--p-anchor\" href=\"https:\/\/portal.aws.amazon.com\/billing\/signup#\/start\" target=\"_blank\" rel=\"noopener\" data-href=\"https:\/\/portal.aws.amazon.com\/billing\/signup#\/start\">here<\/a>. Once you have successfully registered, you will be able to see the AWS Console as shown below:<\/p>\n<\/div>\n<div class=\"section-inner sectionLayout--outsetColumn\">\n<figure id=\"4783\" class=\"graf graf--figure graf--layoutOutsetCenter graf-after--p\" data-scroll=\"native\">\n<div class=\"aspectRatioPlaceholder is-locked\">\n<div class=\"aspectRatioPlaceholder-fill\"><\/div>\n<div class=\"progressiveMedia js-progressiveMedia graf-image is-canvasLoaded is-imageLoaded\" data-image-id=\"0*x93bzQPPt7rcq-9T.png\" data-width=\"1897\" data-height=\"900\" data-is-featured=\"true\" data-action=\"zoom\" data-action-value=\"0*x93bzQPPt7rcq-9T.png\" data-scroll=\"native\"><canvas class=\"progressiveMedia-canvas js-progressiveMedia-canvas\" width=\"75\" height=\"35\"><\/canvas><img decoding=\"async\" class=\"progressiveMedia-image js-progressiveMedia-image\" src=\"https:\/\/i0.wp.com\/cdn-images-1.medium.com\/max\/2000\/0*x93bzQPPt7rcq-9T.png?ssl=1\" data-src=\"https:\/\/i0.wp.com\/cdn-images-1.medium.com\/max\/2000\/0*x93bzQPPt7rcq-9T.png?ssl=1\" data-recalc-dims=\"1\" \/><\/div>\n<\/div>\n<\/figure>\n<\/div>\n<div class=\"section-inner sectionLayout--insetColumn\">\n<p id=\"5e11\" class=\"graf graf--p graf-after--figure\">We can now get the keys and permissions by switching to the\u00a0<a class=\"markup--anchor markup--p-anchor\" href=\"https:\/\/console.aws.amazon.com\/iam\/home?region=us-east-1#\/users\" target=\"_blank\" rel=\"noopener\" data-href=\"https:\/\/console.aws.amazon.com\/iam\/home?region=us-east-1#\/users\">identity and access management<\/a>.<\/p>\n<\/div>\n<div class=\"section-inner sectionLayout--outsetColumn\">\n<figure id=\"c62b\" class=\"graf graf--figure graf--layoutOutsetCenter graf-after--p\" data-scroll=\"native\">\n<div class=\"aspectRatioPlaceholder is-locked\">\n<div class=\"aspectRatioPlaceholder-fill\"><\/div>\n<div class=\"progressiveMedia js-progressiveMedia graf-image is-canvasLoaded is-imageLoaded\" data-image-id=\"0*QuY7WrBVeJLrN2io.png\" data-width=\"1919\" data-height=\"864\" data-action=\"zoom\" data-action-value=\"0*QuY7WrBVeJLrN2io.png\" data-scroll=\"native\"><canvas class=\"progressiveMedia-canvas js-progressiveMedia-canvas\" width=\"75\" height=\"33\"><\/canvas><img decoding=\"async\" class=\"progressiveMedia-image js-progressiveMedia-image\" src=\"https:\/\/i0.wp.com\/cdn-images-1.medium.com\/max\/2000\/0*QuY7WrBVeJLrN2io.png?ssl=1\" data-src=\"https:\/\/i0.wp.com\/cdn-images-1.medium.com\/max\/2000\/0*QuY7WrBVeJLrN2io.png?ssl=1\" data-recalc-dims=\"1\" \/><\/div>\n<\/div>\n<\/figure>\n<\/div>\n<div class=\"section-inner sectionLayout--insetColumn\">\n<p id=\"5ebe\" class=\"graf graf--p graf-after--figure\">Click on\u00a0<code class=\"markup--code markup--p-code\">add User<\/code>\u00a0button and create a new user with any\u00a0<code class=\"markup--code markup--p-code\">User name<\/code>\u00a0that you want to give. Make sure to enable the\u00a0<strong class=\"markup--strong markup--p-strong\">Programmatic Access.\u00a0<\/strong>Then click on\u00a0<strong class=\"markup--strong markup--p-strong\">Next: Permissions<\/strong>.<\/p>\n<figure id=\"0c17\" class=\"graf graf--figure graf-after--p\">\n<div class=\"aspectRatioPlaceholder is-locked\">\n<div class=\"aspectRatioPlaceholder-fill\"><\/div>\n<div class=\"progressiveMedia js-progressiveMedia graf-image is-canvasLoaded is-imageLoaded\" data-image-id=\"0*Ow0d_6yRrzSHzJ0h.png\" data-width=\"1896\" data-height=\"862\" data-action=\"zoom\" data-action-value=\"0*Ow0d_6yRrzSHzJ0h.png\" data-scroll=\"native\"><canvas class=\"progressiveMedia-canvas js-progressiveMedia-canvas\" width=\"75\" height=\"33\"><\/canvas><img decoding=\"async\" class=\"progressiveMedia-image js-progressiveMedia-image\" src=\"https:\/\/i0.wp.com\/cdn-images-1.medium.com\/max\/1600\/0*Ow0d_6yRrzSHzJ0h.png?ssl=1\" data-src=\"https:\/\/i0.wp.com\/cdn-images-1.medium.com\/max\/1600\/0*Ow0d_6yRrzSHzJ0h.png?ssl=1\" data-recalc-dims=\"1\" \/><\/div>\n<\/div>\n<\/figure>\n<p id=\"d479\" class=\"graf graf--p graf-after--figure\">Select,\u00a0<code class=\"markup--code markup--p-code\">Attach existing properties directly<\/code>\u00a0and select the\u00a0<code class=\"markup--code markup--p-code\">AdministratorAccess<\/code>.<\/p>\n<figure id=\"0396\" class=\"graf graf--figure graf-after--p\">\n<div class=\"aspectRatioPlaceholder is-locked\">\n<div class=\"aspectRatioPlaceholder-fill\"><\/div>\n<div class=\"progressiveMedia js-progressiveMedia graf-image is-canvasLoaded is-imageLoaded\" data-image-id=\"0*HQAAgaWGwWz77K9c.png\" data-width=\"1231\" data-height=\"718\" data-action=\"zoom\" data-action-value=\"0*HQAAgaWGwWz77K9c.png\" data-scroll=\"native\"><canvas class=\"progressiveMedia-canvas js-progressiveMedia-canvas\" width=\"75\" height=\"42\"><\/canvas><img decoding=\"async\" class=\"progressiveMedia-image js-progressiveMedia-image\" src=\"https:\/\/i0.wp.com\/cdn-images-1.medium.com\/max\/1600\/0*HQAAgaWGwWz77K9c.png?ssl=1\" data-src=\"https:\/\/i0.wp.com\/cdn-images-1.medium.com\/max\/1600\/0*HQAAgaWGwWz77K9c.png?ssl=1\" data-recalc-dims=\"1\" \/><\/div>\n<\/div>\n<\/figure>\n<p id=\"d5b1\" class=\"graf graf--p graf-after--figure\">Click on\u00a0<strong class=\"markup--strong markup--p-strong\">Next: Review\u00a0<\/strong>and then\u00a0<strong class=\"markup--strong markup--p-strong\">Confirm.\u00a0<\/strong>You will then have created a user in AWS and will now have an\u00a0<strong class=\"markup--strong markup--p-strong\">Access Key ID\u00a0<\/strong>and\u00a0<strong class=\"markup--strong markup--p-strong\">Secret Access Key<\/strong>. This is unique for each user, so I won\u2019t be showing mine to you here.<\/p>\n<p id=\"14b9\" class=\"graf graf--p graf-after--p\">Now open a command terminal on your computer and install the\u00a0<code class=\"markup--code markup--p-code\">awscli<\/code>. Check out the official docs of AWS CLI to see how to install it depending on your operating system.<\/p>\n<div id=\"1e8b\" class=\"graf graf--mixtapeEmbed graf-after--p\"><a class=\"markup--anchor markup--mixtapeEmbed-anchor\" title=\"https:\/\/docs.aws.amazon.com\/cli\/latest\/userguide\/installing.html\" href=\"https:\/\/docs.aws.amazon.com\/cli\/latest\/userguide\/installing.html\" data-href=\"https:\/\/docs.aws.amazon.com\/cli\/latest\/userguide\/installing.html\"><strong class=\"markup--strong markup--mixtapeEmbed-strong\">Installing the AWS Command Line Interface &#8211; AWS Command Line Interface<\/strong><br \/>\n<em class=\"markup--em markup--mixtapeEmbed-em\">Install the AWS Command Line Interface on your system.<\/em>docs.aws.amazon.com<\/a><\/div>\n<p id=\"ec3e\" class=\"graf graf--p graf-after--mixtapeEmbed\">Once installed, we need to configure the AWS CLI by running the command:<\/p>\n<pre id=\"3059\" class=\"graf graf--pre graf-after--p\">$ aws configure<\/pre>\n<p id=\"980f\" class=\"graf graf--p graf-after--pre graf--trailing\">The terminal will then ask you to enter the Access Key ID and the Secret Access Key. The terminal will also ask you to enter the Default Region Name and Default Output format. You can leave the last two inputs empty.<\/p>\n<\/div>\n<\/div>\n<\/section>\n<section class=\"section section--body\">\n<div class=\"section-divider\">\n<hr class=\"section-divider\" \/>\n<\/div>\n<div class=\"section-content\">\n<div class=\"section-inner sectionLayout--insetColumn\">\n<h3 id=\"d01a\" class=\"graf graf--h3 graf--leading\">Serverless Framework<\/h3>\n<p id=\"4533\" class=\"graf graf--p graf-after--h3\">The\u00a0<code class=\"markup--code markup--p-code\">serverless<\/code>\u00a0framework allows one to build apps comprised of microservices that run in response to events, auto-scale for you, and only charge you when they run. This lowers the total cost of maintaining your apps, enabling you to build more logic, faster.<\/p>\n<p id=\"f6d7\" class=\"graf graf--p graf-after--p\">Let\u2019s globally install this framework into our system using NPM:<\/p>\n<pre id=\"85e9\" class=\"graf graf--pre graf-after--p\">$ npm install -g serverless<\/pre>\n<p id=\"f7d7\" class=\"graf graf--p graf-after--pre\">Once installed, we can run the\u00a0<code class=\"markup--code markup--p-code\">serverless<\/code>\u00a0framework in the terminal by running the command:<\/p>\n<pre id=\"cd4f\" class=\"graf graf--pre graf-after--p\">$ serverless<\/pre>\n<p id=\"09c8\" class=\"graf graf--p graf-after--pre\">This command will display all the available commands that come with the\u00a0<code class=\"markup--code markup--p-code\">serverless<\/code>\u00a0framework.<\/p>\n<figure id=\"baa6\" class=\"graf graf--figure graf-after--p\">\n<div class=\"aspectRatioPlaceholder is-locked\">\n<div class=\"aspectRatioPlaceholder-fill\"><\/div>\n<div class=\"progressiveMedia js-progressiveMedia graf-image is-canvasLoaded is-imageLoaded\" data-image-id=\"0*AHW8__wwYdSk6qnU.png\" data-width=\"1117\" data-height=\"800\" data-action=\"zoom\" data-action-value=\"0*AHW8__wwYdSk6qnU.png\" data-scroll=\"native\"><canvas class=\"progressiveMedia-canvas js-progressiveMedia-canvas\" width=\"75\" height=\"52\"><\/canvas><img decoding=\"async\" class=\"progressiveMedia-image js-progressiveMedia-image\" src=\"https:\/\/i0.wp.com\/cdn-images-1.medium.com\/max\/1600\/0*AHW8__wwYdSk6qnU.png?ssl=1\" data-src=\"https:\/\/i0.wp.com\/cdn-images-1.medium.com\/max\/1600\/0*AHW8__wwYdSk6qnU.png?ssl=1\" data-recalc-dims=\"1\" \/><\/div>\n<\/div>\n<\/figure>\n<p id=\"5da4\" class=\"graf graf--p graf-after--figure graf--trailing\">Note: You can also use the shorthand syntax for\u00a0<code class=\"markup--code markup--p-code\">serverless<\/code>\u00a0by typing\u00a0<code class=\"markup--code markup--p-code\">sls<\/code>.<\/p>\n<\/div>\n<\/div>\n<\/section>\n<section class=\"section section--body\">\n<div class=\"section-divider\">\n<hr class=\"section-divider\" \/>\n<\/div>\n<div class=\"section-content\">\n<div class=\"section-inner sectionLayout--insetColumn\">\n<h3 id=\"138e\" class=\"graf graf--h3 graf--leading\">Deploy a Node Function to AWS\u00a0Lambda<\/h3>\n<p id=\"55e8\" class=\"graf graf--p graf-after--h3\">In this section, we will see how to configure a Lambda function, add some simple code to it, and deploy it to AWS Lambda.<\/p>\n<p id=\"1ddc\" class=\"graf graf--p graf-after--p\">First let\u2019s create a folder where we can store all the code related to this post.<\/p>\n<pre id=\"551d\" class=\"graf graf--pre graf-after--p\">$ mkdir less-app<\/pre>\n<p id=\"2138\" class=\"graf graf--p graf-after--pre\">You can give any name you that you want to give to this folder. I have named my folder as\u00a0<code class=\"markup--code markup--p-code\">less-app<\/code>\u00a0for \u201cServerless-app\u201d.<\/p>\n<p id=\"ddd1\" class=\"graf graf--p graf-after--p\">Next create\u00a0<code class=\"markup--code markup--p-code\">serverless.yml<\/code>\u00a0file inside this folder.<\/p>\n<pre id=\"7172\" class=\"graf graf--pre graf-after--p\">$ touch serverless.yml<\/pre>\n<p id=\"df88\" class=\"graf graf--p graf-after--pre\">Here we will define a couple of fields such as\u00a0<code class=\"markup--code markup--p-code\">service<\/code>,\u00a0<code class=\"markup--code markup--p-code\">provider<\/code>, and\u00a0<code class=\"markup--code markup--p-code\">functions<\/code>\u00a0as shown below:<\/p>\n<pre id=\"1393\" class=\"graf graf--pre graf-after--p\">service: less-app\r\nprovider:\r\n  name: aws\r\n  runtime: nodejs8.10\r\nfunctions:\r\n  helloWorld:\r\n    handler: handler.run<\/pre>\n<p id=\"72fa\" class=\"graf graf--p graf-after--pre\">Here, the\u00a0<code class=\"markup--code markup--p-code\">handler<\/code>\u00a0refers to the\u00a0<code class=\"markup--code markup--p-code\">handler.js<\/code>\u00a0file which in turn needs to export the\u00a0<code class=\"markup--code markup--p-code\">run<\/code>\u00a0function. We have not yet created this file, so lets do that:<\/p>\n<pre id=\"69a7\" class=\"graf graf--pre graf-after--p\">$ touch handler.js<\/pre>\n<p id=\"3a0d\" class=\"graf graf--p graf-after--pre\">Inside this file, we need to export the\u00a0<code class=\"markup--code markup--p-code\">run<\/code>\u00a0function. This function has three parameters:\u00a0<code class=\"markup--code markup--p-code\">event<\/code>,\u00a0<code class=\"markup--code markup--p-code\">context<\/code>, and\u00a0<code class=\"markup--code markup--p-code\">callback<\/code>.<\/p>\n<p id=\"0192\" class=\"graf graf--p graf-after--p\">The\u00a0<code class=\"markup--code markup--p-code\">event<\/code>\u00a0is an object that contains all the necessary request data. The\u00a0<code class=\"markup--code markup--p-code\">context\u00a0<\/code>object contains AWS-specific values like AWS request ID, log group name, and so on. The\u00a0<code class=\"markup--code markup--p-code\">callback<\/code>\u00a0is a function and should be invoked with an error response as the first argument or a valid response as the second argument.<\/p>\n<p id=\"97dd\" class=\"graf graf--p graf-after--p\">We can now deploy this\u00a0<code class=\"markup--code markup--p-code\">run<\/code>\u00a0function using the\u00a0<code class=\"markup--code markup--p-code\">deploy<\/code>\u00a0command of the\u00a0<code class=\"markup--code markup--p-code\">serverless<\/code>\u00a0framework as shown below:<\/p>\n<pre id=\"2549\" class=\"graf graf--pre graf-after--p\">$ sls deploy<\/pre>\n<p id=\"dc62\" class=\"graf graf--p graf-after--pre\">This command takes a couple of minutes to finish. You should get something like this in your terminal:<\/p>\n<figure id=\"4da4\" class=\"graf graf--figure graf-after--p\">\n<div class=\"aspectRatioPlaceholder is-locked\">\n<div class=\"aspectRatioPlaceholder-fill\"><\/div>\n<div class=\"progressiveMedia js-progressiveMedia graf-image is-canvasLoaded is-imageLoaded\" data-image-id=\"0*R-zDfPI5Jw4ReWvo.png\" data-width=\"534\" data-height=\"606\" data-scroll=\"native\"><canvas class=\"progressiveMedia-canvas js-progressiveMedia-canvas\" width=\"66\" height=\"75\"><\/canvas><img decoding=\"async\" class=\"progressiveMedia-image js-progressiveMedia-image\" src=\"https:\/\/i0.wp.com\/cdn-images-1.medium.com\/max\/1600\/0*R-zDfPI5Jw4ReWvo.png?ssl=1\" data-src=\"https:\/\/i0.wp.com\/cdn-images-1.medium.com\/max\/1600\/0*R-zDfPI5Jw4ReWvo.png?ssl=1\" data-recalc-dims=\"1\" \/><\/div>\n<\/div>\n<\/figure>\n<p id=\"cdbd\" class=\"graf graf--p graf-after--figure\">Here, the\u00a0<code class=\"markup--code markup--p-code\">serverless<\/code>\u00a0framework will pack the code into a ZIP file and deploy it with a\u00a0<code class=\"markup--code markup--p-code\">CloudFormation<\/code>\u00a0stack.<\/p>\n<p id=\"308f\" class=\"graf graf--p graf-after--p\">We can now\u00a0<code class=\"markup--code markup--p-code\">invoke<\/code>\u00a0the Lambda function directly using the\u00a0<code class=\"markup--code markup--p-code\">invoke<\/code>command of the\u00a0<code class=\"markup--code markup--p-code\">serverless<\/code>\u00a0framework.<\/p>\n<pre id=\"9a94\" class=\"graf graf--pre graf-after--p\">$ sls invoke --function helloWorld<\/pre>\n<p id=\"c7c1\" class=\"graf graf--p graf-after--pre\">Your output should look something like this:<\/p>\n<figure id=\"1a61\" class=\"graf graf--figure graf-after--p\">\n<div class=\"aspectRatioPlaceholder is-locked\">\n<div class=\"aspectRatioPlaceholder-fill\"><\/div>\n<p><img decoding=\"async\" class=\"graf-image\" src=\"https:\/\/i0.wp.com\/cdn-images-1.medium.com\/max\/1600\/0*zIR5eNEovVJSCy3R.png?ssl=1\" data-image-id=\"0*zIR5eNEovVJSCy3R.png\" data-width=\"480\" data-height=\"65\" data-recalc-dims=\"1\" \/><\/p>\n<\/div>\n<\/figure>\n<p id=\"e49f\" class=\"graf graf--p graf-after--figure\">The\u00a0<code class=\"markup--code markup--p-code\">invoke<\/code>\u00a0command also lets us log out a debug statement. Go to the\u00a0<code class=\"markup--code markup--p-code\">handler.js<\/code>\u00a0file and insert a\u00a0<code class=\"markup--code markup--p-code\">console.log<\/code>\u00a0statement as shown below:<\/p>\n<pre id=\"e0f3\" class=\"graf graf--pre graf-after--p\">module.exports.run = (event, context, callback) =&gt; {\r\n  console.log(\"Hello World\")\r\n  callback(null, \"Hello World\")\r\n}<\/pre>\n<p id=\"49a3\" class=\"graf graf--p graf-after--pre\">To display this statement in our output, we need to add a\u00a0<code class=\"markup--code markup--p-code\">--log<\/code>\u00a0flag to our\u00a0<code class=\"markup--code markup--p-code\">invoke<\/code>\u00a0command.<\/p>\n<pre id=\"329f\" class=\"graf graf--pre graf-after--p\">$ sls invoke --function helloWorld --log<\/pre>\n<\/div>\n<div class=\"section-inner sectionLayout--outsetColumn\">\n<figure id=\"3d3b\" class=\"graf graf--figure graf--layoutOutsetCenter graf-after--pre\" data-scroll=\"native\">\n<div class=\"aspectRatioPlaceholder is-locked\">\n<div class=\"aspectRatioPlaceholder-fill\"><\/div>\n<div class=\"progressiveMedia js-progressiveMedia graf-image is-canvasLoaded is-imageLoaded\" data-image-id=\"0*cpgGN-9ra-tgdXgT.png\" data-width=\"1432\" data-height=\"170\" data-action=\"zoom\" data-action-value=\"0*cpgGN-9ra-tgdXgT.png\" data-scroll=\"native\"><canvas class=\"progressiveMedia-canvas js-progressiveMedia-canvas\" width=\"75\" height=\"8\"><\/canvas><img decoding=\"async\" class=\"progressiveMedia-image js-progressiveMedia-image\" src=\"https:\/\/i0.wp.com\/cdn-images-1.medium.com\/max\/2000\/0*cpgGN-9ra-tgdXgT.png?ssl=1\" data-src=\"https:\/\/i0.wp.com\/cdn-images-1.medium.com\/max\/2000\/0*cpgGN-9ra-tgdXgT.png?ssl=1\" data-recalc-dims=\"1\" \/><\/div>\n<\/div>\n<\/figure>\n<\/div>\n<div class=\"section-inner sectionLayout--insetColumn\">\n<p id=\"7e8f\" class=\"graf graf--p graf-after--figure\">Alternatively, we can also run the command\u00a0<code class=\"markup--code markup--p-code\">sls logs<\/code>\u00a0to print only the past log statements.<\/p>\n<pre id=\"a1e4\" class=\"graf graf--pre graf-after--p\">$ sls logs --function helloWorld<\/pre>\n<\/div>\n<div class=\"section-inner sectionLayout--outsetColumn\">\n<figure id=\"c153\" class=\"graf graf--figure graf--layoutOutsetCenter graf-after--pre\" data-scroll=\"native\">\n<div class=\"aspectRatioPlaceholder is-locked\">\n<div class=\"aspectRatioPlaceholder-fill\"><\/div>\n<div class=\"progressiveMedia js-progressiveMedia graf-image is-canvasLoaded is-imageLoaded\" data-image-id=\"0*rvpmY4AmHR083TSc.png\" data-width=\"1431\" data-height=\"123\" data-action=\"zoom\" data-action-value=\"0*rvpmY4AmHR083TSc.png\" data-scroll=\"native\"><canvas class=\"progressiveMedia-canvas js-progressiveMedia-canvas\" width=\"75\" height=\"6\"><\/canvas><img decoding=\"async\" class=\"progressiveMedia-image js-progressiveMedia-image\" src=\"https:\/\/i0.wp.com\/cdn-images-1.medium.com\/max\/2000\/0*rvpmY4AmHR083TSc.png?ssl=1\" data-src=\"https:\/\/i0.wp.com\/cdn-images-1.medium.com\/max\/2000\/0*rvpmY4AmHR083TSc.png?ssl=1\" data-recalc-dims=\"1\" \/><\/div>\n<\/div>\n<\/figure>\n<\/div>\n<div class=\"section-inner sectionLayout--insetColumn\">\n<p id=\"62f7\" class=\"graf graf--p graf-after--figure\">If you do not want to use the\u00a0<code class=\"markup--code markup--p-code\">callback<\/code>\u00a0function, you can return a\u00a0<code class=\"markup--code markup--p-code\">Promise<\/code>\u00a0as well.<\/p>\n<pre id=\"1e53\" class=\"graf graf--pre graf-after--p\">module.exports.run = (event) =&gt; {   \r\n  return Promise.resolve(\"Hello world\"); \r\n}<\/pre>\n<p id=\"5937\" class=\"graf graf--p graf-after--pre\">You might now think that we have to redeploy the whole thing, which takes some time. But we can also just deploy the\u00a0<code class=\"markup--code markup--p-code\">function<\/code>\u00a0part. This quickens things for us as it skips the\u00a0<code class=\"markup--code markup--p-code\">CloudFormation<\/code>\u00a0part and replaces the\u00a0<code class=\"markup--code markup--p-code\">ZIP<\/code>\u00a0for the specific function.<\/p>\n<pre id=\"ab28\" class=\"graf graf--pre graf-after--p\">$ sls deploy function --function helloWorld<\/pre>\n<p id=\"3dff\" class=\"graf graf--p graf-after--pre\">We can also declare our function as asynchronous and return the desired result.<\/p>\n<pre id=\"27b4\" class=\"graf graf--pre graf-after--p\">module.exports.run = async (event) =&gt; {\r\n  return \"Hello world\";\r\n}<\/pre>\n<p id=\"5141\" class=\"graf graf--p graf-after--pre graf--trailing\">You can re-deploy this function and invoke it, and it should work perfectly.<\/p>\n<\/div>\n<\/div>\n<\/section>\n<section class=\"section section--body\">\n<div class=\"section-divider\">\n<hr class=\"section-divider\" \/>\n<\/div>\n<div class=\"section-content\">\n<div class=\"section-inner sectionLayout--insetColumn\">\n<h3 id=\"350e\" class=\"graf graf--h3 graf--leading\">Attaching HTTP Endpoint to AWS Lambda\u00a0Function<\/h3>\n<p id=\"577f\" class=\"graf graf--p graf-after--h3\">Using the\u00a0<code class=\"markup--code markup--p-code\">serverless<\/code>\u00a0framework, we can attach an HTTP endpoint to a Lambda function. To do this, we need to define the\u00a0<code class=\"markup--code markup--p-code\">path<\/code>\u00a0and\u00a0<code class=\"markup--code markup--p-code\">method<\/code>\u00a0in the\u00a0<code class=\"markup--code markup--p-code\">serverless.yml<\/code>\u00a0file.<\/p>\n<pre id=\"73e7\" class=\"graf graf--pre graf-after--p\">functions:   \r\n  helloWorld:     \r\n    handler: handler.run     \r\n    events:        \r\n      - http:            \r\n          path: \/           \r\n          method: get<\/pre>\n<p id=\"8e11\" class=\"graf graf--p graf-after--pre\">But now that we are using HTTP, we need to make a couple of changes to our function because the expected response needs to be an object that contains the\u00a0<code class=\"markup--code markup--p-code\">statusCode<\/code>\u00a0and the\u00a0<code class=\"markup--code markup--p-code\">body<\/code>. Here, I am going to turn my response into\u00a0<code class=\"markup--code markup--p-code\">JSON.stringify()<\/code>\u00a0as shown below:<\/p>\n<pre id=\"07ac\" class=\"graf graf--pre graf-after--p\">module.exports.run = async (event) =&gt; {\r\n  return{\r\n    statusCode: 200,\r\n    body: JSON.stringify({\r\n      message: \"Hello World\"\r\n    })\r\n  }\r\n}<\/pre>\n<p id=\"3c6a\" class=\"graf graf--p graf-after--pre\">Run the\u00a0<code class=\"markup--code markup--p-code\">sls deploy<\/code>\u00a0command in the terminal. Unlike previous cases, we cannot add the\u00a0<code class=\"markup--code markup--p-code\">--function<\/code>\u00a0flag here because the configuration has been changed.<\/p>\n<p id=\"c9dd\" class=\"graf graf--p graf-after--p\">Once deployed, we can use\u00a0<code class=\"markup--code markup--p-code\">curl<\/code>\u00a0to invoke the published HTTP endpoint.<\/p>\n<figure id=\"417a\" class=\"graf graf--figure graf-after--p graf--trailing\">\n<div class=\"aspectRatioPlaceholder is-locked\">\n<div class=\"aspectRatioPlaceholder-fill\"><\/div>\n<p><img decoding=\"async\" class=\"graf-image\" src=\"https:\/\/i0.wp.com\/cdn-images-1.medium.com\/max\/1600\/0*2fXA_q3qrFRl72tH.png?ssl=1\" data-image-id=\"0*2fXA_q3qrFRl72tH.png\" data-width=\"596\" data-height=\"40\" data-recalc-dims=\"1\" \/><\/p>\n<\/div>\n<\/figure>\n<\/div>\n<\/div>\n<\/section>\n<section class=\"section section--body\">\n<div class=\"section-divider\">\n<hr class=\"section-divider\" \/>\n<\/div>\n<div class=\"section-content\">\n<div class=\"section-inner sectionLayout--insetColumn\">\n<h3 id=\"610a\" class=\"graf graf--h3 graf--leading\">DynamoDB<\/h3>\n<p id=\"0727\" class=\"graf graf--p graf-after--h3\">DynamoDB is a fully managed NoSQL database service by AWS that provides fast and predictable performance with seamless scalability. It allows us to create a database table that can store and retrieve any amount of data, and serve any level of request traffic.<\/p>\n<p id=\"0a37\" class=\"graf graf--p graf-after--p\">Lets see how to deploy a DynamoDB table. In order to add a DynamoDB table to our app, we need to add a\u00a0<code class=\"markup--code markup--p-code\">resources<\/code>\u00a0section to our\u00a0<code class=\"markup--code markup--p-code\">serverless.yml<\/code>\u00a0file.<\/p>\n<pre id=\"adb1\" class=\"graf graf--pre graf-after--p\">resources:   \r\n  Resources:     \r\n    HeroesTable:       \r\n      Type: 'AWS::DynamoDB::Table'       \r\n      Properties:        \r\n        TableName: heroes        \r\n        AttributeDefinitions:           \r\n          -             \r\n            AttributeName: id             \r\n            AttributeType: S         \r\n        KeySchema:           \r\n          -             \r\n            AttributeName: id             \r\n            KeyType: HASH         \r\n        ProvisionedThroughput:            \r\n          ReadCapacityUnits: 1           \r\n          WriteCapacityUnits: 1<\/pre>\n<p id=\"45a1\" class=\"graf graf--p graf-after--pre\">We then run\u00a0<code class=\"markup--code markup--p-code\">sls deploy<\/code>\u00a0command in our terminal. This will tell\u00a0<code class=\"markup--code markup--p-code\">CloudFormation<\/code>\u00a0to set up our table.<\/p>\n<p id=\"cba8\" class=\"graf graf--p graf-after--p\">Go to the\u00a0<a class=\"markup--anchor markup--p-anchor\" href=\"https:\/\/console.aws.amazon.com\/dynamodb\/home?region=us-east-1#tables:\" target=\"_blank\" rel=\"noopener\" data-href=\"https:\/\/console.aws.amazon.com\/dynamodb\/home?region=us-east-1#tables:\">DynamoDB Console<\/a>\u00a0and you will that a table named\u00a0<code class=\"markup--code markup--p-code\">heroes<\/code>\u00a0has been automatically created. We can add more Attributes to this table later on. Right now, I have only added one attribute named\u00a0<code class=\"markup--code markup--p-code\">id<\/code>\u00a0to create the table.<\/p>\n<\/div>\n<div class=\"section-inner sectionLayout--outsetColumn\">\n<figure id=\"f965\" class=\"graf graf--figure graf--layoutOutsetCenter graf-after--p graf--trailing\" data-scroll=\"native\">\n<div class=\"aspectRatioPlaceholder is-locked\">\n<div class=\"aspectRatioPlaceholder-fill\"><\/div>\n<div class=\"progressiveMedia js-progressiveMedia graf-image is-canvasLoaded is-imageLoaded\" data-image-id=\"0*mrtGLdztPyOmvB41.png\" data-width=\"1918\" data-height=\"899\" data-action=\"zoom\" data-action-value=\"0*mrtGLdztPyOmvB41.png\" data-scroll=\"native\"><canvas class=\"progressiveMedia-canvas js-progressiveMedia-canvas\" width=\"75\" height=\"35\"><\/canvas><img decoding=\"async\" class=\"progressiveMedia-image js-progressiveMedia-image\" src=\"https:\/\/i0.wp.com\/cdn-images-1.medium.com\/max\/2000\/0*mrtGLdztPyOmvB41.png?ssl=1\" data-src=\"https:\/\/i0.wp.com\/cdn-images-1.medium.com\/max\/2000\/0*mrtGLdztPyOmvB41.png?ssl=1\" data-recalc-dims=\"1\" \/><\/div>\n<\/div>\n<\/figure>\n<\/div>\n<\/div>\n<\/section>\n<section class=\"section section--body\">\n<div class=\"section-divider\">\n<hr class=\"section-divider\" \/>\n<\/div>\n<div class=\"section-content\">\n<div class=\"section-inner sectionLayout--insetColumn\">\n<h3 id=\"814d\" class=\"graf graf--h3 graf--leading\">Storing Data in\u00a0DynamoDB<\/h3>\n<p id=\"9097\" class=\"graf graf--p graf-after--h3\">Before we can start storing data in our DynamoDB, we need to set some permissions for the Lambda function to have write access.<\/p>\n<p id=\"8ea0\" class=\"graf graf--p graf-after--p\">Inside the\u00a0<code class=\"markup--code markup--p-code\">serverless.yml<\/code>\u00a0file, remove the contents of the\u00a0<code class=\"markup--code markup--p-code\">functions<\/code>\u00a0section completely and create a new function called\u00a0<code class=\"markup--code markup--p-code\">createHero<\/code>\u00a0as shown below:<\/p>\n<pre id=\"5efc\" class=\"graf graf--pre graf-after--p\">functions:\r\n  createHero:\r\n    handler: create.run\r\n      events:\r\n        - http:\r\n            path: heroes\r\n            method: post<\/pre>\n<p id=\"720b\" class=\"graf graf--p graf-after--pre\">But the Lambda function does not have the permissions to interact with our DynamoDB table by default. So we need to give these permissions to our Lambda function. This can be done with the help of\u00a0<code class=\"markup--code markup--p-code\">iamRole<\/code>.<\/p>\n<p id=\"ac52\" class=\"graf graf--p graf-after--p\">The\u00a0<code class=\"markup--code markup--p-code\">serverless<\/code>\u00a0framework already uses\u00a0<code class=\"markup--code markup--p-code\">iamRole<\/code>\u00a0under the hood. We need to use\u00a0<code class=\"markup--code markup--p-code\">iamRoleStatements<\/code>\u00a0to extend the permissions for the specific\u00a0<code class=\"markup--code markup--p-code\">iamRole<\/code>.<\/p>\n<p id=\"6ad7\" class=\"graf graf--p graf-after--p\">In your DynamoDB console, click on the table to open its overview. In the\u00a0<strong class=\"markup--strong markup--p-strong\">Table Details\u00a0<\/strong>section, you should find the\u00a0<strong class=\"markup--strong markup--p-strong\">Amazon Resourse Name (ARN)<\/strong>. Enter its content as\u00a0<code class=\"markup--code markup--p-code\">Resource<\/code>\u00a0inside the\u00a0<code class=\"markup--code markup--p-code\">iamRoleStatements<\/code>\u00a0in the\u00a0<code class=\"markup--code markup--p-code\">serverless.yml<\/code>\u00a0file as shown below:<\/p>\n<pre id=\"b81a\" class=\"graf graf--pre graf-after--p\">provider:\r\n  name: aws\r\n  runtime: nodejs8.10\r\n  iamRoleStatements:\r\n    - Effect: Allow\r\n      Action:\r\n        - dynamodb:PutItem\r\n      Resource: \"&lt;enter your Amazon Resource Name here&gt;\"<\/pre>\n<p id=\"5cb0\" class=\"graf graf--p graf-after--pre\">We also have to create the function that will actually send the data to our DynamoDB table. So create a new file named\u00a0<code class=\"markup--code markup--p-code\">create.js<\/code>.<\/p>\n<pre id=\"8a8b\" class=\"graf graf--pre graf-after--p\">$ touch create.js<\/pre>\n<p id=\"ce6c\" class=\"graf graf--p graf-after--pre\">Inside this file, add a function that will return a response.<\/p>\n<pre id=\"f105\" class=\"graf graf--pre graf-after--p\">module.exports.run = async (event) =&gt; {\r\n  const data = JSON.parse(event.body);\r\n  return {\r\n    statusCode: 200,\r\n    body: JSON.stringify(data)\r\n  };\r\n};<\/pre>\n<p id=\"15c7\" class=\"graf graf--p graf-after--pre\">To let this function interact with DynamoDB, we need to import the\u00a0<code class=\"markup--code markup--p-code\">aws-sdk<\/code>and instantiate a\u00a0<code class=\"markup--code markup--p-code\">documentClient()<\/code>\u00a0inside the\u00a0<code class=\"markup--code markup--p-code\">serverless.yml<\/code>\u00a0file:<\/p>\n<pre id=\"b192\" class=\"graf graf--pre graf-after--p\">const AWS = require(\"aws-sdk\");\r\nconst client = new AWS.DynamoDB.documentClient();<\/pre>\n<p id=\"471f\" class=\"graf graf--p graf-after--pre\">Along with this, create a new\u00a0<em class=\"markup--em markup--p-em\">const\u00a0<\/em>named\u00a0<code class=\"markup--code markup--p-code\">params<\/code>\u00a0as shown below:<\/p>\n<pre id=\"41fd\" class=\"graf graf--pre graf-after--p\">module.exports.run = async (event) =&gt; {\r\n  const data = JSON.parse(event.body);\r\n  <strong class=\"markup--strong markup--pre-strong\">const params = {\r\n    TableName: \"heroes\",\r\n    Item: {\r\n      id: \"hero1\",\r\n      name: data.name,\r\n      checked: false\r\n    }\r\n  };\r\n  await client.put(params).promise();<\/strong>\r\n  return {\r\n    statusCode: 200,\r\n    body: JSON.stringify(data)\r\n  };\r\n};<\/pre>\n<p id=\"0a17\" class=\"graf graf--p graf-after--pre\">There is one issue in this code, every new item that we add to our table will have the same\u00a0<code class=\"markup--code markup--p-code\">id<\/code>. To solve this, we can add the\u00a0<code class=\"markup--code markup--p-code\">uuid<\/code>\u00a0package to our code. This package will generate a new\u00a0<code class=\"markup--code markup--p-code\">id<\/code>\u00a0for every new request.<\/p>\n<p id=\"fc6b\" class=\"graf graf--p graf-after--p\">Create a new file named\u00a0<code class=\"markup--code markup--p-code\">package.json<\/code>:<\/p>\n<pre id=\"4069\" class=\"graf graf--pre graf-after--p\">$ touch package.json<\/pre>\n<p id=\"3148\" class=\"graf graf--p graf-after--pre\">Inside this file, write the following code:<\/p>\n<pre id=\"d197\" class=\"graf graf--pre graf-after--p\">{\r\n  \"name\": \"less-app\",\r\n  \"private\": true\r\n}<\/pre>\n<p id=\"57d9\" class=\"graf graf--p graf-after--pre\">Then install the\u00a0<code class=\"markup--code markup--p-code\">uuid<\/code>\u00a0package using NPM\/Yarn:<\/p>\n<pre id=\"5053\" class=\"graf graf--pre graf-after--p\">$ npm install --save uuid<\/pre>\n<p id=\"e044\" class=\"graf graf--p graf-after--pre\">Finally, import this package into the\u00a0<code class=\"markup--code markup--p-code\">create.js<\/code>\u00a0file:<\/p>\n<pre id=\"05c6\" class=\"graf graf--pre graf-after--p\">const uuid = require(\"uuid\/v4\");<\/pre>\n<p id=\"3d2e\" class=\"graf graf--p graf-after--pre\">Also re-write the\u00a0<code class=\"markup--code markup--p-code\">id<\/code>\u00a0property inside the\u00a0<code class=\"markup--code markup--p-code\">Item<\/code>\u00a0object using the\u00a0<code class=\"markup--code markup--p-code\">uuid<\/code>\u00a0package as shown here:<\/p>\n<pre id=\"05c9\" class=\"graf graf--pre graf-after--p\">Item: {\r\n  <strong class=\"markup--strong markup--pre-strong\">id: uuid()<\/strong>,\r\n  name: data.name,\r\n  checked: false\r\n}<\/pre>\n<p id=\"8436\" class=\"graf graf--p graf-after--pre\">With that, we have set up everything and can redeploy this using\u00a0<code class=\"markup--code markup--p-code\">serverless<\/code>.<\/p>\n<pre id=\"d237\" class=\"graf graf--pre graf-after--p\">$ sls deploy<\/pre>\n<p id=\"f4e7\" class=\"graf graf--p graf-after--pre\">Once deployed we can use\u00a0<code class=\"markup--code markup--p-code\">curl<\/code>\u00a0to create an entry into the DynamoDB table as shown below:<\/p>\n<pre id=\"54b0\" class=\"graf graf--pre graf-after--p\">$ curl -X \"&lt;POST URL&gt;\" --data '{\"text\": \"batman\"}'<\/pre>\n<p id=\"e2d8\" class=\"graf graf--p graf-after--pre graf--trailing\">Check in the AWS console to see if this submission was recorded.<\/p>\n<\/div>\n<\/div>\n<\/section>\n<section class=\"section section--body\">\n<div class=\"section-divider\">\n<hr class=\"section-divider\" \/>\n<\/div>\n<div class=\"section-content\">\n<div class=\"section-inner sectionLayout--insetColumn\">\n<h3 id=\"cd04\" class=\"graf graf--h3 graf--leading\">Conclusion<\/h3>\n<p id=\"d8a7\" class=\"graf graf--p graf-after--h3\">I hope this post helped you understand the basics of AWS Lambda and understand why serverless architecture is worth trying out.<\/p>\n<p id=\"debc\" class=\"graf graf--p graf-after--p\">Serverless Architecture like AWS Lambda will simplify the maintenance of backend systems while giving cost benefits for handling all sorts of different user behaviors.<\/p>\n<p id=\"12d0\" class=\"graf graf--p graf-after--p\">You should especially consider implementing serverless architecture if you have a small number of functions that you need hosted. If your application is more complex, a serverless architecture can still be beneficial, but you will need to build your app in a different way.<\/p>\n<p id=\"3b26\" class=\"graf graf--p graf-after--p graf--trailing\">This may not be feasible if you have an existing application. It may make more sense to migrate pieces of the application into serverless functions over time.<\/p>\n<\/div>\n<\/div>\n<\/section>\n<hr class=\"section-divider\" \/>\n<h3>Further Reading<\/h3>\n<ul>\n<li><a href=\"https:\/\/blog.bitsrc.io\/monorepo-architecture-simplified-with-bit-and-npm-b1354be62870\">Monorepos Made Easier with Bit and NPM<\/a><\/li>\n<li><a href=\"https:\/\/blog.bitsrc.io\/how-to-easily-share-react-components-between-projects-3dd42149c09\">How To Share React UI Components Between Projects And Apps<\/a><\/li>\n<li><a href=\"https:\/\/blog.bitsrc.io\/how-to-avoid-duplicate-code-with-git-bit-fe19ceaa65e3\">How to Avoid Duplicate Code with Git+Bit<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>This article was originally written by Rajat S on Medium. Reposted with permission from Bits and Pieces. Serverless architecture refers to the concept where you give your backend logic to a third party vendor\u2019s server architecture. Doing this allows a developer to focus more on their app and not worry about the server at much.<\/p>\n","protected":false},"author":26,"featured_media":6272,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false}}},"categories":[1363,83,2143,2101],"tags":[270,417,10,619],"class_list":["post-6270","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-all-episodes","category-articles","category-exclusive-content","category-contributions","tag-amazon-web-services","tag-cloud-computing","tag-javascript","tag-programming"],"jetpack_publicize_connections":[],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v22.8 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Serverless Backend using AWS Lambda: Hands-on Guide - Software Engineering Daily<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/blog.bitsrc.io\/serverless-backend-using-aws-lambda-hands-on-guide-31806ceb735e\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Serverless Backend using AWS Lambda: Hands-on Guide - Software Engineering Daily\" \/>\n<meta property=\"og:description\" content=\"This article was originally written by Rajat S on Medium. Reposted with permission from Bits and Pieces. Serverless architecture refers to the concept where you give your backend logic to a third party vendor\u2019s server architecture. Doing this allows a developer to focus more on their app and not worry about the server at much.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/blog.bitsrc.io\/serverless-backend-using-aws-lambda-hands-on-guide-31806ceb735e\" \/>\n<meta property=\"og:site_name\" content=\"Software Engineering Daily\" \/>\n<meta property=\"article:published_time\" content=\"2018-10-30T15:00:54+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2018-10-31T14:02:47+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/i0.wp.com\/softwareengineeringdaily.com\/wp-content\/uploads\/2018\/10\/aws-lambda-featured.png?fit=800%2C800&ssl=1\" \/>\n\t<meta property=\"og:image:width\" content=\"800\" \/>\n\t<meta property=\"og:image:height\" content=\"800\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Rajat S\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@geeky_writer_\" \/>\n<meta name=\"twitter:site\" content=\"@software_daily\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Rajat S\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"11 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/blog.bitsrc.io\/serverless-backend-using-aws-lambda-hands-on-guide-31806ceb735e#article\",\"isPartOf\":{\"@id\":\"https:\/\/softwareengineeringdaily.com\/2018\/10\/30\/serverless-backend-using-aws-lambda-hands-on-guide\/\"},\"author\":{\"name\":\"Rajat S\",\"@id\":\"https:\/\/softwareengineeringdaily.com\/#\/schema\/person\/79d2fb666be6b77c6138c7353eaca5f5\"},\"headline\":\"Serverless Backend using AWS Lambda: Hands-on Guide\",\"datePublished\":\"2018-10-30T15:00:54+00:00\",\"dateModified\":\"2018-10-31T14:02:47+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/softwareengineeringdaily.com\/2018\/10\/30\/serverless-backend-using-aws-lambda-hands-on-guide\/\"},\"wordCount\":1765,\"publisher\":{\"@id\":\"https:\/\/softwareengineeringdaily.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/blog.bitsrc.io\/serverless-backend-using-aws-lambda-hands-on-guide-31806ceb735e#primaryimage\"},\"thumbnailUrl\":\"https:\/\/i0.wp.com\/softwareengineeringdaily.com\/wp-content\/uploads\/2018\/10\/aws-lambda-featured.png?fit=800%2C800&ssl=1\",\"keywords\":[\"Amazon Web Services\",\"Cloud Computing\",\"JavaScript\",\"programming\"],\"articleSection\":[\"All Content\",\"Exclusive Articles\",\"Exclusive Content\",\"Written Contributions\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/softwareengineeringdaily.com\/2018\/10\/30\/serverless-backend-using-aws-lambda-hands-on-guide\/\",\"url\":\"https:\/\/blog.bitsrc.io\/serverless-backend-using-aws-lambda-hands-on-guide-31806ceb735e\",\"name\":\"Serverless Backend using AWS Lambda: Hands-on Guide - Software Engineering Daily\",\"isPartOf\":{\"@id\":\"https:\/\/softwareengineeringdaily.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/blog.bitsrc.io\/serverless-backend-using-aws-lambda-hands-on-guide-31806ceb735e#primaryimage\"},\"image\":{\"@id\":\"https:\/\/blog.bitsrc.io\/serverless-backend-using-aws-lambda-hands-on-guide-31806ceb735e#primaryimage\"},\"thumbnailUrl\":\"https:\/\/i0.wp.com\/softwareengineeringdaily.com\/wp-content\/uploads\/2018\/10\/aws-lambda-featured.png?fit=800%2C800&ssl=1\",\"datePublished\":\"2018-10-30T15:00:54+00:00\",\"dateModified\":\"2018-10-31T14:02:47+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/blog.bitsrc.io\/serverless-backend-using-aws-lambda-hands-on-guide-31806ceb735e#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/blog.bitsrc.io\/serverless-backend-using-aws-lambda-hands-on-guide-31806ceb735e\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/blog.bitsrc.io\/serverless-backend-using-aws-lambda-hands-on-guide-31806ceb735e#primaryimage\",\"url\":\"https:\/\/i0.wp.com\/softwareengineeringdaily.com\/wp-content\/uploads\/2018\/10\/aws-lambda-featured.png?fit=800%2C800&ssl=1\",\"contentUrl\":\"https:\/\/i0.wp.com\/softwareengineeringdaily.com\/wp-content\/uploads\/2018\/10\/aws-lambda-featured.png?fit=800%2C800&ssl=1\",\"width\":800,\"height\":800},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/blog.bitsrc.io\/serverless-backend-using-aws-lambda-hands-on-guide-31806ceb735e#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/softwareengineeringdaily.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Serverless Backend using AWS Lambda: Hands-on Guide\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/softwareengineeringdaily.com\/#website\",\"url\":\"https:\/\/softwareengineeringdaily.com\/\",\"name\":\"Software Engineering Daily\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/softwareengineeringdaily.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/softwareengineeringdaily.com\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/softwareengineeringdaily.com\/#organization\",\"name\":\"Software Engineering Daily\",\"url\":\"https:\/\/softwareengineeringdaily.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/softwareengineeringdaily.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/i0.wp.com\/softwareengineeringdaily.com\/wp-content\/uploads\/2024\/01\/cropped-sed_website_banner.png?fit=549%2C169&ssl=1\",\"contentUrl\":\"https:\/\/i0.wp.com\/softwareengineeringdaily.com\/wp-content\/uploads\/2024\/01\/cropped-sed_website_banner.png?fit=549%2C169&ssl=1\",\"width\":549,\"height\":169,\"caption\":\"Software Engineering Daily\"},\"image\":{\"@id\":\"https:\/\/softwareengineeringdaily.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/x.com\/software_daily\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/softwareengineeringdaily.com\/#\/schema\/person\/79d2fb666be6b77c6138c7353eaca5f5\",\"name\":\"Rajat S\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/softwareengineeringdaily.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/eadf55bf5a327daf7dde518ebbfe0c97?s=96&d=retro&r=pg\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/eadf55bf5a327daf7dde518ebbfe0c97?s=96&d=retro&r=pg\",\"caption\":\"Rajat S\"},\"sameAs\":[\"https:\/\/x.com\/geeky_writer_\"],\"url\":\"https:\/\/softwareengineeringdaily.com\/author\/rajats\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Serverless Backend using AWS Lambda: Hands-on Guide - Software Engineering Daily","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/blog.bitsrc.io\/serverless-backend-using-aws-lambda-hands-on-guide-31806ceb735e","og_locale":"en_US","og_type":"article","og_title":"Serverless Backend using AWS Lambda: Hands-on Guide - Software Engineering Daily","og_description":"This article was originally written by Rajat S on Medium. Reposted with permission from Bits and Pieces. Serverless architecture refers to the concept where you give your backend logic to a third party vendor\u2019s server architecture. Doing this allows a developer to focus more on their app and not worry about the server at much.","og_url":"https:\/\/blog.bitsrc.io\/serverless-backend-using-aws-lambda-hands-on-guide-31806ceb735e","og_site_name":"Software Engineering Daily","article_published_time":"2018-10-30T15:00:54+00:00","article_modified_time":"2018-10-31T14:02:47+00:00","og_image":[{"width":800,"height":800,"url":"https:\/\/i0.wp.com\/softwareengineeringdaily.com\/wp-content\/uploads\/2018\/10\/aws-lambda-featured.png?fit=800%2C800&ssl=1","type":"image\/png"}],"author":"Rajat S","twitter_card":"summary_large_image","twitter_creator":"@geeky_writer_","twitter_site":"@software_daily","twitter_misc":{"Written by":"Rajat S","Est. reading time":"11 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/blog.bitsrc.io\/serverless-backend-using-aws-lambda-hands-on-guide-31806ceb735e#article","isPartOf":{"@id":"https:\/\/softwareengineeringdaily.com\/2018\/10\/30\/serverless-backend-using-aws-lambda-hands-on-guide\/"},"author":{"name":"Rajat S","@id":"https:\/\/softwareengineeringdaily.com\/#\/schema\/person\/79d2fb666be6b77c6138c7353eaca5f5"},"headline":"Serverless Backend using AWS Lambda: Hands-on Guide","datePublished":"2018-10-30T15:00:54+00:00","dateModified":"2018-10-31T14:02:47+00:00","mainEntityOfPage":{"@id":"https:\/\/softwareengineeringdaily.com\/2018\/10\/30\/serverless-backend-using-aws-lambda-hands-on-guide\/"},"wordCount":1765,"publisher":{"@id":"https:\/\/softwareengineeringdaily.com\/#organization"},"image":{"@id":"https:\/\/blog.bitsrc.io\/serverless-backend-using-aws-lambda-hands-on-guide-31806ceb735e#primaryimage"},"thumbnailUrl":"https:\/\/i0.wp.com\/softwareengineeringdaily.com\/wp-content\/uploads\/2018\/10\/aws-lambda-featured.png?fit=800%2C800&ssl=1","keywords":["Amazon Web Services","Cloud Computing","JavaScript","programming"],"articleSection":["All Content","Exclusive Articles","Exclusive Content","Written Contributions"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/softwareengineeringdaily.com\/2018\/10\/30\/serverless-backend-using-aws-lambda-hands-on-guide\/","url":"https:\/\/blog.bitsrc.io\/serverless-backend-using-aws-lambda-hands-on-guide-31806ceb735e","name":"Serverless Backend using AWS Lambda: Hands-on Guide - Software Engineering Daily","isPartOf":{"@id":"https:\/\/softwareengineeringdaily.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/blog.bitsrc.io\/serverless-backend-using-aws-lambda-hands-on-guide-31806ceb735e#primaryimage"},"image":{"@id":"https:\/\/blog.bitsrc.io\/serverless-backend-using-aws-lambda-hands-on-guide-31806ceb735e#primaryimage"},"thumbnailUrl":"https:\/\/i0.wp.com\/softwareengineeringdaily.com\/wp-content\/uploads\/2018\/10\/aws-lambda-featured.png?fit=800%2C800&ssl=1","datePublished":"2018-10-30T15:00:54+00:00","dateModified":"2018-10-31T14:02:47+00:00","breadcrumb":{"@id":"https:\/\/blog.bitsrc.io\/serverless-backend-using-aws-lambda-hands-on-guide-31806ceb735e#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/blog.bitsrc.io\/serverless-backend-using-aws-lambda-hands-on-guide-31806ceb735e"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/blog.bitsrc.io\/serverless-backend-using-aws-lambda-hands-on-guide-31806ceb735e#primaryimage","url":"https:\/\/i0.wp.com\/softwareengineeringdaily.com\/wp-content\/uploads\/2018\/10\/aws-lambda-featured.png?fit=800%2C800&ssl=1","contentUrl":"https:\/\/i0.wp.com\/softwareengineeringdaily.com\/wp-content\/uploads\/2018\/10\/aws-lambda-featured.png?fit=800%2C800&ssl=1","width":800,"height":800},{"@type":"BreadcrumbList","@id":"https:\/\/blog.bitsrc.io\/serverless-backend-using-aws-lambda-hands-on-guide-31806ceb735e#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/softwareengineeringdaily.com\/"},{"@type":"ListItem","position":2,"name":"Serverless Backend using AWS Lambda: Hands-on Guide"}]},{"@type":"WebSite","@id":"https:\/\/softwareengineeringdaily.com\/#website","url":"https:\/\/softwareengineeringdaily.com\/","name":"Software Engineering Daily","description":"","publisher":{"@id":"https:\/\/softwareengineeringdaily.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/softwareengineeringdaily.com\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/softwareengineeringdaily.com\/#organization","name":"Software Engineering Daily","url":"https:\/\/softwareengineeringdaily.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/softwareengineeringdaily.com\/#\/schema\/logo\/image\/","url":"https:\/\/i0.wp.com\/softwareengineeringdaily.com\/wp-content\/uploads\/2024\/01\/cropped-sed_website_banner.png?fit=549%2C169&ssl=1","contentUrl":"https:\/\/i0.wp.com\/softwareengineeringdaily.com\/wp-content\/uploads\/2024\/01\/cropped-sed_website_banner.png?fit=549%2C169&ssl=1","width":549,"height":169,"caption":"Software Engineering Daily"},"image":{"@id":"https:\/\/softwareengineeringdaily.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/x.com\/software_daily"]},{"@type":"Person","@id":"https:\/\/softwareengineeringdaily.com\/#\/schema\/person\/79d2fb666be6b77c6138c7353eaca5f5","name":"Rajat S","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/softwareengineeringdaily.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/eadf55bf5a327daf7dde518ebbfe0c97?s=96&d=retro&r=pg","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/eadf55bf5a327daf7dde518ebbfe0c97?s=96&d=retro&r=pg","caption":"Rajat S"},"sameAs":["https:\/\/x.com\/geeky_writer_"],"url":"https:\/\/softwareengineeringdaily.com\/author\/rajats\/"}]}},"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"https:\/\/i0.wp.com\/softwareengineeringdaily.com\/wp-content\/uploads\/2018\/10\/aws-lambda-featured.png?fit=800%2C800&ssl=1","jetpack_shortlink":"https:\/\/wp.me\/p7GuoD-1D8","_links":{"self":[{"href":"https:\/\/softwareengineeringdaily.com\/wp-json\/wp\/v2\/posts\/6270"}],"collection":[{"href":"https:\/\/softwareengineeringdaily.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/softwareengineeringdaily.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/softwareengineeringdaily.com\/wp-json\/wp\/v2\/users\/26"}],"replies":[{"embeddable":true,"href":"https:\/\/softwareengineeringdaily.com\/wp-json\/wp\/v2\/comments?post=6270"}],"version-history":[{"count":0,"href":"https:\/\/softwareengineeringdaily.com\/wp-json\/wp\/v2\/posts\/6270\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/softwareengineeringdaily.com\/wp-json\/wp\/v2\/media\/6272"}],"wp:attachment":[{"href":"https:\/\/softwareengineeringdaily.com\/wp-json\/wp\/v2\/media?parent=6270"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/softwareengineeringdaily.com\/wp-json\/wp\/v2\/categories?post=6270"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/softwareengineeringdaily.com\/wp-json\/wp\/v2\/tags?post=6270"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}