# How do I get a Cognito user from Lambda authorisation event header using the @aws-sdk npm packages?

**URL:** <https://awshq.com/t/how-do-i-get-a-cognito-user-from-lambda-authorisation-event-header-using-the-aws-sdk-npm-packages/16233>\
**Category:** Security & IAM\
**Tags:** lambda, cognito\
**Created:** [February 5, 2023, 12:21pm UTC](https://awshq.com/t/how-do-i-get-a-cognito-user-from-lambda-authorisation-event-header-using-the-aws-sdk-npm-packages/16233 "2023-02-05T12:21:08Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mr-Silly-Bear](https://awshq.com/letter_avatar_proxy/v4/letter/m/43a26b/32.png) [@Mr-Silly-Bear](https://awshq.com/u/Mr-Silly-Bear)\
**Post date:** [February 5, 2023, 12:21pm UTC](https://awshq.com/t/how-do-i-get-a-cognito-user-from-lambda-authorisation-event-header-using-the-aws-sdk-npm-packages/16233/1 "2023-02-05T12:21:08Z")

</div>

I’m trying to work out how I can use the authorisation header in a Lambda event object to get the user details. I’m using the @aws-sdk/client-cognito-identity package, but it isn’t clear how to do this in fron the documentation.

Is this possible?

Edit: for anyone looking at the same problem the solution I’ve used is from here [Decode and verify the signature of a Cognito JSON Web Token | AWS re:Post](https://aws.amazon.com/premiumsupport/knowledge-center/decode-verify-cognito-json-token/)

* * *

**Related discussions:**

- [AWS Cognito vs Authentik/Self hosted options for a multi-tenant auth solution.](https://awshq.com/t/aws-cognito-vs-authentik-self-hosted-options-for-a-multi-tenant-auth-solution/21135)
- [WIP student project: multi-account AWS “Secure Data Hub” (would love feedback!)](https://awshq.com/t/wip-student-project-multi-account-aws-secure-data-hub-would-love-feedback/20822)
- [Cognito now supports TOTP reset via admin API for users](https://awshq.com/t/cognito-now-supports-totp-reset-via-admin-api-for-users/21549)
- [Using Cognito vs Auth0?](https://awshq.com/t/using-cognito-vs-auth0/11232)
- [Cognito Managed Login](https://awshq.com/t/cognito-managed-login/20041)

---

<div class="post-metadata">

**Author:** ![Basile001](https://awshq.com/letter_avatar_proxy/v4/letter/b/9de053/32.png) [@Basile001](https://awshq.com/u/Basile001)\
**Post date:** [February 5, 2023, 1:58pm UTC](https://awshq.com/t/how-do-i-get-a-cognito-user-from-lambda-authorisation-event-header-using-the-aws-sdk-npm-packages/16233/2 "2023-02-05T13:58:53Z")

</div>

You might look to this example : [https://github.com/Basile001/another-aws-example/blob/master/back/src/handlers/note/create-note.ts](https://github.com/Basile001/another-aws-example/blob/master/back/src/handlers/note/create-note.ts)

In this project you have all information to build a serverless app

---

<div class="post-metadata">

**Author:** ![Independent\_Let\_6034](https://awshq.com/letter_avatar_proxy/v4/letter/i/8baadc/32.png) [@Independent\_Let\_6034](https://awshq.com/u/Independent_Let_6034)\
**Post date:** [February 5, 2023, 3:27pm UTC](https://awshq.com/t/how-do-i-get-a-cognito-user-from-lambda-authorisation-event-header-using-the-aws-sdk-npm-packages/16233/3 "2023-02-05T15:27:10Z")

</div>

Depending on the user details you mean they would be included within the claims header - assuming you’re using the id token

---

<div class="post-metadata">

**Author:** ![NFTrot](https://awshq.com/letter_avatar_proxy/v4/letter/n/3be4f8/32.png) [@NFTrot](https://awshq.com/u/NFTrot)\
**Post date:** [February 5, 2023, 4:05pm UTC](https://awshq.com/t/how-do-i-get-a-cognito-user-from-lambda-authorisation-event-header-using-the-aws-sdk-npm-packages/16233/4 "2023-02-05T16:05:26Z")

</div>

You can decode the JWT and its all in there. You don’t need any fancy libraries, its just base64.

---

<div class="post-metadata">

**Author:** ![warchild4l](https://awshq.com/letter_avatar_proxy/v4/letter/w/a9adbd/32.png) [@warchild4l](https://awshq.com/u/warchild4l)\
**Post date:** [February 5, 2023, 6:22pm UTC](https://awshq.com/t/how-do-i-get-a-cognito-user-from-lambda-authorisation-event-header-using-the-aws-sdk-npm-packages/16233/5 "2023-02-05T18:22:34Z")

</div>

> [@NFTrot](#):
>
> You can decode the JWT and its all in there. You don’t need any fancy libraries, its just base64.

To follow up on this, if OP has set up API Gateway, they can setup authorizer and get already decoded claims in the event object as well.

---

<div class="post-metadata">

**Author:** ![no\_career](https://awshq.com/letter_avatar_proxy/v4/letter/n/8491ac/32.png) [@no\_career](https://awshq.com/u/no_career)\
**Post date:** [February 5, 2023, 10:31pm UTC](https://awshq.com/t/how-do-i-get-a-cognito-user-from-lambda-authorisation-event-header-using-the-aws-sdk-npm-packages/16233/6 "2023-02-05T22:31:48Z")

</div>

I asked my bot, here’s what it said:

> You can use the AWS SDK for JavaScript to get a Cognito user from the Lambda authorization event header. First, you need to import the AWS \> SDK into your Lambda function. Then, you can use the getCognitoIdentity() method to get the Cognito user from the event header. The  
> getCognitoIdentity() method takes the event object as an argument and returns an object containing the Cognito identity ID and the pool ID.

---

<div class="post-metadata">

**Author:** ![Mr-Silly-Bear](https://awshq.com/letter_avatar_proxy/v4/letter/m/43a26b/32.png) [@Mr-Silly-Bear](https://awshq.com/u/Mr-Silly-Bear)\
**Post date:** [February 12, 2023, 9:33am UTC](https://awshq.com/t/how-do-i-get-a-cognito-user-from-lambda-authorisation-event-header-using-the-aws-sdk-npm-packages/16233/7 "2023-02-12T09:33:25Z")

</div>

> [@NFTrot](#):
>
> You can decode the JWT and its all in there. You don’t need any fancy libraries, its just base64.

Thanks for pointing me in the right direction. Looks like this is what I’m after [https://aws.amazon.com/premiumsupport/knowledge-center/decode-verify-cognito-json-token/](https://aws.amazon.com/premiumsupport/knowledge-center/decode-verify-cognito-json-token/)
