{"id":121281,"date":"2026-07-10T16:19:18","date_gmt":"2026-07-10T10:49:18","guid":{"rendered":"https:\/\/www.guvi.in\/blog\/?p=121281"},"modified":"2026-07-10T16:19:20","modified_gmt":"2026-07-10T10:49:20","slug":"serverless-framework-tutorial","status":"publish","type":"post","link":"https:\/\/www.guvi.in\/blog\/serverless-framework-tutorial\/","title":{"rendered":"Serverless Framework Tutorial: Build and Deploy an AWS Lambda HTTP API"},"content":{"rendered":"\n<p>Serverless Framework helps developers deploy cloud functions, APIs, events, and infrastructure using a simple configuration file. In this tutorial, we will build a small HTTP API using Serverless Framework, AWS Lambda, and API Gateway HTTP API.<\/p>\n\n\n\n<p>The tutorial uses Serverless Framework v4, AWS Lambda, and the Node.js 22 runtime. AWS currently lists nodejs22.x as a supported Lambda runtime, and Serverless Framework v4 requires authentication through Serverless Dashboard or a license key.&nbsp;<\/p>\n\n\n\n<p><em><strong>TL;DR<\/strong><\/em><\/p>\n\n\n\n<ul>\n<li><em>Builds a two-endpoint HTTP API (GET \/status, POST \/messages) using Serverless Framework v4, AWS Lambda, and Node.js 22<\/em><em><br><\/em><\/li>\n\n\n\n<li><em>Covers the full workflow: install, log in, configure serverless.yml, write the handler, test locally, deploy, and remove<\/em><em><br><\/em><\/li>\n\n\n\n<li><em>Includes fixes for 5 common deployment errors, missing credentials, expired tokens, unsupported runtimes, handler mismatches, CloudFormation rollbacks<\/em><em><br><\/em><\/li>\n\n\n\n<li><em>Ends with next steps for production readiness: auth, validation, monitoring, CI\/CD<\/em><em><br><\/em><\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>What is Serverless Framework?<\/strong><\/h2>\n\n\n\n<p>Serverless Framework is an open-source deployment framework used to build, configure, and deploy serverless applications across cloud platforms such as AWS, Azure, and Google Cloud. It allows developers to define functions, APIs, events, IAM permissions, environment variables, and cloud resources inside a single serverless.yml file. Instead of manually creating AWS Lambda functions, API Gateway routes, deployment packages, and CloudFormation stacks, Serverless Framework automates infrastructure provisioning and simplifies the complete serverless deployment workflow.<\/p>\n\n\n\n<p><strong>What You Will Build<\/strong><\/p>\n\n\n\n<p>We will create two <a href=\"https:\/\/www.guvi.in\/hub\/network-programming-with-python\/understanding-apis\/\" target=\"_blank\" rel=\"noreferrer noopener\">API<\/a> endpoints:<\/p>\n\n\n\n<p>GET \/status<\/p>\n\n\n\n<p>POST \/messages<\/p>\n\n\n\n<p>The first endpoint will return a health status. The second endpoint will accept a JSON message and return a response.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Prerequisites<\/strong><\/h2>\n\n\n\n<p>Before starting, install or create the following:<\/p>\n\n\n\n<ul>\n<li><a href=\"https:\/\/www.guvi.in\/blog\/best-nodejs-frameworks-guide\/\" target=\"_blank\" rel=\"noreferrer noopener\">Node.js<\/a> and npm<\/li>\n<\/ul>\n\n\n\n<ul>\n<li>An AWS account<\/li>\n\n\n\n<li>Serverless Framework CLI<\/li>\n\n\n\n<li><a href=\"https:\/\/www.guvi.in\/blog\/guide-for-amazon-web-services\/\" target=\"_blank\" rel=\"noreferrer noopener\">AWS<\/a> credentials or Serverless Dashboard access<\/li>\n<\/ul>\n\n\n\n<p>Serverless Framework is installed through npm, and the official documentation recommends installing it globally.&nbsp;<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Step-by-Step Guide to Using Serverless Framework<\/strong><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Step 1: Install Serverless Framework<\/h3>\n\n\n\n<p>Install Serverless Framework globally using npm. This gives access to the serverless command from the terminal.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>npm install -g serverless\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Step 2: Log In to Serverless Framework<\/h3>\n\n\n\n<p><a href=\"https:\/\/www.guvi.in\/blog\/guide-on-serverless-architecture\/\" target=\"_blank\" rel=\"noreferrer noopener\">Serverless Framework<\/a> v4 requires authentication. Run the login command and complete the browser-based login process.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>serverless login\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Step 3: Create a New Serverless Project<\/h3>\n\n\n\n<p>Create a new project folder and initialize a Node.js project. This creates the basic files needed for development.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mkdir serverless-http-api\ncd serverless-http-api\nnpm init -y\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Step 4: Create the Required Files<\/h3>\n\n\n\n<p>Create a serverless.yml file for cloud configuration and a handler.js file for Lambda function logic.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>touch serverless.yml handler.js\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Step 5: Configure the serverless.yml File<\/h3>\n\n\n\n<p>Define the cloud provider, runtime, region, functions, and HTTP API routes inside serverless.yml. This file tells Serverless Framework what to deploy.<\/p>\n\n\n\n<p><em>Build hands-on serverless computing skills with HCL GUVI\u2019s <\/em><a href=\"https:\/\/www.guvi.in\/courses\/cloud-computing\/serverless-aws-lambda\/?utm_source=blog&amp;utm_medium=hyperlink&amp;utm_campaign=serverless-framework-tutorial-build-and-deploy-an-aws-lambda-http-api\" target=\"_blank\" rel=\"noreferrer noopener\"><em>Serverless AWS Lambda Course<\/em><\/a><em>. Learn AWS Lambda, serverless architecture, API workflows, deployment basics, and real-world cloud application development through structured training designed for aspiring cloud and backend developers.<\/em><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 6: Write the Lambda Function<\/h3>\n\n\n\n<p>Add the function logic inside handler.js. The function receives an event, processes the request, and returns an HTTP response.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 7: Test the Function Locally<\/h3>\n\n\n\n<p>Use the local invoke command to test the Lambda function before deploying it to AWS.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>serverless invoke local --function getStatus\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Step 8: Deploy the Application<\/h3>\n\n\n\n<p>Deploy the serverless application to AWS. Serverless Framework packages the function code and creates cloud resources using AWS CloudFormation.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>serverless deploy\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Step 9: Test the Deployed API<\/h3>\n\n\n\n<p>Use the generated API Gateway URL to test the deployed endpoint with curl, <a href=\"https:\/\/www.guvi.in\/blog\/how-to-use-a-postman-tool\/\" target=\"_blank\" rel=\"noreferrer noopener\">Postman<\/a>, or a browser.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 10: Check Logs and Debug Issues<\/h3>\n\n\n\n<p>View Lambda logs from the terminal to <a href=\"https:\/\/www.guvi.in\/blog\/debugging-in-software-development\/\" target=\"_blank\" rel=\"noreferrer noopener\">debug<\/a> runtime errors, failed requests, or unexpected function behavior.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>serverless logs --function getStatus\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Step 11: Update and Redeploy<\/h3>\n\n\n\n<p>Make code or configuration changes, then redeploy the service. Use full deployment for infrastructure changes and function deployment for code-only updates.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>serverless deploy\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Step 12: Remove the Service<\/h3>\n\n\n\n<p>Remove the deployed AWS resources after testing to avoid unnecessary cloud charges.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>serverless remove\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">5 Common Serverless Framework Deployment Errors and How to Avoid Them<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">1. AWS Credentials Not Found<\/h3>\n\n\n\n<p>This error occurs when Serverless Framework cannot access valid AWS credentials during deployment.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>AWS provider credentials not found\n<\/code><\/pre>\n\n\n\n<p>Avoid this by configuring AWS credentials before running deployment.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>aws configure\n<\/code><\/pre>\n\n\n\n<p>Use the correct profile when working with multiple AWS accounts.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>serverless deploy --aws-profile dev-profile\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">2. Expired AWS Security Token<\/h3>\n\n\n\n<p>This happens when temporary AWS SSO or session credentials expire.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>The security token included in the request is expired\n<\/code><\/pre>\n\n\n\n<p>Avoid this by refreshing the AWS session before deployment.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>aws sso login --profile dev-profile\n<\/code><\/pre>\n\n\n\n<p>Then deploy with the same profile.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>serverless deploy --aws-profile dev-profile\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">3. Unsupported Lambda Runtime<\/h3>\n\n\n\n<p>Deployment can fail when serverless.yml uses an old or unsupported AWS Lambda runtime.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Runtime nodejs18.x is not supported\n<\/code><\/pre>\n\n\n\n<p>Avoid this by using a supported runtime.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>provider:\n  name: aws\n  runtime: nodejs22.x\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">4. Handler Not Found<\/h3>\n\n\n\n<p>This error appears when the handler path in serverless.yml does not match the file name or exported function.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Cannot resolve handler\n<\/code><\/pre>\n\n\n\n<p>Avoid this by keeping the handler reference and exported function consistent.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>functions:\n  getStatus:\n    handler: handler.getStatus\n<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>module.exports.getStatus = async function () {\n  return {\n    statusCode: 200,\n    body: JSON.stringify({ status: 'ok' })\n  };\n};\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">5. CloudFormation Stack Rollback<\/h3>\n\n\n\n<p>This happens when AWS fails to create one or more resources during deployment.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>CloudFormation stack is in ROLLBACK_COMPLETE state\n<\/code><\/pre>\n\n\n\n<p>Avoid this by checking CloudFormation events, fixing the failed resource, and removing the broken stack before redeploying.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>serverless remove\nserverless deploy\n<\/code><\/pre>\n\n\n\n<p>Most rollback issues come from wrong IAM permissions, invalid resource names, duplicate resources, unsupported configuration, or deployment to the wrong AWS region.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Conclusion<\/strong><\/h2>\n\n\n\n<p>Serverless Framework makes it easier to define, deploy, test, and manage AWS Lambda applications from one configuration file. In this tutorial, we created a Node.js HTTP API, tested it locally, deployed it to AWS, viewed logs, and removed the service after testing.<\/p>\n\n\n\n<p>A production project should also add request validation, authentication, environment variables, IAM permissions, monitoring, and <a href=\"https:\/\/www.guvi.in\/blog\/understanding-ci-cd\/\" target=\"_blank\" rel=\"noreferrer noopener\">CI\/CD<\/a> before going live.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>FAQs<\/strong><\/h2>\n\n\n<div id=\"rank-math-faq\" class=\"rank-math-block\">\n<div class=\"rank-math-list \">\n<div id=\"faq-question-1783341746896\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \"><strong>What is Serverless Framework used for?<\/strong><\/h3>\n<div class=\"rank-math-answer \">\n\n<p>Serverless Framework is used to build, configure, and deploy serverless applications. It helps developers manage AWS Lambda functions, API Gateway routes, IAM permissions, environment variables, and cloud resources through a single serverless.yml file.<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1783341765964\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \"><strong>Does Serverless Framework only work with AWS?<\/strong><\/h3>\n<div class=\"rank-math-answer \">\n\n<p>No. Serverless Framework is commonly used with AWS, but it also supports other cloud providers such as Azure and Google Cloud. AWS remains one of the most widely used providers because of its strong Lambda and API Gateway ecosystem.<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1783341793264\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \"><strong>What is the role of the serverless.yml file?<\/strong><\/h3>\n<div class=\"rank-math-answer \">\n\n<p>The serverless.yml file defines the complete serverless application configuration. It includes provider settings, runtime, region, stage, functions, events, IAM permissions, environment variables, and deployment resources.<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1783341812499\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \"><strong>Can Serverless Framework deploy REST APIs?<\/strong><\/h3>\n<div class=\"rank-math-answer \">\n\n<p>Yes. Serverless Framework can deploy REST APIs and HTTP APIs using AWS API Gateway. Developers can connect API routes directly to Lambda functions and expose them as public endpoints.<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1783341830331\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \"><strong>How do you remove a deployed Serverless Framework project?<\/strong><\/h3>\n<div class=\"rank-math-answer \">\n\n<p>Run the serverless remove command from the project folder. It deletes the deployed AWS resources created by the service, including Lambda functions, API Gateway routes, CloudFormation stacks, and related infrastructure.<\/p>\n\n<\/div>\n<\/div>\n<\/div>\n<\/div>","protected":false},"excerpt":{"rendered":"<p>Serverless Framework helps developers deploy cloud functions, APIs, events, and infrastructure using a simple configuration file. In this tutorial, we will build a small HTTP API using Serverless Framework, AWS Lambda, and API Gateway HTTP API. The tutorial uses Serverless Framework v4, AWS Lambda, and the Node.js 22 runtime. AWS currently lists nodejs22.x as a [&hellip;]<\/p>\n","protected":false},"author":60,"featured_media":122631,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[294],"tags":[],"views":"33","authorinfo":{"name":"Vaishali","url":"https:\/\/www.guvi.in\/blog\/author\/vaishali\/"},"thumbnailURL":"https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2026\/07\/Serverless-Framework-300x116.webp","_links":{"self":[{"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/posts\/121281"}],"collection":[{"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/users\/60"}],"replies":[{"embeddable":true,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/comments?post=121281"}],"version-history":[{"count":3,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/posts\/121281\/revisions"}],"predecessor-version":[{"id":122633,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/posts\/121281\/revisions\/122633"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/media\/122631"}],"wp:attachment":[{"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/media?parent=121281"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/categories?post=121281"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/tags?post=121281"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}