Skip to content

Commit de7d825

Browse files
authored
fix(events): archive construct does not have defaultChild set (#21345)
Fixes #21263 Adds id 'Default' to CfnArchive in Archive construct. ---- ### All Submissions: * [x] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) ### Adding new Unconventional Dependencies: * [ ] This PR adds new unconventional dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md/#adding-new-unconventional-dependencies) ### New Features * [ ] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/main/INTEGRATION_TESTS.md)? * [ ] Did you use `yarn integ` to deploy the infrastructure and generate the snapshot (i.e. `yarn integ` without `--dry-run`)? *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 92b2c84 commit de7d825

File tree

10 files changed

+240
-0
lines changed

10 files changed

+240
-0
lines changed

packages/@aws-cdk/aws-events/lib/archive.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,5 +74,6 @@ export class Archive extends Resource {
7474

7575
this.archiveArn = archive.attrArn;
7676
this.archiveName = archive.attrArchiveName;
77+
this.node.defaultChild = archive;
7778
}
7879
}

packages/@aws-cdk/aws-events/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@
8585
"@aws-cdk/assertions": "0.0.0",
8686
"@aws-cdk/cdk-build-tools": "0.0.0",
8787
"@aws-cdk/cfn2ts": "0.0.0",
88+
"@aws-cdk/integ-runner": "0.0.0",
89+
"@aws-cdk/integ-tests": "0.0.0",
8890
"@aws-cdk/pkglint": "0.0.0",
8991
"@types/jest": "^27.5.2",
9092
"jest": "^27.5.1"
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"version": "20.0.0",
3+
"files": {
4+
"c328ab321c3d5fd5f5a82abed4520136f53bd07785ecd2a382c66fc17090bb0d": {
5+
"source": {
6+
"path": "IntegStack.template.json",
7+
"packaging": "file"
8+
},
9+
"destinations": {
10+
"current_account-current_region": {
11+
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
12+
"objectKey": "c328ab321c3d5fd5f5a82abed4520136f53bd07785ecd2a382c66fc17090bb0d.json",
13+
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
14+
}
15+
}
16+
}
17+
},
18+
"dockerImages": {}
19+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"Resources": {
3+
"EventBridgeF6D0CF9D": {
4+
"Type": "AWS::Events::EventBus",
5+
"Properties": {
6+
"Name": "IntegStackEventBridgeF828A2C9"
7+
}
8+
},
9+
"MyCustomArchive": {
10+
"Type": "AWS::Events::Archive",
11+
"Properties": {
12+
"SourceArn": {
13+
"Fn::GetAtt": [
14+
"EventBridgeF6D0CF9D",
15+
"Arn"
16+
]
17+
},
18+
"EventPattern": {
19+
"account": [
20+
{
21+
"Ref": "AWS::AccountId"
22+
}
23+
]
24+
},
25+
"RetentionDays": 0
26+
}
27+
}
28+
}
29+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"version":"20.0.0"}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"version": "20.0.0",
3+
"testCases": {
4+
"integ.archive": {
5+
"stacks": [
6+
"IntegStack"
7+
],
8+
"diffAssets": false,
9+
"stackUpdateWorkflow": true
10+
}
11+
},
12+
"synthContext": {},
13+
"enableLookups": false
14+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
{
2+
"version": "20.0.0",
3+
"artifacts": {
4+
"Tree": {
5+
"type": "cdk:tree",
6+
"properties": {
7+
"file": "tree.json"
8+
}
9+
},
10+
"IntegStack": {
11+
"type": "aws:cloudformation:stack",
12+
"environment": "aws://unknown-account/unknown-region",
13+
"properties": {
14+
"templateFile": "IntegStack.template.json",
15+
"validateOnSynth": false
16+
},
17+
"metadata": {
18+
"/IntegStack/EventBridge/Resource": [
19+
{
20+
"type": "aws:cdk:logicalId",
21+
"data": "EventBridgeF6D0CF9D"
22+
}
23+
],
24+
"/IntegStack/Archive/Archive": [
25+
{
26+
"type": "aws:cdk:logicalId",
27+
"data": "MyCustomArchive"
28+
}
29+
],
30+
"Archive4DBC1EC9": [
31+
{
32+
"type": "aws:cdk:logicalId",
33+
"data": "Archive4DBC1EC9",
34+
"trace": [
35+
"!!DESTRUCTIVE_CHANGES: WILL_DESTROY"
36+
]
37+
}
38+
]
39+
},
40+
"displayName": "IntegStack"
41+
}
42+
}
43+
}
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
{
2+
"version": "tree-0.1",
3+
"tree": {
4+
"id": "App",
5+
"path": "",
6+
"children": {
7+
"Tree": {
8+
"id": "Tree",
9+
"path": "Tree",
10+
"constructInfo": {
11+
"fqn": "constructs.Construct",
12+
"version": "10.1.58"
13+
}
14+
},
15+
"IntegStack": {
16+
"id": "IntegStack",
17+
"path": "IntegStack",
18+
"children": {
19+
"EventBridge": {
20+
"id": "EventBridge",
21+
"path": "IntegStack/EventBridge",
22+
"children": {
23+
"Resource": {
24+
"id": "Resource",
25+
"path": "IntegStack/EventBridge/Resource",
26+
"attributes": {
27+
"aws:cdk:cloudformation:type": "AWS::Events::EventBus",
28+
"aws:cdk:cloudformation:props": {
29+
"name": "IntegStackEventBridgeF828A2C9"
30+
}
31+
},
32+
"constructInfo": {
33+
"fqn": "@aws-cdk/aws-events.CfnEventBus",
34+
"version": "0.0.0"
35+
}
36+
}
37+
},
38+
"constructInfo": {
39+
"fqn": "@aws-cdk/aws-events.EventBus",
40+
"version": "0.0.0"
41+
}
42+
},
43+
"Archive": {
44+
"id": "Archive",
45+
"path": "IntegStack/Archive",
46+
"children": {
47+
"Archive": {
48+
"id": "Archive",
49+
"path": "IntegStack/Archive/Archive",
50+
"attributes": {
51+
"aws:cdk:cloudformation:type": "AWS::Events::Archive",
52+
"aws:cdk:cloudformation:props": {
53+
"sourceArn": {
54+
"Fn::GetAtt": [
55+
"EventBridgeF6D0CF9D",
56+
"Arn"
57+
]
58+
},
59+
"eventPattern": {
60+
"account": [
61+
{
62+
"Ref": "AWS::AccountId"
63+
}
64+
]
65+
},
66+
"retentionDays": 0
67+
}
68+
},
69+
"constructInfo": {
70+
"fqn": "@aws-cdk/aws-events.CfnArchive",
71+
"version": "0.0.0"
72+
}
73+
}
74+
},
75+
"constructInfo": {
76+
"fqn": "@aws-cdk/aws-events.Archive",
77+
"version": "0.0.0"
78+
}
79+
}
80+
},
81+
"constructInfo": {
82+
"fqn": "@aws-cdk/core.Stack",
83+
"version": "0.0.0"
84+
}
85+
}
86+
},
87+
"constructInfo": {
88+
"fqn": "@aws-cdk/core.App",
89+
"version": "0.0.0"
90+
}
91+
}
92+
}

