Amplify-cli: Generated Lambda trigger doesn't execute properly (index.handler is undefined or not exported)

Created on 9 Apr 2020  路  2Comments  路  Source: aws-amplify/amplify-cli

Describe the bug
I added a Pre Token Generation Lambda trigger by running the amplify update auth command. I successfully pushed this change to the cloud, but sign in for my app no longer works. I inspected the logs of the newly added trigger and found this error:

{
    "errorType": "Runtime.HandlerNotFound",
    "errorMessage": "index.handler is undefined or not exported",
    "stack": [
        "Runtime.HandlerNotFound: index.handler is undefined or not exported",
        "    at Object.module.exports.load (/var/runtime/UserFunction.js:144:11)",
        "    at Object.<anonymous> (/var/runtime/index.js:45:30)",
        "    at Module._compile (internal/modules/cjs/loader.js:778:30)",
        "    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)",
        "    at Module.load (internal/modules/cjs/loader.js:653:32)",
        "    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)",
        "    at Function.Module._load (internal/modules/cjs/loader.js:585:3)",
        "    at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)",
        "    at startup (internal/bootstrap/node.js:283:19)",
        "    at bootstrapNodeJSCore (internal/bootstrap/node.js:623:3)"
    ]
}

I think it's caused by the fact that only the src/custom.js or in this case src/alter-claims.js gets added to the zip build of the Lambda function. The index.js (which contains the handler function that iterates over the different modules) is never uploaded to the cloud.

When executing the Lambda it can't find index.handler since it never got uploaded.

Amplify CLI Version
4.18.0

To Reproduce

  • Add Pre Token Generation Lambda trigger with the Amplify CLI by using amplify update auth
  • Attempt to log into your app
  • Check CloudWatch logs for your PreTokenGeneration Lambda function

Expected behavior
I expect the Lambda trigger generated by amplify to execute properly.

Desktop:

  • OS: macOS Catalina
  • Node Version. v13.5.0
auth bug functions

Most helpful comment

@mdoesburg does manually moving the index.js file to the source folder and doing a push fix the problem?

All 2 comments

@mdoesburg does manually moving the index.js file to the source folder and doing a push fix the problem?

@mdoesburg does manually moving the index.js file to the source folder and doing a push fix the problem?

@nikhname Thanks for the fix! I can confirm this works now.

Was this page helpful?
0 / 5 - 0 ratings