-
Notifications
You must be signed in to change notification settings - Fork 4k
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 RDS DatabaseInstance.fromLookup #32901
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 fails with the following errors:
❌ Features must contain a change to an integration test file and the resulting snapshot.
❌ CLI code has changed. A maintainer must run the code through the testing pipeline (git fetch origin pull/32901/head && git push -f origin FETCH_HEAD:test-main-pipeline), then add the 'pr-linter/cli-integ-tested' label when the pipeline succeeds.
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.
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
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.
❤️ This looks great, thanks!
I have couple of small comments.
}); | ||
|
||
// THEN | ||
expect(result).toEqual({}); |
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.
Shouldn't we return some sort of error value? Perhaps throw an exception?
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.
ok, will throw error instead of returning {}
.
}); | ||
|
||
// THEN | ||
const propsObj = result['my-db-instance-1']; |
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 see the API is returning a dictionary { id1 -> props1, id2 -> props2, ... }
.
What's the advantage of mapping by ID? I'm honestly asking because I don't know if there's a reason for it. Wouldn't it make more sense to return a list? Just [ props1, props2, ... ]
?
I don't think there is a way for the consumer of this API to know the id
in advance, so they will always need to iterate over Object.entries()
anyway to get both [id, props]
at the same time... but the identifier will be in the propsX
object already anyway? (Or at least, if it is requested, which it should be)
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 see your point. Will change it to something like { results: [props1, props2, ...]}
public async getValue(args: CcApiContextQuery) { | ||
const cloudControl = (await initContextProviderSdk(this.aws, args)).cloudControl(); | ||
|
||
const result = await this.findResources(cloudControl, args); |
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.
Is there an exception handler around this already?
What if findJsonValue
throws because the user made a type in their path, will the error be handled sensibly? (I.e., descriptive error shown to the user, not a gory stack trace pointing somewhere to the innards of the CLI?)
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 current code returns undefined so no property of that name is set.
Since we are throwing exceptions in findJsonValue, I will add error handling and unit tests for that.
* @param path | ||
*/ | ||
export function findJsonValue(jsonObject: any, path: string): any { | ||
return path.split('.').reduce((r, k) => r[k], jsonObject); |
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.
This is clever and short, but I think I would like some more type checking on it and throwing descriptive error messages. Likely things users are going to do wrong: mistype a key, reference a key that's missing, reference a key of the wrong type...
Some errors of the kind:
Cannot read field 'foo.bar.quux': expected an object at 'foo.bar' but got "hello"
Cannot read field 'foo.bar.quux': expected an object at 'foo.bar' but got undefined
Or something to that effect.
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.
Makes sense. I will add better error handling.
* @param propertiesToReturn | ||
* @returns | ||
*/ | ||
export function toResultObj(jsonObject: any, propertiesToReturn: string[]): {[key: string]: any} { |
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.
Can we extract all this JSON object manipulation out to a separate file? It's independent and worthwhile enough to not confine it to the "cc api provider", where no one will ever find it again :)
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.
That makes sense. How about aws-cdk/lib/util/json.ts?
dummyValue: {}, | ||
}).value; | ||
|
||
const instance = response[options.instanceIdentifier]; |
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.
You need to account for the fact that it wasn't found, right? What does that do?
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.
Will add try-catch and throw an Error when there is a problem with CC API lookup.
/** | ||
* The instance identifier of the DatabaseInstance | ||
*/ | ||
readonly instanceIdentifier: string; |
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 issue this PR is trying to close says to use databaseIdentifier
. Is instanceIdentifier
the same thing as databaseIdentifier
?
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.
In RDS doc, DatabaseInstance has an instanceIdentifier
property. So I try to be consistent with the doc. https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_rds.DatabaseInstance.html#instanceidentifier-1
exactIdentifier: options.instanceIdentifier, | ||
propertiesToReturn: [ | ||
'DBInstanceArn', | ||
'Endpoint.Address', | ||
'Endpoint.Port', | ||
'DbiResourceId', | ||
'DBSecurityGroups', | ||
], | ||
} as cxschema.CcApiContextQuery, |
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.
This looks great! Does it also work? Have you tested this in your actual AWS account?
I trust that the unit tests assert that the code holds to some contract... but do we actually know the contract is the right one? 😁
const securityGroup = ec2.SecurityGroup.fromSecurityGroupId( | ||
scope, | ||
`LSG-${securityGroupId}`, | ||
securityGroupId, | ||
); |
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.
We probably need to add an option to the properties object, and pass it here to fromSecurityGroupId
, on whether the security groups are going to be mutable or immutable by default.
The difference is whether we will try to add rules to them. false
makes more sense, but due to historical reasons the default is true
...
// Add the new security group to the existing security groups of the RDS instance | ||
instance.connections.addSecurityGroup(myNewSecurityGroup); |
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 example of what to do with a freshly imported database instance doesn't make a lot of sense. Adding a security group to it in this way is unlikely to be what you want (and also, this doesn't do anything because the instance itself is not owned).
Is there another example to copy/paste?
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.
db.grantConnect and db.connections.allowDefaultPortFrom are also popular results from my search. I will use grantConnect instead.
"@jsii/check-node": "1.104.0", | ||
"@smithy/middleware-endpoint": "3.1.4", | ||
"@smithy/middleware-endpoint": "4.0.0", |
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.
A new major version. This is particularly scary! Have you checked for breaking changes?
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.
Good point. I will try to find a 3.x version that works with client-cloudcontrol.
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.
Rico had already bump this to '^4'. I won't need to make this change.
"@smithy/node-http-handler": "3.2.4", | ||
"@smithy/property-provider": "3.1.10", | ||
"@smithy/shared-ini-file-loader": "3.1.8", | ||
"@smithy/types": "3.5.0", | ||
"@smithy/types": "4.0.0", |
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.
A new major version. This is particularly scary! Have you checked for breaking changes?
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.
Will try to find a 3.x version that works with client-cloudcontrol.
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.
This will probably require a change to packages/aws-cdk/lib/context-providers/index.ts
as well.
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.
ok, will double check this.
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.
Thank you for trying to be a good citizen! It's usually very much appreciated. <3
We are currently trying to keep the CLI a bit more stable. Are any of the version upgrades strictly necessary to achieve your goal - or would adding the new package be enough? If so, I'd rather just add one and keep everything else as it was.
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 had to use "@aws-sdk/client-cloudcontrol": "3.723.0". I had to bump the other ones to the same version, because of a smithy error.
'DbiResourceId', | ||
'DBSecurityGroups', | ||
], | ||
} as cxschema.CcApiContextQuery, |
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.
Is the type casting required here? How do we guarantee type correctness? If so, please add a comment explaining why.
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.
Good point. We should use the keyword satisfies
instead of as
here.
This PR cannot be merged because it has conflicts. Please resolve them. The PR will be considered stale and closed if it remains in an unmergeable state. |
This PR cannot be merged because it has conflicts. Please resolve them. The PR will be considered stale and closed if it remains in an unmergeable state. |
1 similar comment
This PR cannot be merged because it has conflicts. Please resolve them. The PR will be considered stale and closed if it remains in an unmergeable state. |
This PR has been in the BUILD FAILING state for 3 weeks, and looks abandoned. To keep this PR from being closed, please continue work on it. If not, it will automatically be closed in a week. |
This PR has been deemed to be abandoned, and will be automatically closed. Please create a new PR for these changes if you think this decision has been made in error. |
Comments on closed issues and PRs are hard for our team to see. |
Issue # (if applicable)
#31720
Needs this PR: cdklabs/cloud-assembly-schema#124
Reason for this change
Add DatabaseInstance.fromLookup() feature
Description of changes
Use CloudControl API as ContextProvider to query for DatabaseInstance.
Describe any new or updated permissions being added
Use will need to have permission to run CloudControl API.
Description of how you validated changes
Included unit tests for CC API and DatabaseInstance changes.
Checklist
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license