Skip to content
This repository was archived by the owner on Jan 28, 2025. It is now read-only.

Allow to set custom handler #2409

Merged
merged 1 commit into from
Apr 20, 2022
Merged

Conversation

nalejandroveron
Copy link
Contributor

@nalejandroveron nalejandroveron commented Mar 16, 2022

When using Builder from @sls-next/lambda-at-edge there's a really useful functionality to add an extra handler (in case you want to call callbackWaitsForEmptyEventLoop = false, set any tracer or establish a DB connection, really useful!).

But unfortunately it's kinda useless on CDK because the default handler is stuck at index.handler, this PR solves that, so you can do the following:

export function MyStack(scope: Construct, id: string, props?: cdk.StackProps) {
  /** other things */

  new NextJSLambdaEdge(stack, `${id}-next`, {
    memory: 1536,
    runtime: Runtime.NODEJS_14_X,
    handler: 'handler.handler' // <------ We could replace the default handler and make use of the one we provided to "build"
  })
}

const builder = new Builder('.', './build', {
  args: ['build'], 
  handler: 'handler.js', // <------ We told builder we want this handler, but we should tell the lambda too ☝🏻
})

builder
  .build()
  .then(() => {
    const app = new cdk.App()
    MyStack(app, `example-stack`)
  })
  .catch((e) => {
    console.log(e)
    process.exit(1)
  })

@slsnextbot
Copy link
Collaborator

Handler Size Report

No changes to handler sizes.

Base Handler Sizes (kB) (commit e079765)

{
    "Lambda": {
        "Default Lambda": {
            "Standard": 1578,
            "Minified": 692
        },
        "Image Lambda": {
            "Standard": 1542,
            "Minified": 830
        }
    },
    "Lambda@Edge": {
        "Default Lambda": {
            "Standard": 1588,
            "Minified": 698
        },
        "Default Lambda V2": {
            "Standard": 1580,
            "Minified": 694
        },
        "API Lambda": {
            "Standard": 634,
            "Minified": 318
        },
        "Image Lambda": {
            "Standard": 1550,
            "Minified": 835
        },
        "Regeneration Lambda": {
            "Standard": 1233,
            "Minified": 566
        },
        "Regeneration Lambda V2": {
            "Standard": 1307,
            "Minified": 596
        }
    }
}

New Handler Sizes (kB) (commit 0221d1d)

{
    "Lambda": {
        "Default Lambda": {
            "Standard": 1578,
            "Minified": 692
        },
        "Image Lambda": {
            "Standard": 1542,
            "Minified": 830
        }
    },
    "Lambda@Edge": {
        "Default Lambda": {
            "Standard": 1588,
            "Minified": 698
        },
        "Default Lambda V2": {
            "Standard": 1580,
            "Minified": 694
        },
        "API Lambda": {
            "Standard": 634,
            "Minified": 318
        },
        "Image Lambda": {
            "Standard": 1550,
            "Minified": 835
        },
        "Regeneration Lambda": {
            "Standard": 1233,
            "Minified": 566
        },
        "Regeneration Lambda V2": {
            "Standard": 1307,
            "Minified": 596
        }
    }
}

@codecov
Copy link

codecov bot commented Mar 16, 2022

Codecov Report

Merging #2409 (0221d1d) into master (e079765) will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##           master    #2409   +/-   ##
=======================================
  Coverage   83.59%   83.59%           
=======================================
  Files         102      102           
  Lines        3706     3707    +1     
  Branches     1188     1189    +1     
=======================================
+ Hits         3098     3099    +1     
  Misses        596      596           
  Partials       12       12           
Impacted Files Coverage Δ
...rless-components/nextjs-cdk-construct/src/index.ts 93.96% <100.00%> (+0.05%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e079765...0221d1d. Read the comment docs.

@dphang dphang merged commit f5c33ac into serverless-nextjs:master Apr 20, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants