Skip to content

feat(cli): build your own fromLookup() imports with the new context provider for CloudControl API #138

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

Merged
merged 13 commits into from
Feb 26, 2025

Conversation

rix0rrr
Copy link
Contributor

@rix0rrr rix0rrr commented Feb 25, 2025

A generic Context Provider for CloudControl API. See aws/aws-cdk#33258 for an example how to implement a fromLookup() method using the new context provider.

(Extracted from aws/aws-cdk#33258)


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

A generic Context Provider for CloudControl API. Extracted from
aws/aws-cdk#33258.
Signed-off-by: github-actions <[email protected]>
Signed-off-by: github-actions <[email protected]>
@@ -31,6 +31,8 @@ import {
} from '../../lib/commands/migrate';
import { MockSdkProvider, mockCloudFormationClient, restoreSdkMocksToDefault } from '../util/mock-sdk';

jest.setTimeout(120_000);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

Copy link
Contributor

@mrgrain mrgrain left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One minor comment. Otherwise good to go.

@codecov-commenter
Copy link

codecov-commenter commented Feb 25, 2025

Codecov Report

Attention: Patch coverage is 94.30052% with 11 lines in your changes missing coverage. Please review.

Project coverage is 84.58%. Comparing base (88e2bdf) to head (ca3d332).
Report is 393 commits behind head on main.

Files with missing lines Patch % Lines
...s/aws-cdk/lib/context-providers/cc-api-provider.ts 93.70% 7 Missing and 1 partial ⚠️
packages/aws-cdk/lib/util/json.ts 95.31% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #138      +/-   ##
==========================================
- Coverage   84.76%   84.58%   -0.19%     
==========================================
  Files         196      198       +2     
  Lines       35187    35380     +193     
  Branches     4552     4555       +3     
==========================================
+ Hits        29828    29926      +98     
- Misses       5208     5310     +102     
+ Partials      151      144       -7     
Flag Coverage Δ
suite.unit 84.58% <94.30%> (-0.19%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Signed-off-by: github-actions <[email protected]>
Signed-off-by: github-actions <[email protected]>
Signed-off-by: github-actions <[email protected]>
Signed-off-by: github-actions <[email protected]>
@mrgrain mrgrain changed the title feat(cli): Context Provider for CloudControl API feat(cli): new context provider for CloudControl API Feb 26, 2025
@mrgrain mrgrain changed the title feat(cli): new context provider for CloudControl API feat(cli): build your own fromLookup() imports with the new context provider for CloudControl API Feb 26, 2025
@aws-cdk-automation aws-cdk-automation added this pull request to the merge queue Feb 26, 2025
Merged via the queue into main with commit 130445d Feb 26, 2025
28 checks passed
@aws-cdk-automation aws-cdk-automation deleted the huijbers/ccapi-provider branch February 26, 2025 16:26
mergify bot pushed a commit to aws/aws-cdk that referenced this pull request Mar 24, 2025
### Issue # (if applicable)

Closes #33606.
Closes #15115.

### Reason for this change

AWS-managed prefix lists are useful to control traffic VPC and AWS managed services.
The name of the AWS-managed prefix list is documented but the id should be copy&paste by hand.

### Description of changes

This PR implements `PrefixList.fromLookup()` to look up an existing managed prefix list by name.
``` ts
ec2.PrefixList.fromLookup(this, 'CloudFrontOriginFacing', {
  prefixListName: 'com.amazonaws.global.cloudfront.origin-facing',
});
```

Uses the new CloudControl context provider: aws/aws-cdk-cli#138 and cdklabs/cloud-assembly-schema#124.

### Describe any new or updated permissions being added

Nothing.

### Description of how you validated changes

Added unit tests and an integ test.

### Checklist
- [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md)

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
shikha372 pushed a commit to shikha372/aws-cdk that referenced this pull request Apr 4, 2025
### Issue # (if applicable)

Closes aws#33606.
Closes aws#15115.

### Reason for this change

AWS-managed prefix lists are useful to control traffic VPC and AWS managed services.
The name of the AWS-managed prefix list is documented but the id should be copy&paste by hand.

### Description of changes

This PR implements `PrefixList.fromLookup()` to look up an existing managed prefix list by name.
``` ts
ec2.PrefixList.fromLookup(this, 'CloudFrontOriginFacing', {
  prefixListName: 'com.amazonaws.global.cloudfront.origin-facing',
});
```

Uses the new CloudControl context provider: aws/aws-cdk-cli#138 and cdklabs/cloud-assembly-schema#124.

### Describe any new or updated permissions being added

Nothing.

### Description of how you validated changes

Added unit tests and an integ test.

### Checklist
- [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md)

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
mergify bot pushed a commit to aws/aws-cdk that referenced this pull request Apr 10, 2025
### Issue # (if applicable)

Closes #31720

This replaces my previous PR #32901.  I addressed the PR comments in this new PR.

This depends on this PR: cdklabs/cloud-assembly-schema#124.

Also depends on this CDK CLI PR: aws/aws-cdk-cli#138. That PR should be merged first and the CLI released, before this PR can be merged.

### Reason for this change

Add DatabaseInstance.fromLookup() feature

### Description of changes

* Add CC API Context Provider.  Needs this PR: cdklabs/cloud-assembly-schema#124
* DatabaseInstance.fromLookup call CC API to get the database instance info from instanceIdentifier.
* Add units tests.

### Describe any new or updated permissions being added

User will need to have permission to run CloudControl API.

### Description of how you validated changes

Tested with this code.  I already have an RDS DB in my AWS account.  I want to look it up and grant connect to a new user.
Saved to packages/@aws-cdk-testing/framework-integ/test/aws-rds/test/my-test-app.ts

```
import * as cdk from 'aws-cdk-lib';
import * as iam from 'aws-cdk-lib/aws-iam';
import * as rds from 'aws-cdk-lib/aws-rds';

const awsAccountId = 'XXXXXXXXXX79';
const instanceId = 'XXXXXXXXXX-instance-1';

const appWithDb = new cdk.App();
const stack = new cdk.Stack(appWithDb, 'StackWithVpc', {
  env: {
    region: 'us-east-1',
    account: awsAccountId,
  },
});

const dbFromLookup = rds.DatabaseInstance.fromLookup(stack, 'dbFromLookup', {
  instanceIdentifier: instanceId,
});

/* eslint-disable no-console */
console.log('lookup values', dbFromLookup.dbInstanceEndpointAddress, dbFromLookup.dbInstanceEndpointPort);

const consoleReadOnlyRole = new iam.Role(stack, 'TestRole', {
  assumedBy: new iam.ArnPrincipal('arn_for_trusted_principal'),
});
dbFromLookup.grantConnect(consoleReadOnlyRole, 'dbTestUser');

```

Ran this command:
```
../../aws-cdk/bin/cdk -a 'npx ts-node test/aws-rds/test/my-test-app.ts' synth 
```


### Checklist
- [ X ] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md)

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
mergify bot pushed a commit to aws/aws-cdk that referenced this pull request Apr 23, 2025
### Issue # (if applicable)

Closes #33602.

### Reason for this change



There will be many cases where IAM roles will be created outside the CFn stack and used.
Importing actual existing roles from AWS accounts is very convenience. It is also useful to be able to make an error if a role does not exist.

On the other hand, a generic Context Provider for CloudControl API has been added in aws-cdk-cli.

aws/aws-cdk-cli#138

This allows us to implement new context methods.

### Description of changes



Add `Role.fromLookup` method using the new context provider.

### Describe any new or updated permissions being added




### Description of how you validated changes



Both unit and integ tests.

### Checklist
- [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md)

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants