Cognito UserPool and App ClientId

Folks,
I am new to the serverless / cloudformation ways of coding the infrastructure.
I have one lambda function as resource which should use generated CognitoUserPool and CognitoUserPoolClient Ids as environment variable. I get [object Object] and [object Object] in my lambda function instead of 'Pool Id’and 'App client id’ respectively.

addUser:
  handler: src/handlers/account.createAccount
  environment:
    USERPOOL_ID: !Ref CognitoUserPool
    USERPOOLCLIENT_ID: !Ref CognitoUserPoolClient

Resources:
  CognitoUserPool:
    Type: 'AWS::Cognito::UserPool'
    Properties:
      MfaConfiguration: OFF
      UserPoolName: ${self:provider.userPoolName}
      UsernameAttributes:
        - email
      Policies:
        PasswordPolicy:
          MinimumLength: 8
          RequireNumbers: True
          RequireSymbols: True
          RequireUppercase: True
  CognitoUserPoolClient:
    Type: 'AWS::Cognito::UserPoolClient'
    Properties:
      ClientName: ${self:provider.userPoolClientName}
      GenerateSecret: False
      UserPoolId:
        Ref: CognitoUserPool

How do I resolve this error? The exiting similar topic did not help much.

Hi,

Fairly new myself but you might need to add an outputs section to allow it to be referenced in the lambda environment variables?

Use the output in this link and see if that works?