Commit 6be7b4b
authored
feat(core): cfn constructs (L1s) can now accept constructs as parameters for known resource relationships (#35838)
### Issue # (if applicable)
Closes #<issue number here>.
### Reason for this change
Reintroduces #35713
### Description of changes
#### This generates code that looks like this for non nested properties:
In the properties:
`readonly role: IamIRoleRef | string;`
This is then used in the constructor:
```
this.role = (props.role as IamIRoleRef)?.roleRef?.roleArn ?? cdk.ensureStringOrUndefined(props.role, "role", "iam.IRoleRef | string");
```
If there were multiple possible IxxRef:
```
"targetArn": (props.targetArn as SqsIQueueRef)?.queueRef?.queueArn ?? (props.targetArn as SnsITopicRef)?.topicRef?.topicArn ?? cdk.ensureStringOrUndefined(props.targetArn, "targetArn", "sqs.IQueueRef | sns.ITopicRef | string")
```
#### For arrays
```
this.layers = (props.layers?.forEach((item: ILayerVersionRef | string, i: number, arr: Array<ILayerVersionRef | string>) => { arr[i] = (item as ILayerVersionRef)?.layerVersionRef?.layerVersionArn ?? cdk.ensureStringOrUndefined(item, "layers", "lambda.ILayerVersionRef | string"); }), props.layers as Array<string>);
```
### Nested properties are currently disabled as they are backwards incompatible in the state of this PR
#### For nested properties
The props behave the same way, "flatten" functions are generated to recursively perform the same role that was done in the constructor for non nested properties:
```
function flattenCfnFunctionCodeProperty(props: CfnFunction.CodeProperty | cdk.IResolvable): CfnFunction.CodeProperty | cdk.IResolvable {
if (cdk.isResolvableObject(props)) return props;
return {
"imageUri": props.imageUri,
"s3Bucket": (props.s3Bucket as S3IBucketRef)?.bucketRef?.bucketName ?? cdk.ensureStringOrUndefined(props.s3Bucket, "s3Bucket", "s3.IBucketRef | string"),
"s3Key": props.s3Key,
"s3ObjectVersion": props.s3ObjectVersion,
"sourceKmsKeyArn": props.sourceKmsKeyArn,
"zipFile": props.zipFile
};
}
```
#### For arrays of nested props:
```
(cdk.isResolvableObject(props.fileSystemConfigs) ? props.fileSystemConfigs : (!props.fileSystemConfigs ? undefined : props.fileSystemConfigs.forEach((item: any, i: number, arr: any[]) => { arr[i] = flattenCfnFunctionFileSystemConfigProperty(item) }), props.fileSystemConfigs));
```
### Description of how you validated changes
- Checked the diffs between the previously generated code and the new one.
- Added snapshot tests
- Added unit tests for lambda
- Deployed a stack manually consisting of mixes of L1 and L2 resources using the new capabilities this PR adds
### 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 f9a894f commit 6be7b4b
File tree
9 files changed
+1934
-61
lines changed- packages
- @aws-cdk/mixins-preview/scripts/spec2mixins
- aws-cdk-lib/aws-lambda/test
- tools/@aws-cdk/spec2cdk
- lib/cdk
- test
- __snapshots__
9 files changed
+1934
-61
lines changedLines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
127 | 127 | | |
128 | 128 | | |
129 | 129 | | |
130 | | - | |
| 130 | + | |
131 | 131 | | |
132 | 132 | | |
133 | 133 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5046 | 5046 | | |
5047 | 5047 | | |
5048 | 5048 | | |
| 5049 | + | |
| 5050 | + | |
| 5051 | + | |
| 5052 | + | |
5049 | 5053 | | |
5050 | 5054 | | |
5051 | 5055 | | |
| |||
5107 | 5111 | | |
5108 | 5112 | | |
5109 | 5113 | | |
| 5114 | + | |
| 5115 | + | |
| 5116 | + | |
| 5117 | + | |
| 5118 | + | |
| 5119 | + | |
| 5120 | + | |
| 5121 | + | |
| 5122 | + | |
| 5123 | + | |
| 5124 | + | |
| 5125 | + | |
| 5126 | + | |
| 5127 | + | |
| 5128 | + | |
| 5129 | + | |
| 5130 | + | |
| 5131 | + | |
| 5132 | + | |
| 5133 | + | |
| 5134 | + | |
| 5135 | + | |
| 5136 | + | |
| 5137 | + | |
| 5138 | + | |
| 5139 | + | |
| 5140 | + | |
| 5141 | + | |
| 5142 | + | |
| 5143 | + | |
| 5144 | + | |
| 5145 | + | |
| 5146 | + | |
| 5147 | + | |
| 5148 | + | |
| 5149 | + | |
| 5150 | + | |
| 5151 | + | |
| 5152 | + | |
| 5153 | + | |
| 5154 | + | |
| 5155 | + | |
| 5156 | + | |
| 5157 | + | |
| 5158 | + | |
| 5159 | + | |
| 5160 | + | |
| 5161 | + | |
| 5162 | + | |
| 5163 | + | |
| 5164 | + | |
| 5165 | + | |
| 5166 | + | |
| 5167 | + | |
| 5168 | + | |
| 5169 | + | |
| 5170 | + | |
| 5171 | + | |
| 5172 | + | |
| 5173 | + | |
| 5174 | + | |
| 5175 | + | |
| 5176 | + | |
| 5177 | + | |
| 5178 | + | |
| 5179 | + | |
| 5180 | + | |
| 5181 | + | |
| 5182 | + | |
| 5183 | + | |
| 5184 | + | |
| 5185 | + | |
| 5186 | + | |
| 5187 | + | |
| 5188 | + | |
| 5189 | + | |
| 5190 | + | |
| 5191 | + | |
| 5192 | + | |
| 5193 | + | |
| 5194 | + | |
| 5195 | + | |
| 5196 | + | |
| 5197 | + | |
| 5198 | + | |
| 5199 | + | |
| 5200 | + | |
| 5201 | + | |
| 5202 | + | |
| 5203 | + | |
| 5204 | + | |
| 5205 | + | |
| 5206 | + | |
| 5207 | + | |
| 5208 | + | |
| 5209 | + | |
| 5210 | + | |
| 5211 | + | |
5110 | 5212 | | |
5111 | 5213 | | |
5112 | 5214 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
182 | 182 | | |
183 | 183 | | |
184 | 184 | | |
185 | | - | |
186 | | - | |
187 | | - | |
188 | | - | |
189 | | - | |
190 | | - | |
191 | | - | |
192 | 185 | | |
193 | 186 | | |
194 | 187 | | |
| |||
262 | 255 | | |
263 | 256 | | |
264 | 257 | | |
265 | | - | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
266 | 267 | | |
267 | 268 | | |
268 | 269 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | | - | |
9 | | - | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
10 | 21 | | |
11 | 22 | | |
12 | 23 | | |
| |||
30 | 41 | | |
31 | 42 | | |
32 | 43 | | |
33 | | - | |
| 44 | + | |
34 | 45 | | |
35 | 46 | | |
36 | 47 | | |
| |||
61 | 72 | | |
62 | 73 | | |
63 | 74 | | |
64 | | - | |
| 75 | + | |
65 | 76 | | |
66 | 77 | | |
67 | 78 | | |
| |||
135 | 146 | | |
136 | 147 | | |
137 | 148 | | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
138 | 152 | | |
139 | 153 | | |
140 | 154 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
| 4 | + | |
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| |||
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
31 | | - | |
| 31 | + | |
| 32 | + | |
32 | 33 | | |
33 | 34 | | |
34 | 35 | | |
| |||
37 | 38 | | |
38 | 39 | | |
39 | 40 | | |
40 | | - | |
41 | | - | |
42 | | - | |
43 | | - | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
44 | 46 | | |
45 | | - | |
46 | | - | |
47 | | - | |
48 | | - | |
49 | | - | |
50 | | - | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
51 | 54 | | |
52 | 55 | | |
53 | 56 | | |
| |||
80 | 83 | | |
81 | 84 | | |
82 | 85 | | |
83 | | - | |
84 | | - | |
| 86 | + | |
| 87 | + | |
85 | 88 | | |
86 | 89 | | |
87 | 90 | | |
| |||
93 | 96 | | |
94 | 97 | | |
95 | 98 | | |
96 | | - | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
97 | 102 | | |
98 | 103 | | |
99 | 104 | | |
| |||
118 | 123 | | |
119 | 124 | | |
120 | 125 | | |
121 | | - | |
| 126 | + | |
122 | 127 | | |
123 | 128 | | |
124 | 129 | | |
125 | | - | |
| 130 | + | |
126 | 131 | | |
127 | 132 | | |
128 | 133 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
106 | 106 | | |
107 | 107 | | |
108 | 108 | | |
109 | | - | |
| 109 | + | |
110 | 110 | | |
111 | 111 | | |
112 | 112 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
41 | | - | |
| 41 | + | |
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
| |||
0 commit comments