Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid lambda function output : Invalid JSON #2735

Closed
danhumphrey opened this issue Nov 14, 2019 · 4 comments
Closed

Invalid lambda function output : Invalid JSON #2735

danhumphrey opened this issue Nov 14, 2019 · 4 comments

Comments

@danhumphrey
Copy link

danhumphrey commented Nov 14, 2019

Describe the bug

I'm using amplify auth and have a working model which uses a post confirmation hook with the following functionality:

  • add user to group
  • custom (added later)

My custom function is now adding the user to DynamoDB and doing some additional stuff so I no longer need to make use of the add user to group so I am using amplify update auth to remove this.

After I amplify push and signup up and verify a user, I see the error 'Invalid lambda function output : Invalid JSON'

There are no errors reported in CloudWatch and my custom function has completed successfully. Also, the user is actually confirmed in the user pool.

Additionally, but not a high priority is that the PostConformation lambda still has the GROUP environment variable set after removing the add user to group functionality

Amplify CLI Version
3.17

To Reproduce

1.
amplify update auth
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 AW
S 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) No
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? Yes
Enter the minimum password length for this User Pool: 8
Select the password character requirements for your userpool: (Press to select, to toggle all,
to invert selection)Requires Lowercase, Requires Uppercase, Requires Numbers, Requires Symbols
Specify the app's refresh token expiration period (in days): 15
Do you want to specify the user attributes this app can read and write? Yes
Specify read attributes: (Press to select,
to toggle all, to invert selection)Email
Specify write attributes: (Press to select,
to toggle all, to invert selection)
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 (Press to select,
to toggle all, to invert se
lection)Post Confirmation
? What functionality do you want to use for Post Confirmation (Press to select,
to toggle all, t
o invert selection)Create your own module

2. sign up and verify a user

Expected behavior

Sign up and conformation process completes successfully

Desktop (please complete the following information):

irrelevant I assume but Mac OS Catalina

@danhumphrey
Copy link
Author

it appears that I have to use the callback(null) call to prevent this, although this didn't cause an issue until I removed the add to group functionality.

@yogeshwar607
Copy link

In case you are using async function , then callback(null,event) does not work out , have a look at this reference for more details - https://docs.aws.amazon.com/lambda/latest/dg/nodejs-handler.html

@ctjlewis
Copy link
Contributor

ctjlewis commented Apr 25, 2021

@danhumphrey This actually seems to be an active bug, and using the "add user to group" functionality with Amplify Auth (advanced settings) actually causes the Lambda to fail with "Invalid lambda function output : Invalid JSON".

See also: #4341. A template generated by Amplify CLI uses async, which causes the error seen here.

ctjlewis added a commit to ctjlewis/amplify-cli that referenced this issue Apr 25, 2021
/**
 * For some reason, naively returning a value / Promise or throwing an error
 * will not work as it is specified in the Lambda docs:
 * @see https://docs.aws.amazon.com/lambda/latest/dg/nodejs-handler.html
 *
 * This causes an "Invalid JSON" error which can, so far, only be worked
 * around by resolving with deprecated non-async `callback`:
 * @see aws-amplify#2735
 * @see aws-amplify#4341
 * @see aws-amplify#7179
 */
@github-actions
Copy link

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 25, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants