Skip to content

Commit 0bce2f0

Browse files
authored
revert(ec2): update PrefixList.fromLookup() to expect the result from CcApi context provider has exactly one resource (#34557)
Reverts #34199
1 parent b420033 commit 0bce2f0

File tree

5 files changed

+30
-17
lines changed

5 files changed

+30
-17
lines changed

packages/@aws-cdk/cx-api/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,12 @@
8282
"semver": "^7.7.2"
8383
},
8484
"peerDependencies": {
85-
"@aws-cdk/cloud-assembly-schema": ">=43.6.0"
85+
"@aws-cdk/cloud-assembly-schema": ">=41.0.0"
8686
},
8787
"license": "Apache-2.0",
8888
"devDependencies": {
8989
"@aws-cdk/cdk-build-tools": "0.0.0",
90-
"@aws-cdk/cloud-assembly-schema": "^43.6.0",
90+
"@aws-cdk/cloud-assembly-schema": "^41.2.0",
9191
"@aws-cdk/pkglint": "0.0.0",
9292
"@types/jest": "^29.5.14",
9393
"@types/mock-fs": "^4.13.4",

packages/aws-cdk-lib/aws-ec2/lib/prefix-list.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,14 +148,15 @@ export class PrefixList extends PrefixListBase {
148148
...(options.addressFamily ? { AddressFamily: options.addressFamily } : undefined),
149149
},
150150
propertiesToReturn: ['PrefixListId'],
151-
expectedMatchCount: 'exactly-one',
152151
} satisfies Omit<cxschema.CcApiContextQuery, 'account'|'region'>,
153152
dummyValue: [dummyResponse] satisfies PrefixListContextResponse[],
154153
}).value;
155154

156155
// getValue returns a list of result objects. We are expecting 1 result or Error.
157-
if (response.length !== 1) {
158-
throw new ValidationError('Unexpected response received from the context provider. Please clear out the context key using `cdk context --remove` and try again.', scope);
156+
if (response.length === 0) {
157+
throw new ValidationError(`Could not find any managed prefix lists matching ${JSON.stringify(options)}`, scope);
158+
} else if (response.length > 1) {
159+
throw new ValidationError(`Found ${response.length} managed prefix lists matching ${JSON.stringify(options)}; please narrow the search criteria`, scope);
159160
}
160161

161162
const prefixList = response[0];

packages/aws-cdk-lib/aws-ec2/test/prefix-list.test.ts

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,6 @@ describe('prefix list', () => {
130130
PrefixListName: 'com.amazonaws.us-east-1.testprefixlist',
131131
},
132132
propertiesToReturn: ['PrefixListId'],
133-
expectedMatchCount: 'exactly-one',
134133
},
135134
dummyValue: [
136135
{ PrefixListId: 'pl-xxxxxxxx' },
@@ -165,7 +164,6 @@ describe('prefix list', () => {
165164
AddressFamily: 'IPv6',
166165
},
167166
propertiesToReturn: ['PrefixListId'],
168-
expectedMatchCount: 'exactly-one',
169167
},
170168
dummyValue: [
171169
{ PrefixListId: 'pl-xxxxxxxx' },
@@ -184,11 +182,9 @@ describe('prefix list', () => {
184182
}).toThrow('All arguments to look up a managed prefix list must be concrete (no Tokens)');
185183
});
186184

187-
test.each([
188-
[[]],
189-
[[{ PrefixListId: 'pl-xxxxxxxx' }, { PrefixListId: 'pl-yyyyyyyy' }]],
190-
])('fromLookup throws for unexpected result', (resultObjs) => {
185+
test('fromLookup throws if not found', () => {
191186
// GIVEN
187+
const resultObjs = [];
192188
jest.spyOn(ContextProvider, 'getValue').mockReturnValue({ value: resultObjs });
193189

194190
// WHEN
@@ -199,6 +195,22 @@ describe('prefix list', () => {
199195
PrefixList.fromLookup(stack, 'PrefixList', {
200196
prefixListName: 'com.amazonaws.us-east-1.missingprefixlist',
201197
});
202-
}).toThrow('Unexpected response received from the context provider.');
198+
}).toThrow('Could not find any managed prefix lists matching');
199+
});
200+
201+
test('fromLookup throws if multiple resources found', () => {
202+
// GIVEN
203+
const resultObjs = [{ PrefixListId: 'pl-xxxxxxxx' }, { PrefixListId: 'pl-yyyyyyyy' }];
204+
jest.spyOn(ContextProvider, 'getValue').mockReturnValue({ value: resultObjs });
205+
206+
// WHEN
207+
const stack = new Stack(undefined, undefined, { env: { region: 'us-east-1', account: '123456789012' } });
208+
209+
// THEN
210+
expect(() => {
211+
PrefixList.fromLookup(stack, 'PrefixList', {
212+
prefixListName: 'com.amazonaws.us-east-1.missingprefixlist',
213+
});
214+
}).toThrow('Found 2 managed prefix lists matching');
203215
});
204216
});

packages/aws-cdk-lib/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@
121121
"dependencies": {
122122
"@aws-cdk/asset-awscli-v1": "2.2.237",
123123
"@aws-cdk/asset-node-proxy-agent-v6": "^2.1.0",
124-
"@aws-cdk/cloud-assembly-schema": "^43.6.0",
124+
"@aws-cdk/cloud-assembly-schema": "^41.2.0",
125125
"@balena/dockerignore": "^1.0.2",
126126
"case": "1.6.3",
127127
"fs-extra": "^11.3.0",

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,10 @@
7474
"@aws-cdk/service-spec-types" "^0.0.141"
7575
"@cdklabs/tskb" "^0.0.3"
7676

77-
"@aws-cdk/cloud-assembly-schema@^43.6.0":
78-
version "43.9.0"
79-
resolved "https://registry.npmjs.org/@aws-cdk/cloud-assembly-schema/-/cloud-assembly-schema-43.9.0.tgz#795c491f703c0faa71b4c97a888086a54614b2d4"
80-
integrity sha512-S6fiiNGSRoTqCnpAH3mXV52Ssj6i+eUB6LSKYqGdKqzrgGkyvR/acurMGYtCJt5gsf3uZ+5J6utYs2X6dcg8Vw==
77+
"@aws-cdk/cloud-assembly-schema@^41.2.0":
78+
version "41.2.0"
79+
resolved "https://registry.npmjs.org/@aws-cdk/cloud-assembly-schema/-/cloud-assembly-schema-41.2.0.tgz#c1ef513e1cc0528dbc05948ae39d5631306af423"
80+
integrity sha512-JaulVS6z9y5+u4jNmoWbHZRs9uGOnmn/ktXygNWKNu1k6lF3ad4so3s18eRu15XCbUIomxN9WPYT6Ehh7hzONw==
8181
dependencies:
8282
jsonschema "~1.4.1"
8383
semver "^7.7.1"

0 commit comments

Comments
 (0)