Skip to main content
Brave Programmer Logo

BraveProgrammer

BraveProgrammer

HomeProjectsBlogsCoursesLessonsAbout

Site footer

BraveProgrammer

Free coding courses, practical tutorials, and real projects from BraveProgrammer. Learn web development with React, Next.js, and TypeScript.

Navigation

  • Home
  • Projects
  • Blogs
  • Courses

Resources

  • About
  • Lessons

© 2026 BraveProgrammer. All rights reserved.

  1. Courses
  2. /
  3. TypeScript Mastery

Lesson 51 of 56 · Typescript

Serverless Functions – AWS Lambda with TypeScript

Duration: 25 minutes

Set up a Lambda project

npm init -y
npm i -D typescript @types/aws-lambda @aws-sdk/client-s3
npm i aws-lambda
npx tsc --init

Handler example

import { APIGatewayProxyEvent, APIGatewayProxyResult } from 'aws-lambda';

export const handler = async (event: APIGatewayProxyEvent): Promise<APIGatewayProxyResult> => {
  const name = event.queryStringParameters?.name ?? 'world';
  return {
    statusCode: 200,
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({ message: `Hello, ${name}!` })
  };
};

Build & package

npm run build   # tsc → ./dist
zip -r function.zip dist/*

Upload function.zip via AWS Console or use the Serverless Framework:

npm i -g serverless
sls create -t aws-nodejs-typescript -p my-service

Testing locally with sam

sam local invoke "HelloFunction" -e event.json

Info

Remember to set runtime: nodejs20.x in serverless.yml and enable source maps for better debugging.

Previous: Deno – Secure Runtime for TypeScriptNext: GraphQL with TypeScript – `type-graphql`