amplify-hosting icon indicating copy to clipboard operation
amplify-hosting copied to clipboard

What is the correct way to customize NextJS lambda@edge

Open CauanCabral opened this issue 2 years ago • 8 comments

Please describe which feature you have a question about?

Amplify to deploy NextJS with SSR, SSG and api's.

Provide additional details

Amplify build the NextJS and delivery it using CloudFront.

They create a Lambda for each of api and SSR routes.

Accessing Lambda console, I can see memory, runtime and other configurations for my lambdas. I can even edit any of then. But in next build/deploy, they are all reset to default again.

How am I suppose to configure how much memory, or what version of runtime, or how long lambda should run before timeout? I can't find anything about it on AWS Docs or panel.

What AWS Services are you utilizing?

  • Amplify Console
  • To deploy a Next.js 10 app with SSR, SSG and api

Provide additional details e.g. code snippets

image

CauanCabral avatar Sep 14 '21 18:09 CauanCabral

Also interested in customizing these settings

andrewgadziksonos avatar Sep 20 '21 02:09 andrewgadziksonos

I also want to know

Leejjon avatar Sep 27 '21 09:09 Leejjon

Hi @CauanCabral, @andrewgadziksonos, @Leejjon

Unfortunately these settings are not customizable at the moment. We are rolling out a change in the default values to increase the Lamda@Edge execution timeout from 10 seconds to 30 seconds.

If we were to offer customization of these values, how would you like to specify this configuration? Perhaps as environment variables? Or as part of the amplify.yml file? Or as App Settings in the console? We are evaluating options at the moment.

ferdingler avatar Sep 27 '21 23:09 ferdingler

Hi @ferdingler, I would like to define defaults from Console, but any of alternatives are good enough.

Defining timeout default as 30s is really appreciate move.

How about also update default runtime to node 14.x?

CauanCabral avatar Sep 27 '21 23:09 CauanCabral

I am getting same 10 sec timeout for regeneration lambda, any way to update it ?

yogeshydvme avatar Oct 14 '21 21:10 yogeshydvme

How about updating the node version of the lambda edge runtime ? We would like to run the node 16 runtime and it seems to be stuck on an older version ?

deangenovski avatar Aug 02 '22 07:08 deangenovski

I am facing the same issue, we would like to configure the runtime of the lamda edge.

smilhas avatar Aug 04 '22 13:08 smilhas

Same here. I don't care if I can customize it via environment variables, or as part of the amplify.yml file, or as App Settings in the console. As long as I can change it. ;)

pitgrap avatar Aug 10 '22 15:08 pitgrap

It kind of sounds like these lambda settings should be in infra as code. I would expect them to be in the amplify branch cloudformation and cdk.

Leejjon avatar Jan 02 '23 11:01 Leejjon

@CauanCabral are you still able to see the Lambdas deployed for your NextJS app?

I've deployed NextJS v12 and v13 and I can't find anything Lambda resources that might be used for API or SSR. I've looked in CloudFormation and Lambda consoles but nothing. 🤔 I'm using Amplify v10.6.2.

williamrjribeiro avatar Jan 24 '23 11:01 williamrjribeiro

@williamrjribeiro

That's the way the new Amplify platform WEB_COMPUTE works (they manage all resources internally).

Only the old platform WEB_DYNAMIC have CloudFront and associated Lambdas visible.

I don't know if you can choose the WEB_DYNAMIC for new projects.

You can see more about the migration in docs: https://docs.aws.amazon.com/amplify/latest/userguide/update-app-nextjs-version.html

CauanCabral avatar Jan 24 '23 11:01 CauanCabral

Thanks a lot for the docs link @CauanCabral ! I had missed it and it was quite informative.

williamrjribeiro avatar Jan 24 '23 14:01 williamrjribeiro

Hello everyone (@ferdingler, @CauanCabral, @williamrjribeiro)!

I'm very new to using AWS Amplify, having switched over from Vercel.

I would like to know whether and how one can:

  • ~~expose the environment variables to the Lambda handler for API routes~~ (I had to move the .env file inside the appRoot for my monorepo setup)
  • customize the timeout for the Lambda handlers for the API routes

Any help is really appreciated! Thank you for your time!

I'm so close to having everything work, this is the only blocker 😄

kelvindecosta avatar Jul 19 '23 16:07 kelvindecosta

@kelvindecosta I'm sorry but I also don't know. 😓

williamrjribeiro avatar Jul 24 '23 17:07 williamrjribeiro