# Anyone have a good modern example of using a cognito user pool authorizer?

**URL:** <https://forum.serverless.com/t/anyone-have-a-good-modern-example-of-using-a-cognito-user-pool-authorizer/3136>\
**Category:** Serverless Framework\
**Created:** [November 16, 2017, 10:45pm UTC](https://forum.serverless.com/t/anyone-have-a-good-modern-example-of-using-a-cognito-user-pool-authorizer/3136 "2017-11-16T22:45:31Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![JulioBarros](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/juliobarros/32/1295_2.png) [@JulioBarros](https://forum.serverless.com/u/JulioBarros)\
**Post date:** [November 16, 2017, 10:45pm UTC](https://forum.serverless.com/t/anyone-have-a-good-modern-example-of-using-a-cognito-user-pool-authorizer/3136/1 "2017-11-16T22:45:31Z")

</div>

I’m an AWS noob and am trying to set up a cognito user pool as an authorizer for my api-gateway lambda.

As far as I can tell the docs talk about about setting up the pool as an event source and I have not found a way to configure api-gateway. I expected it to be something like the cors: true setting where I’d just say authorizer: myPool … but I can’t seem to find an example.

I’ve searched around but strangely have not found exactly what I need. I see the references to aws\_iam, user groups, etc. but am not sure how to get to the user pool.

Does anyone know where in the docs I can find that or of a blog post or something explaining it?

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![bobbiebarker](https://avatars.discourse-cdn.com/v4/letter/b/77aa72/32.png) [@bobbiebarker](https://forum.serverless.com/u/bobbiebarker)\
**Post date:** [December 4, 2017, 2:43am UTC](https://forum.serverless.com/t/anyone-have-a-good-modern-example-of-using-a-cognito-user-pool-authorizer/3136/2 "2017-12-04T02:43:41Z")

</div>

Little delayed in the response, hopefully you’ve figured this out since you posted, but I believe the answer you’re looking for can be found [here](https://serverless.com/framework/docs/providers/aws/events/apigateway/#http-endpoints-with-aws_iam-authorizers). Scroll down to the part where it talks about the user pool.

---

<div class="post-metadata">

**Author:** ![yn5](https://avatars.discourse-cdn.com/v4/letter/y/eada6e/32.png) [@yn5](https://forum.serverless.com/u/yn5)\
**Post date:** [June 20, 2018, 2:29pm UTC](https://forum.serverless.com/t/anyone-have-a-good-modern-example-of-using-a-cognito-user-pool-authorizer/3136/3 "2018-06-20T14:29:27Z")

</div>

@bobbiebarker I have successfully protected an endpoint in my service following the example in that link by using a Cognito user pool arn. And by successfully meaning that once I request, I get back the message “Unauthorized”.

From what I’ve read I need to include a token received from logging in with Cognito in the request as an Authorization header. But when I do it does not allow me to reach the endpoint. What am I missing here?

This is my serverless.yml:

```
service:
  name: my-service

plugins:
  - serverless-webpack

provider:
  name: aws
  region: eu-central-1
  runtime: nodejs6.10

functions:
  create:
  handler: posts.get
  events:
    - http:
        path: posts/get
        method: get
        authorizer:
          arn: arn:aws:cognito-idp:us-east-1:xxx:userpool/us-east-1_ZZZ

```

And for the request I’m using Postman to include the Bearer token which results in a Authenitcation header like this:

```
Authentication: Bearer myTokenXXXXXXXXXXXXX

```

I’ve also tried removing the Bearer part from that header without any luck.

---

<div class="post-metadata">

**Author:** ![yn5](https://avatars.discourse-cdn.com/v4/letter/y/eada6e/32.png) [@yn5](https://forum.serverless.com/u/yn5)\
**Post date:** [June 20, 2018, 3:12pm UTC](https://forum.serverless.com/t/anyone-have-a-good-modern-example-of-using-a-cognito-user-pool-authorizer/3136/4 "2018-06-20T15:12:59Z")

</div>

Just fixed it! Turned out I was using the accessToken from the response of cognitoUser#authenticateUser where I should use the idToken 🙂

---

<div class="post-metadata">

**Author:** ![dcabib](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/dcabib/32/4475_2.png) [@dcabib](https://forum.serverless.com/u/dcabib)\
**Post date:** [August 9, 2020, 12:16am UTC](https://forum.serverless.com/t/anyone-have-a-good-modern-example-of-using-a-cognito-user-pool-authorizer/3136/5 "2020-08-09T00:16:37Z")

</div>

Hello @yn5… I am trying create user in Cognito User Pool using serverless… I was able to handle user authentication using this article [https://www.serverless.com/blog/serverless-auth-with-aws-http-apis](https://www.serverless.com/blog/serverless-auth-with-aws-http-apis) but I was not able to create user using an API Gateway / Lambda endpoint.

Do you have any reference how I should create a lambda function to be able to create a new users instead of using Host UI interface?

Thanks in advanced.
