question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error running server-side within Lambda

See original GitHub issue

Describe the bug I’m trying to use Amplify server-side within Lambda in order to de-couple the Cognito token & session management from our clients. If I run my Lambda function locally with sam-cli, login is successful. However, it fails when deployed to AWS. I’ve traced the code to the authenticateUser function.

The error message I receive in the Lambda logs seems like the username isn’t being passed into the Cognito call:

"Please provide an `arn`, `name` or `phone` number"  

I have a very basic user pool, email as username and no triggers. Also, my Lambda’s execution role has full access to Cognito.

To Reproduce I tried using the Amplify function:

Auth.signIn({
    username,
    password
  });

as well as using amazon-cognito-identity-js lib directly.

const userPoolData = new CognitoUserPool({
    UserPoolId: process.env.COGNITO_USER_POOL_ID,
    ClientId: process.env.COGNITO_CLIENT_ID
  });
  const userData = {
    Username: username,
    Pool: userPoolData
  };
  const user = new CognitoUser(userData);
  const authDetails = new AuthenticationDetails({
    Username: username,
    Password: password
    // ValidationData: { },
  });

  return new Promise((resolve, reject) => {
    user.authenticateUser(authDetails, {
      onSuccess: resolve,
      onFailure: reject,
    });

Expected behavior I should be able to sign in from a Lambda function that’s deployed to AWS. This works from a local Lambda

Additional context My versions are:

  "amazon-cognito-identity-js": "^3.0.7",
  "aws-amplify": "^1.1.19",
   "aws-sdk": "^2.279.1",

My Amplify config is:

Amplify.configure({
  Auth: {
    identityPoolId: process.env.COGNITO_IDENTITY_POOL_ID,
    region: process.env.COGNITO_REGION,
    userPoolId: process.env.COGNITO_USER_POOL_ID,
    userPoolWebClientId: process.env.COGNITO_CLIENT_ID,
  },
});

I also tried updating the AWS config with my Amplify admin user credentials but no luck

AWS.config.update({
  region: process.env.REGION,
  credentials: new AWS.Credentials({
    accessKeyId: amplifyKeyId,
    secretAccessKey: amplifyAccessKey
  }),
});

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
jkeys-ecg-nmsucommented, Feb 7, 2019

You need to use “USER_PASSWORD_AUTH” authentication type if you want the username and password to actually get sent over the wire. Amplify uses SRP by default.

0reactions
github-actions[bot]commented, Jun 12, 2021

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 or Discussions for those types of questions.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Troubleshoot Lambda 502 and 500 errors - Amazon AWS
First, identify the specific Lambda Invoke API error that you receive. Then, follow the troubleshooting steps listed for that error.
Read more >
3 Common AWS Lambda Errors and Workarounds for Them
3 Common AWS Lambda Errors and Workarounds for Them · 1. Unknown application error occurred. Source: https://imgur.com. Um… · 2. Runtime exited ...
Read more >
Problem with AWS CloudFront and Server Side Rendering ...
As an entry point of the application, I have a CloudFront distribution that splits the backend requests (/api/*) to the EC2 instance, and...
Read more >
Serverless Server Side Rendering with Angular on AWS ...
In this article we will look at how we can enable server side ... it now you will run into an error, as...
Read more >
Socket disconnected before secure TLS connection was ...
The Lambda function will not execute properly if you return early and the dreaded error will absolutely be seen. Ensure that your server...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found