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

How best to upgrade Lambda functions from Node 12 to Node 16?

Open PeteDuncanson opened this issue 2 years ago • 18 comments

Before opening, please confirm:

  • [X] I have installed the latest version of the Amplify CLI (see above), and confirmed that the issue still persists.
  • [X] I have searched for duplicate or closed issues.
  • [X] I have read the guide for submitting bug reports.
  • [X] I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.
  • [X] I have removed any sensitive information from my code snippets and submission.

How did you install the Amplify CLI?

yarn

If applicable, what version of Node.js are you using?

No response

Amplify CLI Version

9.2.1

What operating system are you using?

Windows

Did you make any manual changes to the cloud resources managed by Amplify? Please describe the changes made.

No. I'm trying to avoid making any when upgrading to Node 16 in all my Lambda's. I'm worried any changes will just get over-written when I next deploy anyway hence asking here :)

Amplify Categories

function

Amplify Commands

push

Describe the bug

Got an email this week reminding me that I'm still running some early functions on Node 12, this is going to be retired in November so I need to change the environment that they are running on to be Node 16.

I used this lovely little one line in a console to get a list of all the functions in question (taken from the email, thank you):

aws lambda list-functions --function-version ALL --region us-east-1 --output text --query "Functions[?Runtime=='nodejs12.x'].FunctionArn"

Obvs change the region to match the one you are using.

I found some older docs on how to do this upgrade from Node 8 to Node 10 (https://docs.amplify.aws/cli/migration/lambda-node-version-update/) but we don't seem to have an updated version for Node 12 to Node 16. Is there going to be one? Could we get one created?

Expected behavior

The docs at https://docs.amplify.aws/cli/migration/lambda-node-version-update/ include a section on how to update from Node 12 to Node 16 in a manner that Amplify won't over write any changes on the next deploy.

I could try to follow the Node 8 upgrade path but not sure if anything differs (its not something I do regularly).

Reproduction steps

Well, not sure really, have a Lambda setup to run with Node 12 and try to upgrade it?

GraphQL schema(s)

# Put schemas below this line


Project Identifier

No response

Log output

# Put your logs below this line


Additional information

No response

PeteDuncanson avatar Aug 16 '22 13:08 PeteDuncanson

@PeteDuncanson Even I got an email this week about the deprecation of node.js 12.x version for Lambda. I created amplify environment using terraform two weeks ago.

kvenkata986 avatar Aug 16 '22 16:08 kvenkata986

The problem is that even the latest version of Amplify CLI creates a function with node 12. See #10887

dral3x avatar Aug 17 '22 14:08 dral3x

came here with same concern which described in comments above

myroslavmail avatar Aug 19 '22 13:08 myroslavmail

Note for fix: it would be nice to have a amplify migrate function command to auto-migrate runtimes without the need for a string replace in the function's CloudFormation template

josefaidt avatar Aug 20 '22 19:08 josefaidt

Related - https://github.com/aws-amplify/amplify-adminui/issues/639

hein-j avatar Aug 22 '22 17:08 hein-j

Hey folks, as a manual workaround we can manually replace nodejs12.x with nodejs14.x or nodejs16.x in the functions' CloudFormation templates.

// amplify/backend/function/myfunction/myfunction-cloudformation-template.json
- "Runtime": "nodejs12.x",
+ "Runtime": "nodejs16.x",

josefaidt avatar Sep 19 '22 21:09 josefaidt

@josefaidt assume we will have to do this for all environments? So make the change and push then do a amplify env checkout <envname> and then make the change again and push?

PeteDuncanson avatar Sep 20 '22 13:09 PeteDuncanson

Yes, additionally, you should manual change few lambdas that were created with amplify, those functions starts with: "amplify-login-(verify/create/custom/define)-(ID)"

gzimbron avatar Sep 20 '22 14:09 gzimbron

how do you manually change these lambda functions: "amplify-login-(verify/create/custom/define)-(ID)"? I don't see any Cloudformation templates for them.

joshpopelka20 avatar Sep 20 '22 14:09 joshpopelka20

how do you manually change these lambda functions: "amplify-login-(verify/create/custom/define)-(ID)"? I don't see any Cloudformation templates for them.

Directly in AWs Console panel.

Those functions stay although you deleted the amplify app, normally 4 for each amplify app are created. I mean i have 5 amplify apps created, and i updated 32 lambdas from 12.x to 16.x manually, but i can't identify to wich app it belongs to

Add this filter in lambda to find them CleanShot 2022-09-20 at 09 13 01@2x

gzimbron avatar Sep 20 '22 14:09 gzimbron

@pptavozl Hello! So there'll be no problem with just changing the node version from every amplify generated lambda to 16.x, right?

juaiglesias avatar Sep 22 '22 18:09 juaiglesias

@juaiglesias I did this last week follow the steps mentioned above and no problems reported so far. Seems safe to do.

PeteDuncanson avatar Sep 26 '22 13:09 PeteDuncanson

I will proceed then. Thanks, @PeteDuncanson !

juaiglesias avatar Oct 03 '22 19:10 juaiglesias

how do you manually change these lambda functions: "amplify-login-(verify/create/custom/define)-(ID)"? I don't see any Cloudformation templates for them.

Just wanted to add in case it wasn't obvious: if you want to update the runtime (not just delete stale 'amplify-login-*' lambdas), documentation is here

eettaa avatar Jan 03 '23 04:01 eettaa

When I attempt to edit the cloudformation templates to replace nodejs12.x with anything else, something during amplify push overwrites my changes and sets them back to nodejs12.x. Anyone else experience this or have a way around it? No matter what I do, three resources always revert back to nodejs12.x during the push: UserPoolClientLambda, HostedUICustomResource, HostedUIProvidersCustomResource

natoco avatar Aug 01 '23 03:08 natoco

Little update on this. Got an email saying I now need to repeat this to get from node14 to node16 so followed the same steps and they worked just fine.

One word of warning though, if you've manually edited the memory size or timeouts etc in the AWS console then this will delete those changes. Seems if you manaully edit the cloudformation templates that seems to overrule your manual settings in the console. To stop this happening again we've gone back and added in the memory and timeout settings which go into the same place as the node setting in each template so nice to do it all in one hit. Details here should help: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-function.html

PeteDuncanson avatar Aug 31 '23 10:08 PeteDuncanson

@PeteDuncanson

Little update on this. Got an email saying I now need to repeat this to get from node14 to node16 so followed the same steps and they worked just fine.

One word of warning though, if you've manually edited the memory size or timeouts etc in the AWS console then this will delete those changes. Seems if you manaully edit the cloudformation templates that seems to overrule your manual settings in the console. To stop this happening again we've gone back and added in the memory and timeout settings which go into the same place as the node setting in each template so nice to do it all in one hit. Details here should help: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-function.html

Which steps above did you follow? The ones listed in the docs ? https://docs.amplify.aws/cli/migration/lambda-node-version-update/ or one of the other comments?

any help would be much appreciated!!

legalcasecatalyst avatar Sep 01 '23 03:09 legalcasecatalyst

@legalcasecatalyst start here and work down :) https://github.com/aws-amplify/amplify-cli/issues/10894#issuecomment-1251564540

PeteDuncanson avatar Sep 28 '23 10:09 PeteDuncanson