Skip to content

Commit 5a8be4f

Browse files
authored
feat(aws-cdk-lib): add arnFor<ResourceName> for 47 more resources (#36231)
### Reason for this change Today, out of `1512` resources, `892` have an `arnFor${Resource}` getter function (~58%). The reasons are varied, but it comes done to us not being able to identify the required resource properties in an automated way. ### Description of changes We are adding a few additional heuristics to the matching: - If we cannot find an Arn property for a resource, but can match all variables of its arn template to properties, we can use that to interpolate the Arn . (`37` additional resources) - A property may now also be called or end in `ARN` (all caps). (`9` additional resources) - Some resources use a property name prefix that is different than their resource name, e.g. [AWS::BedrockAgentCore::Runtime](https://docs.aws.amazon.com/AWSCloudFormation/latest/TemplateReference/aws-resource-bedrockagentcore-runtime.html) uses `AgentRuntime` instead of the expected `Runtime`. We extract this prefix from a primary identifier if it is ending in `Id`. (`2` additional resources) This brings our total count to `939` or `~62%`. A little better! PR also includes a major refactor of how reference props and now arn getters are organized. A lot of code depends on this information, so best to centralize the logic for it. ### Describe any new or updated permissions being added n/a ### Description of how you validated changes Existing and additional 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*
1 parent 3d6b204 commit 5a8be4f

File tree

21 files changed

+491
-147
lines changed

21 files changed

+491
-147
lines changed

aws-cdk.code-workspace

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,30 +7,14 @@
77
"type": "on-demand"
88
},
99
"jest.virtualFolders": [
10-
{
11-
"name": "aws-cdk",
12-
"rootPath": "packages/aws-cdk"
13-
},
1410
{
1511
"name": "aws-cdk-lib",
1612
"rootPath": "packages/aws-cdk-lib"
1713
},
18-
{
19-
"name": "cli-lib-alpha",
20-
"rootPath": "packages/@aws-cdk/cli-lib-alpha"
21-
},
22-
{
23-
"name": "cloudformation-diff",
24-
"rootPath": "packages/@aws-cdk/cloudformation-diff"
25-
},
2614
{
2715
"name": "custom-resource-handlers",
2816
"rootPath": "packages/@aws-cdk/custom-resource-handlers"
2917
},
30-
{
31-
"name": "integ-runner",
32-
"rootPath": "packages/@aws-cdk/integ-runner"
33-
},
3418
{
3519
"name": "integ-tests-alpha",
3620
"rootPath": "packages/@aws-cdk/integ-tests-alpha"
@@ -39,17 +23,13 @@
3923
"name": "aws-custom-resource-sdk-adapter",
4024
"rootPath": "packages/@aws-cdk/aws-custom-resource-sdk-adapter"
4125
},
42-
{
43-
"name": "toolkit",
44-
"rootPath": "packages/@aws-cdk/toolkit"
45-
},
46-
{
47-
"name": "user-input-gen",
48-
"rootPath": "tools/@aws-cdk/user-input-gen"
49-
},
5026
{
5127
"name": "mixins",
5228
"rootPath": "packages/@aws-cdk/mixins-preview"
29+
},
30+
{
31+
"name": "spec2cdk",
32+
"rootPath": "tools/@aws-cdk/spec2cdk"
5333
}
5434
]
5535
},
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
export * from './cfn-props-mixins.generated';
2+
export * from './logs-delivery-mixins.generated';
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './events.generated';
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
export * as events from './events';
12
export * as mixins from './mixins';
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
export * from './cfn-props-mixins.generated';
2+
export * from './logs-delivery-mixins.generated';

packages/@aws-cdk/mixins-preview/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,7 @@
486486
"./aws_s3vectors": "./lib/services/aws-s3vectors/index.js",
487487
"./aws_s3vectors/mixins": "./lib/services/aws-s3vectors/mixins.js",
488488
"./aws_sagemaker": "./lib/services/aws-sagemaker/index.js",
489+
"./aws_sagemaker/events": "./lib/services/aws-sagemaker/events.js",
489490
"./aws_sagemaker/mixins": "./lib/services/aws-sagemaker/mixins.js",
490491
"./aws_sam": "./lib/services/aws-sam/index.js",
491492
"./aws_sam/mixins": "./lib/services/aws-sam/mixins.js",

