-
Notifications
You must be signed in to change notification settings - Fork 3.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(rds): add clusterArn property to DatabaseCluster #29289
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The pull request linter has failed. See the aws-cdk-automation comment below for failure reasons. If you believe this pull request should receive an exemption, please comment and provide a justification.
A comment requesting an exemption should contain the text Exemption Request
. Additionally, if clarification is needed add Clarification Request
to a comment.
/** | ||
* The ARN of the cluster | ||
*/ | ||
public get clusterArn(): string { | ||
return Stack.of(this).formatArn({ | ||
service: 'rds', | ||
resource: 'cluster', | ||
arnFormat: ArnFormat.COLON_RESOURCE_NAME, | ||
resourceName: this.clusterIdentifier, | ||
}); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just like ServerlessCluster
aws-cdk/packages/aws-cdk-lib/aws-rds/lib/serverless-cluster.ts
Lines 345 to 355 in 1f30b5d
/** | |
* The ARN of the cluster | |
*/ | |
public get clusterArn(): string { | |
return Stack.of(this).formatArn({ | |
service: 'rds', | |
resource: 'cluster', | |
arnFormat: ArnFormat.COLON_RESOURCE_NAME, | |
resourceName: this.clusterIdentifier, | |
}); | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@blimmer Is this how CDK normally handles this? I ask because the output becomes a Join
instead of doing a GetAtt
on the resource. Trying to wrap my head around why we should do this over the GetAtt
path. I tried looking at the Lambda Function L2, since there is a readonly
property for the Arn.
Honestly not sure if it matters (likely not) but trying to learn different parts of this as I go. To me seems like we have two patterns going on, the one you have here and the readonly
property for the Arn.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure - I just followed the pattern in the linked code. One of the core contributors might be able to tell us.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I asked the team directly. I did find SQS which does this differently. https://github.com/aws/aws-cdk/blob/v2.130.0/packages/aws-cdk-lib/aws-sqs/lib/queue.ts#L437-L440
const queue = new sqs.Queue(this, 'CdkExampleQueue', {
visibilityTimeout: Duration.seconds(300)
});
new CfnOutput(this, "arn", {
exportName: "arn",
value: queue.queueArn,
})
CFN Synth
Outputs:
arn:
Value:
Fn::GetAtt:
- CdkExampleQueue7618E31B
- Arn
Export:
Name: arn
Which fits my mental model better. I am not sure if there is a big difference or a reason it was done this way in RDS. Maybe one is a "legacy" way of doing things.
Generally, this looks fine. I just want to get some deeper clarity on what is typical.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jfuss Sorry to jump in - I was looking at something similar recently. This is a very typical pattern that is used in the codebase here are just a few examples:
return Stack.of(this).formatArn({ |
return cdk.Stack.of(this).formatArn({ |
return Stack.of(this).formatArn({ |
Also, this is just a "getter" for the clusterArn
so I don't think we want to be producing any outputs in the synthesized template. Instead, this just allows clusterArn
to be exposed for use throughout the rest of their app.
@@ -4052,6 +4052,34 @@ describe('cluster', () => { | |||
], | |||
}); | |||
}); | |||
|
|||
test('check that clusterArn property works', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
aws-cdk/packages/aws-cdk-lib/aws-rds/test/serverless-cluster.test.ts
Lines 602 to 627 in 1f30b5d
test('check that clusterArn property works', () => { | |
// GIVEN | |
const stack = testStack(); | |
const vpc = ec2.Vpc.fromLookup(stack, 'VPC', { isDefault: true }); | |
const cluster = new ServerlessCluster(stack, 'Database', { | |
engine: DatabaseClusterEngine.AURORA_MYSQL, | |
vpc, | |
}); | |
const exportName = 'DbCluterArn'; | |
// WHEN | |
new cdk.CfnOutput(stack, exportName, { | |
exportName, | |
value: cluster.clusterArn, | |
}); | |
// THEN | |
expect(stack.resolve(cluster.clusterArn)).toEqual({ | |
'Fn::Join': ['', [ | |
'arn:', | |
{ Ref: 'AWS::Partition' }, | |
':rds:us-test-1:12345:cluster:', | |
{ Ref: 'DatabaseB269D8BB' }, | |
]], | |
}); | |
}); |
Exemption request. The JSDoc should be sufficient and I added a unit test. |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
The pull request linter fails with the following errors:
PRs must pass status checks before we can provide a meaningful review. If you would like to request an exemption from the status checks or clarification on feedback, please leave a comment on this PR containing |
Is there a duplication with this PR? |
Reason for this change
It wasn't clear to me how to get the
clusterArn
fromDatabaseCluster
. This PR adds that property.Description of changes
Add
clusterArn
to DatabaseCluster, just likeServerlessCluster
exposes.Description of how you validated changes
Added unit test similar to
ServerlessCluster
.Checklist
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license