Serverless Framework Deploys AWS Lambda

Your `serverless.yml` maps `GET /hello` to `src/handler.main`. I’m curious how that small route config becomes an AWS footprint you can understand before granting deployment access.

You’ll trace how an HTTP API request reaches the function and what response it returns. You’ll see what the Framework adds around Lambda beyond the code it runs.

What Serverless Framework adds to Lambda

The Serverless Framework is a command-line deployment tool that packages a service and describes the AWS resources its functions need. AWS Lambda runs the handler, while an API Gateway HTTP API can route web requests to it.

The Framework uses your project configuration to deploy AWS resources, while the handler stays in Lambda and processes events after deployment.

Flow from a Serverless Framework project through its CLI and S3 artifact to Lambda and API Gateway resources
The Framework uploads a deployment package to S3 before CloudFormation provisions the Lambda function and HTTP API.

This example uses an HTTP API because the function needs a URL that clients can call. If the function responds only to AWS events, choose its event source instead of adding an HTTP route.

The service configuration connects a function handler to its trigger. The Lambda handler then receives the event and returns the response.

What you need before deploying

Framework v4 access and AWS deployment credentials control separate layers, so configure both before deploying.

  • Install Node.js and npm. The example selects AWS Lambda’s Node.js 24 runtime, identified in configuration as nodejs24.x.
  • Use an AWS account and a deployment profile assigned to you through IAM Identity Center. Follow AWS’s AWS CLI IAM Identity Center instructions instead of creating long-lived keys for this tutorial.
  • Choose the region and stage for the service. This example uses us-east-1 and dev.
  • Sign in to the Serverless Framework v4 CLI or provide a license key. Its account requirement is separate from the AWS profile, as described in the Framework v4 setup documentation.

AWS grants your deployment profile permission to create or update the service, while Lambda uses a separate execution role at runtime. The Lambda permissions guide explains the difference, so do not copy an administrator access key into the function.

Build and deploy an HTTP Lambda

The service has one function and one GET route, and its files connect that route to a Lambda handler.

Step 1: Create the service folder

Start with a new directory so the Framework can find its configuration and handler together.

mkdir lambda-hello && cd lambda-hello

Step 2: Add Serverless Framework to the project

Install the CLI as a project development dependency with npm. The command uses the package name without a version selector and does not create a package lock.

npm install --save-dev serverless --package-lock=false

The no-lock option keeps npm from generating a lockfile for this small example. If your service uses a committed lockfile, follow that repository’s dependency policy.

Step 3: Connect the route to a handler

The provider selects AWS with its Node.js runtime and region, then hello maps the GET request at /hello to the exported main function.

service: lambda-hello
provider:
  name: aws
  runtime: nodejs24.x
  region: us-east-1
functions:
  hello:
    handler: src/handler.main
    events:
      - httpApi:
          method: GET
          path: /hello

The handler value maps a file path to an exported function, while the HTTP API event configures an API Gateway route to invoke it.

Step 4: Return a response from the function

Lambda passes the request data to the handler as an event object. This handler reads the name query parameter, uses “world” when it is absent, and returns the status, content type, and JSON body that an HTTP integration needs.

export const main = async (event) => {
  const name = event.queryStringParameters?.name ?? "world";
  return {
    statusCode: 200,
    headers: { "content-type": "application/json" },
    body: JSON.stringify({ message: `Hello, ${name}!` }),
  };
};

The optional property access handles an event without query parameters, and the nullish fallback avoids replacing an explicitly empty value. The response body is a string because an HTTP API response carries serialized JSON.

Step 5: Run the handler locally

Pass the function an event with the same query parameter an HTTP API would provide. This direct Node.js call checks the handler’s response without creating AWS resources.

node --input-type=module -e 'import { main } from "./src/handler.js"; console.log(await main({ queryStringParameters: { name: "Ada" } }))'
Node.js handler returns status 200 and a JSON greeting for Ada
The local event has a query parameter named Ada, and the handler returns a 200 response with JSON.

I ran the handler with Ada and got a 200 response with a JSON greeting, but this local call tests only the function code, not Lambda or API Gateway.

Step 6: Deploy and check the HTTP route

The Framework command writes to AWS, so select the deployment profile and region before you run it. Confirm the stage in the service file.

npx serverless deploy --stage dev

The Framework deployment guide describes the process, and a successful deploy prints the API endpoint for this GET route. Open it with a name query parameter to receive the handler’s greeting.

Fix a deployment that stops early

Match the error to the layer that owns it. A region setting belongs to the provider or AWS profile, while a function permission belongs to the deployment identity or execution role.

SymptomCheckNext action
“Region is missing”The provider region and selected AWS profileSet the intended region in the service or configure the profile for that region.
Access denied for a Lambda actionThe AWS profile used by the CLI and its deployment permissionsAsk the account administrator for the assigned deployment role instead of attaching AdministratorAccess.
Handler file or export not foundThe configured path and exported function nameMatch src/handler.main to src/handler.js and its main export.

AWS Lambda separates permissions used by the deployment caller from permissions granted to the function while it runs. Keep those roles separate, and grant only the access this service needs.

Remove the stack when you finish

CloudFormation manages the service resources as a stack. Remove that stack with the same stage and region you used to create it.

npx serverless remove --stage dev

The Framework remove command deletes the deployed service defined by the project. Check the AWS account and stage before running it because this command removes cloud resources.

Common Serverless Framework questions

The Framework login, AWS profile, and Lambda execution role belong to different layers of the same deployment.

What does Serverless Framework do with AWS Lambda?

The Framework packages your service and deploys the AWS resources described by its configuration. AWS Lambda runs the function handler when an event invokes it.

Does running a Lambda handler locally deploy it?

No. Calling the exported function with an event checks the handler code on your local Node.js runtime. It does not create a Lambda function, API Gateway route, or AWS permissions.

Should I put AWS access keys in my Lambda code?

No. Use an assigned AWS identity for deployment and give the Lambda function a separate execution role. Do not store long-lived AWS keys in the source code.

Pankaj Kumar
Pankaj Kumar

Pankaj Kumar is the founder and CEO of CodeForGeek, with more than 14 years in IT. He is an open-source enthusiast who enjoys sharing what he learns through CodeForGeek and YouTube, with a focus on Python, data analytics, machine learning, Angular, Node.js, and Kafka.

Articles: 337