Skip to content

Commit 084b736

Browse files
authored
fix(bedrock-agentcore-alpha): fix unexpected validation error when properties are Token (#35978)
### Issue # (if applicable) N/A ### Reason for this change Some Validation logics were throwing unexpected errors when properties are defined as CDK `Token` types. `string` or `number` may be `Token`. ### Description of changes - Added `Token` type checking before property validation - Added test cases for `Token` properties to verify not throwing errors. ### Describe any new or updated permissions being added N/A ### Description of how you validated changes Added unit tests to verify `Token` properties bypass validation ### 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 689ad05 commit 084b736

File tree

4 files changed

+52
-3
lines changed

4 files changed

+52
-3
lines changed

packages/@aws-cdk/aws-bedrock-agentcore-alpha/agentcore/memory/memory.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
* and limitations under the License.
1212
*/
1313

14-
import { Arn, ArnFormat, Duration, IResource, Lazy, Resource } from 'aws-cdk-lib';
14+
import { Arn, ArnFormat, Duration, IResource, Lazy, Resource, Token } from 'aws-cdk-lib';
1515
import { IConstruct, Construct } from 'constructs';
1616
import * as bedrockagentcore from 'aws-cdk-lib/aws-bedrockagentcore';
1717
import { CfnMemory, CfnMemoryProps } from 'aws-cdk-lib/aws-bedrockagentcore';
@@ -828,6 +828,10 @@ export class Memory extends MemoryBase {
828828
private _validateMemoryExpirationDays = (expirationDays: number): string[] => {
829829
let errors: string[] = [];
830830

831+
if (Token.isUnresolved(expirationDays)) {
832+
return errors;
833+
}
834+
831835
if (expirationDays < MEMORY_EXPIRATION_DAYS_MIN || expirationDays > MEMORY_EXPIRATION_DAYS_MAX) {
832836
errors.push(`Memory expiration days must be between ${MEMORY_EXPIRATION_DAYS_MIN} and ${MEMORY_EXPIRATION_DAYS_MAX}`);
833837
}

packages/@aws-cdk/aws-bedrock-agentcore-alpha/agentcore/runtime/runtime-authorizer-configuration.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
import { CfnRuntime } from 'aws-cdk-lib/aws-bedrockagentcore';
1515
import { ValidationError } from './validation-helpers';
16+
import { Token } from 'aws-cdk-lib';
1617
import { IUserPool, IUserPoolClient } from 'aws-cdk-lib/aws-cognito';
1718

1819
/**
@@ -44,7 +45,7 @@ export abstract class RuntimeAuthorizerConfiguration {
4445
allowedClients?: string[],
4546
allowedAudience?: string[],
4647
): RuntimeAuthorizerConfiguration {
47-
if (!discoveryUrl.endsWith('/.well-known/openid-configuration')) {
48+
if (!Token.isUnresolved(discoveryUrl) && !discoveryUrl.endsWith('/.well-known/openid-configuration')) {
4849
throw new ValidationError('JWT discovery URL must end with /.well-known/openid-configuration');
4950
}
5051
return new JwtAuthorizerConfiguration(discoveryUrl, allowedClients, allowedAudience);
@@ -81,7 +82,7 @@ export abstract class RuntimeAuthorizerConfiguration {
8182
clientId: string,
8283
allowedAudience?: string[],
8384
): RuntimeAuthorizerConfiguration {
84-
if (!discoveryUrl.endsWith('/.well-known/openid-configuration')) {
85+
if (!Token.isUnresolved(discoveryUrl) && !discoveryUrl.endsWith('/.well-known/openid-configuration')) {
8586
throw new ValidationError('OAuth discovery URL must end with /.well-known/openid-configuration');
8687
}
8788
return new OAuthAuthorizerConfiguration(discoveryUrl, clientId, allowedAudience);

packages/@aws-cdk/aws-bedrock-agentcore-alpha/test/agentcore/memory/memory.test.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,21 @@ describe('Memory expiration duration validation tests', () => {
471471
});
472472
}).not.toThrow();
473473
});
474+
475+
test('does not fail validation if expirationDuration is a late-bound value', () => {
476+
// WHEN
477+
const expirationDuration = new cdk.CfnParameter(stack, 'ExpirationDuration', {
478+
default: 30,
479+
type: 'Number',
480+
});
481+
482+
expect(() => {
483+
new Memory(stack, 'memory-late-bound', {
484+
memoryName: 'memory_late_bound',
485+
expirationDuration: Duration.days(expirationDuration.valueAsNumber),
486+
});
487+
}).not.toThrow();
488+
});
474489
});
475490

476491
describe('Memory with custom strategies tests', () => {

packages/@aws-cdk/aws-bedrock-agentcore-alpha/test/agentcore/runtime/runtime.test.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1154,6 +1154,35 @@ describe('Runtime authentication configuration error cases', () => {
11541154
app.synth();
11551155
expect(runtime.agentRuntimeName).toBe('test_runtime');
11561156
});
1157+
1158+
test('does not fail validation if JWT discovery URL is a late-bound value', () => {
1159+
// WHEN
1160+
const discoveryUrlParam = new cdk.CfnParameter(stack, 'JWTDiscoveryUrl', {
1161+
default: 'https://example.com/.well-known/openid-configuration',
1162+
type: 'String',
1163+
});
1164+
1165+
// THEN
1166+
expect(() => {
1167+
RuntimeAuthorizerConfiguration.usingJWT(discoveryUrlParam.valueAsString);
1168+
}).not.toThrow();
1169+
});
1170+
1171+
test('does not fail validation if OAuth discovery URL is a late-bound value', () => {
1172+
// WHEN
1173+
const discoveryUrlParam = new cdk.CfnParameter(stack, 'OAuthDiscoveryUrl', {
1174+
default: 'https://oauth-provider.com/.well-known/openid-configuration',
1175+
type: 'String',
1176+
});
1177+
1178+
// THEN
1179+
expect(() => {
1180+
RuntimeAuthorizerConfiguration.usingOAuth(
1181+
discoveryUrlParam.valueAsString,
1182+
'oauth-client-123',
1183+
);
1184+
}).not.toThrow();
1185+
});
11571186
});
11581187

11591188
describe('RuntimeNetworkConfiguration tests', () => {

0 commit comments

Comments
 (0)