1

Given the user's cognito-Id is there a way to get the custom attributes associated with them in lambda?

The attribute I am referring to is timezone, since time is saved in unix in database, when it is converted for the user to see, I would need to know their timezone.

Extra text as question did not meet quality standard

WeCanBeFriends
  • 641
  • 1
  • 10
  • 23
  • Related: https://stackoverflow.com/questions/37963906/how-to-get-user-attributes-username-email-etc-using-cognito-identity-id – jarmod Mar 03 '18 at 17:59

1 Answers1

3

If you're using API Gateway with Cognito authorizer (and Lambda proxy integration), you can get the user's custom attributes via requestContext, for example event.requestContext.authorizer.claims["custom:timezone"].

(By the way, Cognito provides a standard attribute called zoneinfo.)

If you're not using Cognito authorizer, you can get the user's custom attributes using AdminGetUser by providing the username and user pool ID. In this case, your Lambda function's IAM role needs to have an allow rule to execute the "cognito-idp:AdminGetUser" action against your user pool resource.

Khalid T.
  • 10,039
  • 5
  • 45
  • 53