aws / aws-cdk

The AWS Cloud Development Kit is a framework for defining cloud infrastructure in code
https://aws.amazon.com/cdk
Apache License 2.0
11.61k stars 3.9k forks source link

(aws-rds): Add lookup functonality #31720

Open JoshMcCullough opened 1 week ago

JoshMcCullough commented 1 week ago

Describe the feature

See related ticket: https://github.com/aws/aws-cdk/issues/7295

We would like a lookup function so we can fetch an RDS Database Instance reference by id, similar to other constructs.

Use Case

Currently, we need to provide many things (instanceIdentifier, instanceEndpointAddress, port, securityGroups) in order to use an existing RDS Database Instance in the stack. This is "untenable" as hard-coding them is not a good idea.

Proposed Solution

Add a lookup, e.g.:

const dbInstance = DatabaseInstance.fromLookup(stack, "DbInstance", { databaseIdentifier: "my-db-instance" });

Other Information

No response

Acknowledgements

CDK version used

2.161.0

Environment details (OS name and version, etc.)

Manjaro Linux

khushail commented 1 week ago

Hi @JoshMcCullough , thanks for requesting this.

As far as current implementation goes and mentioned in the linked issue as well, fromDatabaseInstanceAttribute() method exists which needs few parameters as input.

https://github.com/aws/aws-cdk/blob/361df5f6f44bdddc5dec818ad307c2b75bcb2414/packages/aws-cdk-lib/aws-rds/lib/instance.ts#L138

Having an instance lookup method would definitely be useful.

Thanks for volunteering for this implementation. Looking forward to your PR!

JoshMcCullough commented 1 week ago

I'd prefer if someone else would do the PR, but I can try ... maybe.