Commit 8c70b53
feat(cli): can ignore errors and return dummy value in CloudControl API context provider (#211)
CDK app with CC API Context Provider fails if the resource we want to
get doesn't exist.
```
[Error at /LookupStack] Encountered CC API error while getting resource MyLookupTestRole. Error: ResourceNotFoundException: AWS::IAM::Role Handler returned status FAILED: The role with name MyLookupTestRole cannot be found. (Service: Iam, Status Code: 404, Request ID: xxxx-xxx-xxxx-xxxx) (HandlerErrorCode: NotFound, RequestToken: xxxx-xxx-xxxx-xxxx)
```
Also CC API Context Provider (`CcApiContextProviderPlugin`) cannot
ignore errors even if `ignoreErrorOnMissingContext` is passed in
aws-cdk-lib because the current code in aws-cdk-**cli** doesn't handle
the property.
Sample cdk-lib code (based on my
[PR](aws/aws-cdk#33603) for IAM Role
fromLookup):
```ts
const response: {[key: string]: any}[] = ContextProvider.getValue(scope, {
provider: cxschema.ContextProvider.CC_API_PROVIDER,
props: {
typeName: 'AWS::IAM::Role',
exactIdentifier: options.roleName,
propertiesToReturn: [
'Arn',
],
} as cxschema.CcApiContextQuery,
dummyValue: [
{
// eslint-disable-next-line @cdklabs/no-literal-partition
Arn: 'arn:aws:iam::123456789012:role/DUMMY_ARN',
},
],
ignoreErrorOnMissingContext: options.returnDummyRoleOnMissing, // added
}).value;
```
However it would be good if the provider can ignore errors and return
any dummy value to cdk library. This allows all resources to be **used
if available, or created if not.**
Actually, SSM and KMS provider can ignore errors:
KMS:
https://github.com/aws/aws-cdk-cli/blob/main/packages/aws-cdk/lib/context-providers/keys.ts#L43-L48
SSM:
https://github.com/aws/aws-cdk-cli/blob/main/packages/aws-cdk/lib/context-providers/ssm-parameters.ts#L27-L30
For example, in cdk-lib, we can specify
[ignoreErrorOnMissingContext](https://github.com/aws/aws-cdk/blob/v2.182.0/packages/aws-cdk-lib/aws-kms/lib/key.ts#L741-L744)
in the `fromLookup`. The `dummyValue` and `ignoreErrorOnMissingContext`
properties can also be specified in
[GetContextValueOptions](https://github.com/go-to-k/aws-cdk/blob/45a276fd0fc9b7b08f69f7faf3d0091796ab1663/packages/aws-cdk-lib/core/lib/context-provider.ts#L31-L45).
## cli-integ
aws/aws-cdk-cli-testing#50
---
By submitting this pull request, I confirm that my contribution is made
under the terms of the Apache-2.0 license
---------
Co-authored-by: Rico Hermans <rix0rrr@gmail.com>1 parent 1f880a5 commit 8c70b53
File tree
5 files changed
+412
-113
lines changed- packages
- @aws-cdk/cloud-assembly-schema
- lib/cloud-assembly
- schema
- aws-cdk
- lib/context-providers
- test/context-providers
5 files changed
+412
-113
lines changedLines changed: 63 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
365 | 365 | | |
366 | 366 | | |
367 | 367 | | |
368 | | - | |
369 | | - | |
370 | | - | |
371 | | - | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
372 | 374 | | |
373 | 375 | | |
374 | 376 | | |
375 | 377 | | |
376 | | - | |
377 | | - | |
| 378 | + | |
| 379 | + | |
378 | 380 | | |
379 | | - | |
380 | | - | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
381 | 391 | | |
382 | 392 | | |
383 | 393 | | |
384 | 394 | | |
385 | 395 | | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
386 | 413 | | |
387 | 414 | | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
388 | 443 | | |
389 | 444 | | |
390 | 445 | | |
| |||
Lines changed: 11 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1032 | 1032 | | |
1033 | 1033 | | |
1034 | 1034 | | |
1035 | | - | |
| 1035 | + | |
1036 | 1036 | | |
1037 | 1037 | | |
1038 | 1038 | | |
1039 | | - | |
| 1039 | + | |
1040 | 1040 | | |
1041 | 1041 | | |
1042 | 1042 | | |
1043 | | - | |
| 1043 | + | |
1044 | 1044 | | |
1045 | 1045 | | |
1046 | 1046 | | |
1047 | 1047 | | |
1048 | 1048 | | |
| 1049 | + | |
| 1050 | + | |
| 1051 | + | |
| 1052 | + | |
| 1053 | + | |
| 1054 | + | |
| 1055 | + | |
| 1056 | + | |
1049 | 1057 | | |
1050 | 1058 | | |
1051 | 1059 | | |
| |||
Lines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
3 | | - | |
| 2 | + | |
| 3 | + | |
4 | 4 | | |
Lines changed: 104 additions & 70 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
| 2 | + | |
| 3 | + | |
2 | 4 | | |
3 | 5 | | |
4 | 6 | | |
| |||
11 | 13 | | |
12 | 14 | | |
13 | 15 | | |
14 | | - | |
15 | | - | |
16 | | - | |
17 | | - | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
18 | 19 | | |
19 | 20 | | |
20 | | - | |
21 | | - | |
22 | | - | |
23 | | - | |
24 | | - | |
25 | | - | |
26 | | - | |
| 21 | + | |
27 | 22 | | |
28 | | - | |
| 23 | + | |
29 | 24 | | |
30 | | - | |
31 | | - | |
| 25 | + | |
| 26 | + | |
32 | 27 | | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
33 | 34 | | |
34 | | - | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | | - | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
40 | 54 | | |
41 | 55 | | |
42 | 56 | | |
43 | 57 | | |
44 | 58 | | |
45 | 59 | | |
46 | 60 | | |
47 | | - | |
48 | | - | |
| 61 | + | |
49 | 62 | | |
50 | 63 | | |
51 | 64 | | |
52 | 65 | | |
53 | 66 | | |
54 | | - | |
55 | | - | |
56 | | - | |
| 67 | + | |
57 | 68 | | |
58 | 69 | | |
59 | 70 | | |
60 | 71 | | |
61 | 72 | | |
62 | | - | |
63 | | - | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
| 73 | + | |
| 74 | + | |
69 | 75 | | |
70 | | - | |
71 | | - | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
72 | 86 | | |
73 | | - | |
74 | 87 | | |
75 | 88 | | |
76 | 89 | | |
77 | 90 | | |
78 | 91 | | |
79 | 92 | | |
80 | | - | |
81 | | - | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
82 | 96 | | |
83 | 97 | | |
84 | 98 | | |
85 | 99 | | |
86 | 100 | | |
87 | | - | |
88 | | - | |
89 | | - | |
90 | | - | |
| 101 | + | |
91 | 102 | | |
92 | 103 | | |
93 | 104 | | |
94 | | - | |
95 | | - | |
96 | | - | |
97 | | - | |
98 | | - | |
99 | | - | |
100 | | - | |
101 | | - | |
102 | | - | |
103 | | - | |
104 | | - | |
105 | | - | |
106 | | - | |
107 | | - | |
108 | | - | |
109 | | - | |
110 | | - | |
111 | | - | |
112 | | - | |
113 | | - | |
114 | | - | |
115 | 105 | | |
116 | | - | |
117 | | - | |
118 | | - | |
119 | | - | |
120 | | - | |
121 | 106 | | |
122 | | - | |
123 | | - | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
124 | 122 | | |
125 | | - | |
126 | 123 | | |
127 | 124 | | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
0 commit comments