aws-amplify / amplify-cli

The AWS Amplify CLI is a toolchain for simplifying serverless web and mobile development.
Apache License 2.0
2.82k stars 820 forks source link

Amplify Auth creates lambda using deprecated node6.10 #1305

Closed paddlefish closed 5 years ago

paddlefish commented 5 years ago

Describe the bug AWS is deprecating Node 6.10 Within a few weeks it will no longer be possible to deploy lambdas using Node6.10. Amplify CLI Auth creates a Node6.10 Lambda.

Here's the message from AWS that arrived in my inbox because I used amplify add auth on my account:

Hello,

Your AWS Account currently has one or more Lambda functions or applications published to the AWS Serverless Application Repository using the node.js 6.10 runtime. The Node Foundation has previously published that node.js 6.x "Boron" will be declared End-of-Life (EOL) on April 2019 [1], and will stop receiving bug fixes, security updates, or performance improvements. Per the AWS Lambda runtime support policy [2], language runtimes that have reached their EOL are deprecated in AWS Lambda.

Invokes for functions configured to run on node.js 6.10 will continue to work normally, however the ability to create new Lambda functions configured to use the node.js 6.10 runtime will be disabled on April 30 2019. Code updates to existing functions using node.js 6.10 will be disabled 30 days later on May 30 2019.

We encourage you to update your node.js 6.10 Lambda functions and applications published to the AWS Serverless Application Repository to a newer version of the Node runtime (node.js 8.10) so that you continue to benefit from important security, performance, and functionality enhancements offered by more recent releases. If you have already updated to node.js 8.10 version then no further action is required. The newer node.js 8.10 version has improved ECMAScript support, along with other language and API improvements. The AWS Lambda programming model [3] for node.js 8.10 maintains backwards compatibility with previous versions to simplify portability. We recommend that you test your Lambda function to validate its behavior on the newer version of Node.js.

Should you have any questions or concerns please contact AWS Support [4].

[1] Node Foundation’s announcement of EOL: https://nodejs.org/en/blog/release/v6.9.0/
[2] AWS Lambda runtime support policy: https://docs.aws.amazon.com/lambda/latest/dg/runtime-support-policy.html
[3] https://aws.amazon.com/blogs/compute/node-js-8-10-runtime-now-available-in-aws-lambda/
[4] AWS Support: https://aws.amazon.com/support

Sincerely,
Amazon Web Services

To Reproduce Steps to reproduce the behavior:

  1. Amplify add auth
  2. Go to lambdas on the aws console
  3. Look at the 'runtime column'
  4. Nodejs6.10

Expected behavior Nodejs8.10

Screenshots If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information): Darwin Kernel Version 18.5.0: Mon Mar 11 20:40:32 PDT 2019; root:xnu-4903.251.3~3/RELEASE_X86_64

Smartphone (please complete the following information): n/a

Additional context

The lambda is created by the cloud formation template packages/amplify-category-analytics/provider-utils/awscloudformation/cloudformation-templates/pinpoint-cloudformation-template.json

Note: There is also another template packages/amplify-category-interactions/provider-utils/awscloudformation/cloudformation-templates/lex-cloudformation-template.json.ejs but I don't use that so someone else can write up that bug.

Sample code

Here's a snippet of pinpoint-cloudformation-template.json

Screen Shot 2019-04-18 at 9 13 04 AM
        "PinpointFunction": {
            "Type": "AWS::Lambda::Function",
            "Condition": "ShouldCreatePinpointApp",
            "Properties": {
                "Code": {
                    "ZipFile": {
                        "Fn::Join": [
                            "\n",
                            [
                                "const response = require('cfn-response');",
                                "const aws = require('aws-sdk');",
                                "exports.handler = function(event, context) {",
                                "    if (event.RequestType == 'Delete') {",
                                "        response.send(event, context, response.SUCCESS);",
                                "        return;",
                                "    }",
                                "    if (event.RequestType == 'Update') {",
                                "        response.send(event, context, response.SUCCESS);",
                                "        return;",
                                "    }",
                                "    if (event.RequestType == 'Create') {",
                                "       const appName = event.ResourceProperties.appName;",
                                "       let responseData = {};",
                                "       const params = {",
                                "           CreateApplicationRequest: {",
                                "               Name: appName",
                                "           }",
                                "       };",
                                "       const pinpoint = new aws.Pinpoint({ apiVersion: '2016-12-01', region: event.ResourceProperties.region });",
                                "       return pinpoint.createApp(params).promise()",
                                "           .then((res) => {",
                                "               responseData = res.ApplicationResponse;",
                                "               response.send(event, context, response.SUCCESS, responseData);",
                                "           }).catch((err) => {",
                                "               console.log(err.stack);",
                                "               responseData = {Error: err};",
                                "               response.send(event, context, response.FAILED, responseData);",
                                "               throw err;",
                                "           });",
                                "    }",
                                "};"
                            ]
                        ]
                    }
                },
                "Handler": "index.handler",
                "Runtime": "nodejs6.10",
                "Timeout": "300",
                "Role": {
                    "Fn::GetAtt": [
                        "LambdaExecutionRole",
                        "Arn"
                    ]
                }
            }
        },

You can turn on the debug mode to provide more info for us by setting window.LOG_LEVEL = 'DEBUG'; in your app.

UnleashedMind commented 5 years ago

Thanks @paddlefish for letting us know. We've already updated the codebase for this and the PR is currently pending review. https://github.com/aws-amplify/amplify-cli/pull/1267

yuyokk commented 5 years ago

@UnleashedMind will you please clarify one point here. After fix is merged, will updating amplify-cli be enough for existing project (just push the codebase with updated cli version) to update the runtime Node? Or we need to manually update cloudformation templates for existing projects? Thanks.

ghost commented 5 years ago

I am hoping that whether with an automatic upgrade of a project from 6.10 to 8.10, or with the manual updating of the template, that any project upgrade will only effect the node version for the Lambda and not effect the Cognito User Pool or Federated Identity that might be attached to the auth service.

Can this also be confirmed? Thank you.

UnleashedMind commented 5 years ago

@yuyokk Thanks for bringing it up. We'll also add to our document about this. For existing project, if you plan to update anything related to lambda, such as resources from the Amplify CLI Function category, or custom resources backed by Lambda function (e.g. analytics, interactions, etc. ), then you will have to manually update the node version in the CloudFormation template.

UnleashedMind commented 5 years ago

@leantide Auth also uses custom resources backed by Lambda function. So this update shouldn't affect resources already created for the auth category. But if you need to update them (if you created auth before v1.6.x release), then you will need to manually update the node version in the Auth Cloudformation template.

kaustavghosh06 commented 5 years ago

We upgraded our default Cloudformation tempaltes to NodeJS 8.10 with the latest version of the CLI. Here's a quick migration guide out here if you're using an older version/template in your project - https://aws-amplify.github.io/docs/cli/lambda-node-version-update

github-actions[bot] commented 3 years ago

This issue has been automatically locked since there hasn't been any recent activity after it was closed. Please open a new issue for related bugs.

Looking for a help forum? We recommend joining the Amplify Community Discord server *-help channels for those types of questions.