AWS & Typescript Masterclass - 4. Lambda - bundling, testing and debugging

September 9th, 2022

(23) Section Intro

(24) Why Bundling?

(25) Bundling with CDK Node Lambda

(26)Webpack intro

(27)Webpack setup

 


 

(23) Section Intro

 


 

(24) Why Bundling?

options

  1. deploy all node_modules

    • NOPE

  2. Node Lambda - with esbuild (integrated with CDK)

    • YES

  3. webpack (hard to configure)

    • NOPE

 

why?

  • growing list of dependencies

  • typescript needs compilation to node_js

 


(25) Bundling with CDK Node Lambda

integrated with CDK

uses esbuild

npm install --save-dev esbuild@0

 

example dependency

npm i uuid @types/uuid

 

services/node-lambda/hello.ts

import {v4} from "uuid";

async function handler(event: any, context: any) {

return {

status: 200,

body: 'hello from lambda!' + v4()

}

}

export {handler}

 

infra/SpaceStack.ts

const helloLambdaNodeJs = new NodejsFunction(this, 'helloLambdaNodeJs', {

entry: join(__dirname, '..', 'services', 'node-lambda', 'hello.ts'),

handler: 'handler'

})

 


(26)Webpack intro

> skipped

(27)Webpack setup

> skipped