# Need a reference to a Cognito user pool before it was created

**URL:** <https://discourse.sst.dev/t/need-a-reference-to-a-cognito-user-pool-before-it-was-created/1033>\
**Category:** General\
**Created:** [May 24, 2019, 4:52pm UTC](https://discourse.sst.dev/t/need-a-reference-to-a-cognito-user-pool-before-it-was-created/1033 "2019-05-24T16:52:58Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![DWboutin](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/dwboutin/32/489_2.png) [@DWboutin](https://discourse.sst.dev/u/DWboutin)\
**Post date:** [May 24, 2019, 4:52pm UTC](https://discourse.sst.dev/t/need-a-reference-to-a-cognito-user-pool-before-it-was-created/1033/1 "2019-05-24T16:52:58Z")

</div>

Hi!

I’m trying to refactor my mono-service Stack to a multi-services Cross-Stack. First I have my ApiGatway created with this route:

```
functions:
  contact-creation:
    handler: handler.creation
    environment:
      USER_POOL:
        Ref: ${self:custom.stage}-ContactsCognitoUserPoolId
    events:
      - http:
          method: post
          path: contact
          cors:
            origins: ${self:custom.cors.${self:custom.stage}

```

In this route, USER\_POOL is needed to update the cognito profile of the user.

In my deployment process, I need to create the ApiGateway before the Cognito user pool and identity pool because I specify the access in the identity pool like this:

```
- Effect: 'Allow'
                Action:
                  - 'execute-api:Invoke'
                Resource:
                  Fn::Join:
                    - ''
                    -
                      - 'arn:aws:execute-api:'
                      - Ref: AWS::Region
                      - ':'
                      - Ref: AWS::AccountId
                      - ':'
                      - 'Fn::ImportValue': ${self:custom.stage}-ApiGatewayRestApiId
                      - '/*'

```

When I trigger the deployment, I get this error:

`The CloudFormation template is invalid: Template format error: Unresolved resource dependencies [dev-ContactsCognitoUserPoolId] in the Resources block of the template`

Do I need to import the ressources in my ApiGateway service or I can stay with the Cognito completely separated from others services? How can I handle this correctly?

Thank you for your help!

---

<div class="post-metadata">

**Author:** ![jayair](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/jayair/32/9_2.png) [@jayair](https://discourse.sst.dev/u/jayair)\
**Post date:** [May 27, 2019, 12:28am UTC](https://discourse.sst.dev/t/need-a-reference-to-a-cognito-user-pool-before-it-was-created/1033/2 "2019-05-27T00:28:19Z")

</div>

Oh I just saw your other comment but you can see we split this service out in Part II of our guide. Here is an example:

> **[Configure Cognito Identity Pool in Serverless](https://serverless-stack.com/chapters/configure-cognito-identity-pool-in-serverless.html)**
>
> We can define our Cognito Identity Pool using the Infrastructure as Code pattern by using CloudFormation in our serverless.yml. We are going to set the User Pool as the Cognito Identity Provider. And define the Auth Role with a policy allowing access...
