Jerald
Jerald

Reputation: 4048

!Ref function in aws-cdk

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
});

Upvotes: 3

Views: 2458

Answers (1)

Romain
Romain

Reputation: 12819

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).

Upvotes: 3

Related Questions