packages/@aws-cdk/aws-events/test/archive.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,20 @@ describe('archive', () => {
7777
},
7878
});
7979
});
80+
81+
test('should have defined defaultChild', () => {
82+
const stack = new Stack();
83+
84+
const eventBus = new EventBus(stack, 'Bus');
85+
86+
const archive = new Archive(stack, 'Archive', {
87+
sourceEventBus: eventBus,
88+
eventPattern: {
89+
account: [stack.account],
90+
},
91+
retention: Duration.days(10),
92+
});
93+
94+
expect(archive.node.defaultChild).toBe(archive.node.findChild('Archive'));
95+
});
8096
});
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { App, Stack } from '@aws-cdk/core';
2+
import { IntegTest } from '@aws-cdk/integ-tests';
3+
import { Archive, CfnArchive, EventBus } from '../lib';
4+
5+
const app = new App();
6+
7+
const stack = new Stack(app, 'IntegStack');
8+
9+
const eventBus = new EventBus(stack, 'EventBridge');
10+
11+
const archive = new Archive(stack, 'Archive', {
12+
sourceEventBus: eventBus,
13+
eventPattern: {
14+
account: [stack.account],
15+
},
16+
});
17+
(archive.node.defaultChild as CfnArchive).overrideLogicalId('MyCustomArchive');
18+
19+
new IntegTest(app, 'ArchiveTest', {
20+
testCases: [stack],
21+
});
22+
23+
app.synth();

0 commit comments

Comments
 (0)