packages/@aws-cdk/mixins-preview/scripts/spec2eventbridge/builder.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ import { LibraryBuilder } from '@aws-cdk/spec2cdk/lib/cdk/library-builder';
99
import type { LocatedModule, ServiceSubmoduleProps } from '@aws-cdk/spec2cdk/lib/cdk/service-submodule';
1010
import { BaseServiceSubmodule } from '@aws-cdk/spec2cdk/lib/cdk/service-submodule';
1111
import { eventNamespaceName } from '@aws-cdk/spec2cdk/lib/naming';
12-
import type { ReferenceProp } from '@aws-cdk/spec2cdk/lib/cdk/reference-props';
13-
import { getReferenceProps } from '@aws-cdk/spec2cdk/lib/cdk/reference-props';
12+
import { ResourceReference, type ReferenceProp } from '@aws-cdk/spec2cdk/lib/cdk/reference-props';
1413
import { log } from '@aws-cdk/spec2cdk/lib/util';
1514

1615
/**
@@ -136,7 +135,7 @@ class EventBridgeEventsClass extends ClassType {
136135

137136
this.refInterface = Type.fromName(constructLibModule, naming.referenceInterfaceName(resource.name));
138137
this.referenceName = naming.referenceInterfaceAttributeName(resource.name);
139-
this.referenceProps = getReferenceProps(resource);
138+
this.referenceProps = new ResourceReference(resource).referenceProps;
140139
}
141140

142141
public build() {

packages/@aws-cdk/mixins-preview/scripts/spec2logs/builder.ts

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,7 @@ import { BaseServiceSubmodule, relativeImportPath } from '@aws-cdk/spec2cdk/lib/
99
import type { AddServiceProps, LibraryBuilderProps } from '@aws-cdk/spec2cdk/lib/cdk/library-builder';
1010
import { LibraryBuilder } from '@aws-cdk/spec2cdk/lib/cdk/library-builder';
1111
import { MIXINS_CORE } from '../spec2mixins/helpers';
12-
13-
// we cannot currently get an Arn for these
14-
const EXCLUDE: string[] = [
15-
'AWS::BedrockAgentCore::Runtime',
16-
'AWS::ElastiCache::CacheCluster',
17-
'AWS::Grafana::Workspace',
18-
'AWS::RUM::AppMonitor',
19-
'AWS::SageMaker::Workteam',
20-
];
12+
import { ResourceReference } from '@aws-cdk/spec2cdk/lib/cdk/reference-props';
2113

2214
class LogsDeliveryBuilderServiceModule extends BaseServiceSubmodule {
2315
public readonly constructLibModule: ExternalModule;
@@ -47,7 +39,8 @@ export class LogsDeliveryBuilder extends LibraryBuilder<LogsDeliveryBuilderServi
4739
}
4840

4941
protected addResourceToSubmodule(submodule: LogsDeliveryBuilderServiceModule, resource: Resource, _props?: AddServiceProps): void {
50-
if (resource.vendedLogs && !EXCLUDE.includes(resource.cloudFormationType)) {
42+
const resourceReference = new ResourceReference(resource);
43+
if (resource.vendedLogs && resourceReference.hasArnGetter) {
5144
const service = this.db.incoming('hasResource', resource).only().entity;
5245
const logsModule = this.obtainLogsDeliveryModule(submodule, service);
5346

packages/@aws-cdk/mixins-preview/test/codegen/logs-delivery.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ test('Logs Delivery Mixin for a resource', () => {
3131
},
3232
},
3333
attributes: {
34-
SomethingArn: {
34+
ThingArn: {
3535
type: { type: 'string' },
3636
documentation: 'The arn for something',
3737
},

packages/@aws-cdk/mixins-preview/test/events/l1-l2.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ describe.each([
5656
const asgEvents = AutoScalingGroupEvents.fromAutoScalingGroup(new class extends Construct {
5757
public readonly autoScalingGroupRef: AutoScalingGroupReference = {
5858
autoScalingGroupName: 'asdf',
59+
autoScalingGroupArn: 'arn:aws:autoscaling:us-west-2:123456789012:autoScalingGroup:1a2b3c4d-5e6f-7a8b-9c0d-123456789012:autoScalingGroupName/MyAutoScalingGroup',
5960
};
6061
public readonly env = { account: '11111111111', region: 'us-east-1' };
6162
}(stack, 'Group'));

0 commit comments

Comments
 (0)