{
    "componentChunkName": "component---src-templates-blog-post-js",
    "path": "/aws-serverless-node-restapi-using-serverless-framework/",
    "result": {"data":{"site":{"siteMetadata":{"title":"CrewCode Solutions"}},"markdownRemark":{"id":"361811c6-75ac-583f-ada2-0052ae2cebbc","excerpt":"In this blog, I will guide you through the process of creating a serverless API using Node.js, AWS Lambda, and API Gateway, all managed effortlessly with the…","html":"<p>In this blog, I will guide you through the process of creating a serverless API using Node.js, AWS Lambda, and API Gateway, all managed effortlessly with the Serverless Framework.We’ll cover everything from setting up your project to deploying your API in AWS.\nBy the end of this tutorial, you’ll have a fully functional API that’s scalable, cost-efficient, and requires no server management.</p>\n<h4>Step 1 Install Node Js, NPM and Serverless framework</h4>\n<p>Install Node.js and npm.\nInstall the Serverless Framework</p>\n<pre><code class=\"language-ts\">npm install -g serverless\n</code></pre>\n<p>Configure AWS credentials:</p>\n<pre><code class=\"language-ts\">aws configure\n</code></pre>\n<h4>Step 2 Create a New Serverless Project</h4>\n<pre><code class=\"language-ts\">npx serverless\n</code></pre>\n<p>The command will create serverless node, express api project for you along with the serverless.yml file</p>\n<p><img src=\"https://crew-code-images.s3.us-east-1.amazonaws.com/blog_images/serverlss.png\" alt=\"page\"></p>\n<p><img src=\"https://crew-code-images.s3.us-east-1.amazonaws.com/blog_images/node-api.png\" alt=\"page\"></p>\n<h4>Step 3 Define Your Serverless Configuration</h4>\n<p>Customize the serverless.yml with the api according to your needs, all the api will be defined under functions->api->handler in this <code>handler.handler</code> handler is the name of the file and handler after dot is the name of the lambda function inside handler</p>\n<p>serverless.yml file</p>\n<pre><code class=\"language-ts\"># \"org\" ensures this Service is used with the correct Serverless Framework Access Key.\norg: crewcode\n# \"app\" enables Serverless Framework Dashboard features and sharing them with other Services.\napp: node-api\n# \"service\" is the name of this project. This will also be added to your AWS resource names.\nservice: node-api\n\nprovider:\n  name: aws\n  runtime: nodejs20.x\n\nfunctions:\n  api:\n    handler: handler.handler\n    events:\n      - httpApi: \"*\"\n\n</code></pre>\n<p>handler.js file</p>\n<pre><code class=\"language-ts\">const serverless = require(\"serverless-http\");\nconst express = require(\"express\");\nconst app = express();\n\napp.get(\"/\", (req, res, next) => {\n  return res.status(200).json({\n    message: \"Hello from root!\",\n  });\n});\n\napp.get(\"/hello\", (req, res, next) => {\n  return res.status(200).json({\n    message: \"Hello from path!\",\n  });\n});\n\napp.use((req, res, next) => {\n  return res.status(404).json({\n    error: \"Not Found\",\n  });\n});\n\nexports.handler = serverless(app);\n</code></pre>\n<h4>Step 4 Deploy the application to AWS:</h4>\n<pre><code class=\"language-ts\">npx serverless deploy\n</code></pre>","fields":{"slug":"/aws-serverless-node-restapi-using-serverless-framework/"},"frontmatter":{"title":"AWS Serverless Node Rest API using lambda function, api gateway and serverless framework","date":"April 06, 2022","description":"In this article i will explain you how you can create Node API using aws lambda function, api gateway and serverless framework","bannerimage":"https://crew-code-images.s3.us-east-1.amazonaws.com/blog_images/serverless-apigateway-node.jpg"}},"previous":{"fields":{"slug":"/adding-offline-capabilities-with-service-worker-angular/"},"frontmatter":{"title":"How to add offline capabilities with service worker in angular","date":"April 06, 2022","bannerimage":"https://crew-code-images.s3.us-east-1.amazonaws.com/blog_images/offline-capabilities-service-worker.jpeg"}},"next":{"fields":{"slug":"/adding-stripe-payment-in-react-application/"},"frontmatter":{"title":"Adding stripe payment in react application","date":"April 20, 2022","bannerimage":"https://crew-code-images.s3.us-east-1.amazonaws.com/blog_images/stripe-react.jpeg"}}},"pageContext":{"id":"361811c6-75ac-583f-ada2-0052ae2cebbc","previousPostId":"86a39015-e6c0-5f10-9f73-819fa8e2e479","nextPostId":"2b4f6f36-50c5-59ab-8fe8-e62eea1f4fa0"}},
    "staticQueryHashes": ["3860684146"]}