title: How to fix Circular dependency between resources on a logical ID
body: <p>I trying to automate building process of my serverless application. When I set up CognitoUserPool resources I need the resources Ref CognitoUserPoolClient to create a link to redirect the client in "EmailMessage"</p>
  
  <p>But the CognitoUserPoolClient need Ref CognitoUserPool</p>
  
  <pre><code> CognitoUserPool:
      Type: AWS::Cognito::UserPool
      Properties:
        # Generate a name based on the stage
        UserPoolName: ${self:custom.STAGE}-${self:custom.CLIENT}-user-pool
            EmailMessage: !Join
            - ''
            - - &gt;
                You are invited to the SonderMMS platform, the world's first owned media management software. &lt;br&gt;
                 Username: {username} &lt;br&gt;
                 Password: {####} &lt;br&gt;
                 Login
                 &lt;a href='
                 https://${self:custom.COGNITO_DOMAIN}.auth.${self:custom.REGION}.amazoncognito.com/oauth2/authorize?&amp;response_type=token&amp;redirect_uri=${self:custom.URL.${self:custom.STAGE}}&amp;client_id=
              - !Sub '#{CognitoUserPoolClient}'
  
              - &gt;
                '&gt; here &lt;/a&gt;.
            EmailSubject: "Email Invite"
  
  
    CognitoUserPoolClient:
      Type: AWS::Cognito::UserPoolClient
      Properties:
        # Generate an app client name based on the stage
        ClientName: ${self:custom.STAGE}-${self:custom.CLIENT}-user-pool-client
        UserPoolId: !Ref CognitoUserPool
        ExplicitAuthFlows:
          - ADMIN_NO_SRP_AUTH
        GenerateSecret: false
  </code></pre>
  
  <p>So i get this error</p>
  
  <blockquote>
    <p>The CloudFormation template is invalid: Circular dependency between resources: [CognitoUserPoolClient, ApiGatewayAuthorizer, IdentityPool, SSMCognitoUserPoolClientId, IdentityPoolRoleMapping, SSMUserPoolId, ApiGatewayMethodTelstraPost, CognitoUserPool, SSMIdentityPoolId, ApiGatewayDeployment1559121507544, CognitoUnAuthorizedRole]</p>
  </blockquote>