How to debug in VS Code a local AWS Lambda function with API Gateway written in TypeScript?

I wrote a medium article explaining how to create, invoke and debug a TypeScript lambda function. Please for more details check the following link.


1- Create a nodejs12x;

  1. Create a nodejs12x lambda;

  2. Install TypeScript: npm i -g typescript

  3. Initialize typescript: tsc --init (It will create the tsconfig.json file)

  4. Replace the created tsconfig.json file with the following code:

    "compilerOptions": {
    "module": "CommonJS",
    "target": "ES2017",
    "noImplicitAny": true,
    "preserveConstEnums": true,
    "outDir": "./built",
    "sourceMap": true
    "include": ["handler/**/*"],
    "exclude": ["node_modules", "**/*.spec.ts"]
  5. Delete app.js file;

  6. Create your lambda in TypeScript code inside of handler folder (you need o create it):

    import { 
    } from "aws-lambda";
    export const lambdaHandler = async (
      event: APIGatewayProxyEvent
    ): Promise<APIGatewayProxyResult> => {
      const queries = JSON.stringify(event.queryStringParameters);
      return {
        statusCode: 200,
        body: `Queries: ${queries}`
  7. Adapt the template.yaml. Change the CodeUri path of your lambda: CodeUri: hello-world/built

  8. Install the needed node packages: npm install typescript @types/aws-lambda @types/node -save-dev

  9. Package json:

    "name": "typescript_lambda",
    "version": "1.0.0",
    "description": "hello world sample for TypeScript",
    "main": "app.js",
    "repository": "",
    "author": "Jorge Freitas",
    "license": "JorgeFreitas Ltd :)",
    "dependencies": {
    "scripts": {
      "compile": "tsc"
    "devDependencies": {
      "@types/aws-lambda": "^8.10.71",
      "@types/node": "^14.14.22",
      "aws-sdk": "^2.815.0",
      "typescript": "^4.1.3"
  10. npm install

  11. npm run compile

  12. Set a breakpoint in your lambda function (TypeScript code). On the left panel select Debug and then Start debugging (green button on top). And that's it :)

  13. Project structure

enter image description here

Please find more details in my tutorial.

source code