!Ref function in aws-cdk

Viewed 1980

How to call !Ref function in aws-cdk stack? I have a UserPool resource and UserPoolClientResource with userPoolId property:

const userPool = new cognito.cloudformation.UserPoolResource(this, userPoolResourceName, {
  userPoolName,
  usernameAttributes: ['email'],
  autoVerifiedAttributes: ['email'],
  policies: {
    passwordPolicy: {
      minimumLength: 8,
      requireLowercase: false,
      requireNumbers: false,
      requireSymbols: false,
      requireUppercase: false
    }
  }
});

new cognito.cloudformation.UserPoolClientResource(this, userPoolClientResourceName, {
  userPoolId: `!Ref ${userPool.id}`, // failed
  clientName: userPoolClientName
});
1 Answers

The CDK renames the Ref to make them look like any other properties, and they have a name that is automatically generated from the resource name and the Ref type (typically either Name, Id or Arn).

In the particular case you're facing here, you need to use the UserPoolResource.userPoolId property (userPool is the resource type name, and Id is the Ref type).

Related