Amplify-cli: Post confirmation trigger to add-to-group throws "Cannot find module 'add-to-group'"

Created on 27 Dec 2019  路  6Comments  路  Source: aws-amplify/amplify-cli

Describe the bug
After updating to amplify cli version 4.9.0, I walked through the update auth flow. I created a trigger to add users to group, post-confirmation. When the lambda is triggered, the following error can be observed in cloudwatch:

{
    "errorType": "Error",
    "errorMessage": "Cannot find module 'add-to-group'",
    "code": "MODULE_NOT_FOUND",
    "stack": [
        "Error: Cannot find module 'add-to-group'",
        "    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)",
        "    at Function.Module._load (internal/modules/cjs/loader.js:562:25)",
        "    at Module.require (internal/modules/cjs/loader.js:692:17)",
        "    at require (internal/modules/cjs/helpers.js:25:18)",
        "    at Runtime.exports.handler (/var/task/index.js:10:25)",
        "    at Runtime.handleOnce (/var/runtime/Runtime.js:66:25)"
    ]
}

Amplify CLI Version
4.9.0

To Reproduce
Update auth to add the post-confirmation trigger that adds users to a user pool group. Push your backend. I am using the console to track my branches, so I build via the console as well. When the frontend build is complete, create an account and confirm the account. The post-confirmation trigger should fail with the error: Cannot find module 'add-to-group'

Expected behavior
Confirmed user should be added to the group.

Screenshots
N/A

Desktop (please complete the following information):

  • Build env: AWS Amplify Console branch build
  • Node Version: 10.9 is the runtime of the lambda

Additional context
I am using amplify console to build. I explicitly specify 4.9.0 as the CLI version. I suspect this is related to the migration from node 8.x to 10.x, which perhaps introduced a breaking change.

@auth bug pending-release

Most helpful comment

@dsr771 Here鈥檚 the documentation for the update - https://aws-amplify.github.io/docs/cli/lambda-node-version-update

All 6 comments

These releases are pretty risky and dangerous. I'm attempting to roll back to 4.7.0.

Rolling back to 4.7.0 introduces https://github.com/aws-amplify/amplify-cli/issues/2458

I had to go to 4.9.0, remove the post-confirmation lambda, then revert back to 4.7.0

Now I'm testing if this even worked...

馃槩

I fixed by prefixing the modules with "./"

/*
  this file will loop through all js modules which are uploaded to the lambda resource,
  provided that the file names (without extension) are included in the "MODULES" env variable.
  "MODULES" is a comma-delimmited string.
*/

exports.handler = (event, context, callback) => {
  const modules = process.env.MODULES.split(',');
  for (let i = 0; i < modules.length; i += 1) {
    const { handler } = require('./' + modules[i]);
    handler(event, context, callback);
  }
};

I updated the amplify cli to 4.9 to resolve a backend build fail issue last night. amplify cli prompted me to update the node functions to the new version. I was able to build successfully after this. I also used the 'amplify push' to update everything.

However, this appear to have broken the lambda functions for auth.
Trying to create a new login results in : "CustomMessage failed with error Cannot find module 'verification-link'.
"
Trying to reset a password also fails with the same message.

Is there any documentation of steps to take after the node versions are updated?

Thanks in advance.

I updated the handler with "require('./' + modules[i]);" as mentioned above and it is working now.

p.s., my user is properly added to the user pools group.

@dsr771 Here鈥檚 the documentation for the update - https://aws-amplify.github.io/docs/cli/lambda-node-version-update

Was this page helpful?
0 / 5 - 0 ratings