AWS Lambda - Cognito Identifier ID Changes With Same Name

I use AWS Lambda, Cognito, and the Gateway API (hosted with Serverless ) to create an API for my web application.

The user authenticates with Cognito and then performs an authenticated API request (template copied from the tutorial

This is very problematic because I see no other way to uniquely identify the user record in my database associated with the Cognito record.

QUESTIONS: Am I missing something? Is there a better way to do this? Is this expected behavior?

Currently, the API is not actually connected to the database. Since our data structure is still moving and the application is far from live, I developed an API that acts the way it integrates with the database and returns data, but this data is simply stored in a JSON file. I will reproduce part of the corresponding code below, in case this is appropriate.

Lambda example to retrieve the current user:

export function getSelf(event, context, callback) {
  const { cognitoID } = parser(event);

  const requester = cognitoID && users.find(u => u.cognitoID === cognitoID);

  try {
    if (requester) {
      return callback(null, success(prep(requester, 0)));
    } else {
      return authError(callback, `No user found with ID: ${cognitoID}`);
    }
  } catch (error) {
    return uncaughtError(callback, error);
  }
}

This parser is just a utility to get the identifier I want.

A related user entry might look like this:

  {
    cognitoID: 'us-west-2:605249a8-8fc1-40ed-bf89-23bc74ecc232',
    id: 'some-slug',
    email: 'email@whatever.com',
    firstName: 'John',
    lastName: 'Jacob Jingleheimer Schmidt',
    headshot: 'http://fillmurray.com/g/300/300',
    role: 'admin'
  },
+4
source share
1 answer

Cognito JWT. AWS, AWS ( ). Federated Identities. , Cognito User Pools, Federated Identities, AWS AWS. detail.

, , , Federated Identities ( Amazon Cognito), . , , .

0

Source: https://habr.com/ru/post/1687818/


All Articles