Amplify-cli: PostConfirmation failed with error index.handler is undefined or not exported.

Created on 4 Apr 2020  路  6Comments  路  Source: aws-amplify/amplify-cli

Describe the bug

  • amplifyXXXXXXPostConfirmation Lambda index.js and event.js generated in incorrect directory.
  • Error occured when call Auth.confirmSignUp aws-amplify API
PostConfirmation failed with error index.handler is undefined or not exported.

Amplify CLI Version
4.17.2

To Reproduce

  1. amplify auth update
 What do you want to do? 
Walkthrough all the auth configurations
 Select the authentication/authorization services that you want to use: 
User Sign-Up, Sign-In, connected with AWS IAM controls (Enables per-user Storage features for images or other content, Analytics, and more)
 Allow unauthenticated logins? (Provides scoped down permissions that you can control via AWS IAM) 
Yes
 Do you want to enable 3rd party authentication providers in your identity pool?
No
 Do you want to add User Pool Groups? 
No
 Do you want to add an admin queries API? 
No
 Multifactor authentication (MFA) user login options: 
OFF
 Email based user registration/forgot password: 
Enabled (Requires per-user email entry at registration)
 Please specify an email verification subject: 
Your verification code
 Please specify an email verification message: 
Your verification code is {####}
 Do you want to override the default password policy for this User Pool? 
No
 Specify the app's refresh token expiration period (in days): 
30
 Do you want to specify the user attributes this app can read and write? 
No
 Do you want to enable any of the following capabilities? 
 Do you want to use an OAuth flow? 
No
? Do you want to configure Lambda Triggers for Cognito? 
Yes
? Which triggers do you want to enable for Cognito 
Post Confirmation
? What functionality do you want to use for Post Confirmation 
Create your own module
  1. call Auth.signUp aws-amplify API

Expected behavior

  • amplifyXXXXXXPostConfirmation Lambda index.js and event.js generated in src directory.
  • Success call Auth.confirmSignUp aws-amplify API

Screenshots
image

Desktop (please complete the following information):

  • OS: [Ubuntu]
  • Node Version. [v12.14.1]
functions pending-triage

Most helpful comment

@jingxizhang I upgraded to 4.18.1 and it fixed the problem. But I had to do one trick because when I just ran amplify auth update again hoping to just refresh my add to groups function, it didn't fix the file structure. What I had to do is this:

  1. Run amplify auth update
  2. When it asked if I want to generate all those post functions I unselected everything.
  3. After auth update is done it removed my function.
  4. Run amplify auth update again and chose to create add to group function.
  5. Now it generated correct directory and file structure.

Hope this helps.

All 6 comments

Hi same here.

amplify function invoke <function> gives

Error: ENOENT: no such file or directory, open 'amplify/backend/function/apiPostConfirmation/src/event.json'

It seems that the lib is looking for event.json and index.js inside the src directory

EDIT:

If you move the files accordingly to the following

-- add-to-group.js
-- event.json
-- index.js
-- package.json
-- package-lock.json

and alter the index.js function to your needs. For my use case it was like:

exports.handler = (event, context, callback) => {
  const { handler } = require('./add-to-group')
  handler(event, context, callback)
}

Closing as a duplicate of https://github.com/aws-amplify/amplify-cli/issues/3823
This is fixed by version 4.18.0
@regenrek please try amplify mock function <yourFunction> after updating your CLI
Feel free to comment if this doesn't resolve your issue.

Closing as a duplicate of #3823
This is fixed by version 4.18.0
@regenrek please try amplify mock function <yourFunction> after updating your CLI
Feel free to comment if this doesn't resolve your issue.

I don't understand what exactly was fixed in 4.18.0 - local invocation or the original problem that "PostConfirmation failed with error index.handler is undefined or not exported." ?
Could you please clarify? I'm still experiencing this problem with index.handler is undefined with 4.18.0.

Amplify version 4.18.0 does not fix the problem.
I am using amplify version 4.18.0 and I am having the same problem.
All codes (except add-to-group.js) are outside of src directory. If I move the files (index.js, package.json, package-lock.json and node-modules) into the src directory it works. However, if I further update the lambda function by adding the permission to access another DynamoDB I got "RangeError: Maximum call stack size exceeded".

{
"errorType": "RangeError",
"errorMessage": "Maximum call stack size exceeded",
"stack": [
"RangeError: Maximum call stack size exceeded",
" at Object.hasOwnProperty ()",
" at Function.NativeModule.exists (internal/bootstrap/loaders.js:199:33)",
" at Function.NativeModule.nonInternalExists (internal/bootstrap/loaders.js:217:27)",
" at Function.Module._resolveLookupPaths (internal/modules/cjs/loader.js:456:20)",
" at Function.Module._resolveFilename (internal/modules/cjs/loader.js:629:20)",
" 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 exports.handler (/var/task/index.js:10:25)",
" at exports.handler (/var/task/index.js:11:5)"
]
}

@jingxizhang I upgraded to 4.18.1 and it fixed the problem. But I had to do one trick because when I just ran amplify auth update again hoping to just refresh my add to groups function, it didn't fix the file structure. What I had to do is this:

  1. Run amplify auth update
  2. When it asked if I want to generate all those post functions I unselected everything.
  3. After auth update is done it removed my function.
  4. Run amplify auth update again and chose to create add to group function.
  5. Now it generated correct directory and file structure.

Hope this helps.

@spyboost Thank you. I confirm that version 4.18.1 fixes the problem of placing files generated outside of src folder. However, I still get "RangeError: Maximum call stack size exceeded" after I updated the postComfirm lambda function by adding permission to another DynamoDB. I reported it separatedly (#4065).

Was this page helpful?
0 / 5 - 0 ratings