aws / aws/aws-cdk

aws-rds: ServerlessCluster does not resolve tokens in clusterIdentifier if lowercaseDbIdentifier is enabled.

Open Beginner friendly
#24,937 4 comments 0 reactions 0 assignees View on GitHub
@aws-cdk/aws-rds bug effort/small p2
Dominant language
TypeScript
Stars
12.9k
Forks
4.6k
Avg merge
2d 3h
Merged PRs (30d)
83

Description

### Describe the bug

When the "@aws-cdk/aws-rds:lowercaseDbIdentifier" feature flag is enabled in the cdk.json file, CDK will automatically make the value assigned to the clusterIdentifier property of the ServerlesCluster construct lower case.

If the value assigned to clusterIdentifier includes any tokens, then they will be made lower case before they are resolved, leading to the output being the literal lower case token as we see in the CX environment.

### Expected Behavior


new CfnParameter(this, 'env', {
type: 'String',
default: 'example'
});

const cluster = new rds.ServerlessCluster(this, `ClusterDB`, {
//clusterIdentifier: `cluster-${Tokenization.resolve(Fn.ref("env"), {resolver: tokenResolver., scope: this})}`,
clusterIdentifier: Fn.ref("env"),

Should output

```

Cluster:
Type: AWS::RDS::DBCluster
Properties:
...
DBClusterIdentifier:
Ref: env
```

### Current Behavior

If lowercaseDbIdentifier is set to true, the above code instead outputs

```
Cluster:
Type: AWS::RDS::DBCluster
Properties:
...
DBClusterIdentifier: ${token[token.324]}

```

### Reproduction Steps

1. Set @aws-cdk/aws-rds:lowercaseDbIdentifier to true in the cdk.json file
2. Create a ServerlessCluster resource with the clusterIdentifier property defined, include a tokenized object in the value for the cluster identifier
3. Synthesize the CDK application and observe the value assigned to DBClusterIdentifier for the generated AWS::RDS::DBCluster resouce

### Possible Solution

This was a [known and resolved issue](https://github.com/aws/aws-cdk/issues/18802) for the RDS DatabaseCluster construct, however the fix has not been implemented in the ServelessCluster construct code.

[The code for DatabaseCluster](https://github.com/aws/aws-cdk/pull/20287/files) will make the clusterIdentifier lower case if the lower case feature flag is set to true, and if there are no unresolved tokens in the name

` const clusterIdentifier = FeatureFlags.of(this).isEnabled(cxapi.RDS_LOWERCASE_DB_IDENTIFIER) && !Token.isUnresolved(props.clusterIdentifier)`

However, this is not the case for the [ServerlessCluster code](https://github.com/aws/aws-cdk/blob/259fb5be8ece87891c7c70138ba6b044661f1f7d/packages/aws-cdk-lib/aws-rds/lib/serverless-cluster.ts#L418), which will set the db cluster identifier to lower case regardless of whether there is a token included.

` const clusterIdentifier = FeatureFlags.of(this).isEnabled(cxapi.RDS_LOWERCASE_DB_IDENTIFIER)`

Adding the unresolved token checker to the ServlessCluster code will resolve this issue.

` const clusterIdentifier = FeatureFlags.of(this).isEnabled(cxapi.RDS_LOWERCASE_DB_IDENTIFIER) && !Token.isUnresolved(props.clusterIdentifier)`

### Additional Information/Context

_No response_

### CDK CLI Version

2.65.0

### Framework Version

_No response_

### Node.js Version

v16.16.0

### OS

Amazon Linux 2

### Language

Typescript

### Language Version

_No response_

### Other information

_No response_

Contributor guide

Open the contributing guide

Research direction

The issue points to packages/aws-cdk-lib/aws-rds/lib/serverless-cluster.ts and compares it with DatabaseCluster's implementation. Start by tracing ServerlessCluster's clusterIdentifier handling and synthesizing the reproduction with lowercaseDbIdentifier enabled. Done means unresolved token values remain CloudFormation references while literal identifiers still follow lowercase behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, typescript
Domain
cloud, infrastructure
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
82/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.