Skip to content

Commit

Permalink
Updated README with DatabaseInstance.fromLookup
Browse files Browse the repository at this point in the history
  • Loading branch information
pcheungamz committed Dec 2, 2024
1 parent 78f79d6 commit 16de83b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
17 changes: 17 additions & 0 deletions packages/aws-cdk-lib/aws-rds/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1421,3 +1421,20 @@ new rds.DatabaseCluster(this, 'Cluster', {
monitoringRole,
});
```

## Importing existing DatabaseInstance

### Lookup DatabaseInstance by instanceIdentifier

You can lookup an existing DatabaseInstance by its instanceIdentifier using `DatabaseInstance.fromLookup()`. This method returns an `IDatabaseInstance`.

Here's how `DatabaseInstance.fromLookup()` can be used:

```ts
const instance = rds.DatabaseInstance.fromLookup(stack, 'MyInstance', {
instanceIdentifier: 'instance-1',
});

// Add the new security group to the existing security groups of the RDS instance
instance.connections.addSecurityGroup(myNewSecurityGroup);
```
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe('DatabaseInstanceBase from lookup', () => {
});

const stack = new Stack(undefined, undefined, { env: { region: 'us-east-1', account: '123456789012' } });
const instance = rds.DatabaseInstance.fromLookup(stack, 'Key', {
const instance = rds.DatabaseInstance.fromLookup(stack, 'MyInstance', {
instanceIdentifier: 'instance-1',
});

Expand All @@ -42,7 +42,7 @@ describe('DatabaseInstanceBase from lookup', () => {
});

const stack = new Stack(undefined, undefined, { env: { region: 'us-east-1', account: '123456789012' } });
const instance = rds.DatabaseInstance.fromLookup(stack, 'Key', {
const instance = rds.DatabaseInstance.fromLookup(stack, 'MyInstance', {
instanceIdentifier: 'instance-1',
});

Expand Down

0 comments on commit 16de83b

Please sign in to comment.