Reference Cognito User Pool from Resource in Lambda Authorizer

aws

#1
functions:
  authorized:
    handler: auth.authorized
    memorySize: 128
    timeout: 5
    events:
      - http:
          path: authorized
          method: get
          integration: lambda
          cors:
            origins:
              - '*'
          authorizer:
            arn: ${cf:my-project.userpoolarn}

...
resources:
  Outputs:
    ...
    UserPoolArn:
      Value:
        Fn::GetAtt: [myProjectUsrPool, Arn]
      Export:
        Name: 'userpoolarn'
    ...
  Resources:
    myProjectUsrPool:
      Type: AWS::Cognito::UserPool
      Properties:
        UserPoolName: MyProject-${self:provider.stage}-user-pool
        AutoVerifiedAttributes: 
          - email

Given the config. I’m getting the following error

Trying to request a non exported variable from CloudFormation. Stack name: "my-project" Requested variable: "userpoolarn".

Am I doing this wrong?


#2

You can’t reference an exported variable from the same service. Use Ref instead (with the JSON-style syntax).