title: Unable to reference CloudFormation resource in serverless.yml. Invalid variable reference syntax for variable UserPoolId
body: <p>I am using the Serverless framework to deploy a serverless app to AWS. However, the CloudFormation part is not working as expected. I have looked up on the web and couldn't find anything wrong with my YAML.</p>
  
  <p>I am creating a <code>UserPool</code> and then <code>UserPoolClient</code> by using CloudFormation. I have the following YAML for <code>resources:</code></p>
  
  <pre class="lang-yaml prettyprint-override"><code>    resources:
        Resources:
          HttpBucket:
            Type: "AWS::S3::Bucket"
            Properties:
              BucketName: ${self:service}-${UserPoolId}
              AccessControl: PublicRead
              WebsiteConfiguration:
                IndexDocument: index.html
          UserPool:
            Type: "AWS::Cognito::UserPool"
            Properties:
              UserPoolName: ${self:service}-user-pool
              MfaConfiguration: "OFF"
              EmailVerificationSubject: "Your verification code"
              EmailVerificationMessage: "Your verification code is {####}. "  
              Schema:
                - Name: name
                  AttributeDataType: String
                  Mutable: true
                  Required: true
                - Name: email
                  AttributeDataType: String
                  Mutable: false
                  Required: true
                - Name: teamName
                  AttributeDataType: String
                  Mutable: true
                  Required: false
                - Name: custom:supportedTeam
                  AttributeDataType: String
                  Mutable: true
                  Required: false
                - Name: custom:payment
                  AttributeDataType: String
                  Mutable: true
                  Required: false
                  DeveloperOnlyAttribute: true
              UsernameAttributes:
                - email
              AutoVerifiedAttributes:
                - email
              AdminCreateUserConfig:
                InviteMessageTemplate:
                  EmailMessage: 'Your username is {username} and temporary password is {####}. '
                  EmailSubject: Your temporary password
                  SMSMessage: 'Your username is {username} and temporary password is {####}. '
                UnusedAccountValidityDays: 7
                AllowAdminCreateUserOnly: false
              Policies:
                PasswordPolicy:
                  RequireLowercase: true
                  RequireSymbols: false
                  RequireNumbers: true
                  MinimumLength: 6
                  RequireUppercase: true
          UserPoolClient:
            Type: "AWS::Cognito::UserPoolClient"
            Properties:
              ClientName: ${self:service}-client
              GenerateSecret: false
              UserPoolId: 
                Ref: UserPool
        Outputs:
          UserPoolId:
            Value: 
              Ref: UserPool
            Export:
              Name: "UserPool::Id"
          UserPoolClientId:
            Value: 
              Ref: UserPoolClient
            Export:
              Name: "UserPoolClient::Id"
  </code></pre>
  
  <p>I am unable to reference <code>UserPool</code> when specifying <code>UserPoolClient</code> (to be used as <code>UserPoolId</code>).</p>
  
  <p>The following:</p>
  
  <pre><code>UserPoolId: 
    Ref: UserPool
  </code></pre>
  
  <p>yields the error:</p>
  
  <blockquote>
    <p>Invalid variable reference syntax for variable UserPoolId. You can
    only reference env vars, options, &amp; files. You can check our docs for
    more info.</p>
  </blockquote>
  
  <p>Another thing which I am not sure about, I have seen people sharing YAML containing the following syntax:</p>
  
  <pre><code>UserPoolId: !Ref UserPool
  </code></pre>
  
  <p>But it also fails and errors about the invalid syntax (due to <code>!Ref</code>). Can anyone clear me on this?</p>