Skip to content

Commit 50a727d

Browse files
committed
update
1 parent 4375dac commit 50a727d

File tree

30 files changed

+2082
-380
lines changed

30 files changed

+2082
-380
lines changed

packages/@aws-cdk/aws-bedrock-agentcore-alpha/lib/gateway/gateway.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Stack, Token } from 'aws-cdk-lib';
1+
import { Names, Stack, Token } from 'aws-cdk-lib';
22
import * as bedrockagentcore from 'aws-cdk-lib/aws-bedrockagentcore';
33
import * as cognito from 'aws-cdk-lib/aws-cognito';
44
import * as iam from 'aws-cdk-lib/aws-iam';
@@ -685,15 +685,12 @@ export class Gateway extends GatewayBase {
685685
* @internal
686686
*/
687687
private createDefaultCognitoAuthorizerConfig(): IGatewayAuthorizerConfig {
688-
// Create User Pool for M2M authentication
689688
const userPool = new cognito.UserPool(this, 'UserPool', {
690-
userPoolName: `${this.name}-gw-userpool`,
691689
signInCaseSensitive: false,
692690
});
693691

694692
const resourceServer = userPool.addResourceServer('ResourceServer', {
695-
identifier: `${this.name}-gateway-resource-server`,
696-
userPoolResourceServerName: `${this.name}-GatewayResourceServer`,
693+
identifier: Names.uniqueResourceName(this, { maxLength: 256, separator: '-' }),
697694
scopes: [
698695
{
699696
scopeName: 'read',
@@ -707,7 +704,6 @@ export class Gateway extends GatewayBase {
707704
});
708705

709706
const userPoolClient = userPool.addClient('DefaultClient', {
710-
userPoolClientName: `${this.name}-gw-client`,
711707
generateSecret: true,
712708
oAuth: {
713709
flows: {
@@ -727,9 +723,12 @@ export class Gateway extends GatewayBase {
727723
});
728724

729725
// Create Cognito Domain for OAuth2 token endpoint
730-
// Use gateway name as domain prefix (already validated to be alphanumeric with hyphens/underscores)
731-
// Replace underscores with hyphens and convert to lowercase for Cognito domain requirements
732-
const domainPrefix = `${this.name}-gw`.replace(/_/g, '-').toLowerCase();
726+
// Use uniqueResourceName to generate a unique domain prefix toLowerCase() is required because the hash portion is uppercase
727+
const domainPrefix = Names.uniqueResourceName(this, {
728+
maxLength: 63, // Cognito domain prefix max length
729+
separator: '-',
730+
}).toLowerCase();
731+
733732
const userPoolDomain = userPool.addDomain('Domain', {
734733
cognitoDomain: {
735734
domainPrefix: domainPrefix,

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

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2307,3 +2307,39 @@ describe('MCP Server Target Configuration Tests', () => {
23072307
expect(target.credentialProviderConfigurations).toHaveLength(1);
23082308
});
23092309
});
2310+
2311+
describe('Gateway M2M Authentication Tests', () => {
2312+
let stack: cdk.Stack;
2313+
2314+
beforeEach(() => {
2315+
const app = new cdk.App();
2316+
stack = new cdk.Stack(app, 'TestStack', {
2317+
env: { account: '123456789012', region: 'us-east-1' },
2318+
});
2319+
});
2320+
2321+
test('Should create default Cognito authorizer with M2M support', () => {
2322+
new Gateway(stack, 'TestGateway', {
2323+
gatewayName: 'test-gateway',
2324+
});
2325+
2326+
const template = Template.fromStack(stack);
2327+
2328+
template.hasResourceProperties('AWS::Cognito::UserPoolClient', {
2329+
AllowedOAuthFlows: ['client_credentials'],
2330+
AllowedOAuthFlowsUserPoolClient: true,
2331+
GenerateSecret: true,
2332+
});
2333+
2334+
// Resource Server identifier is auto-generated using Names.uniqueResourceName()
2335+
template.hasResourceProperties('AWS::Cognito::UserPoolResourceServer', {
2336+
Scopes: [
2337+
{ ScopeName: 'read', ScopeDescription: 'Read access to gateway tools' },
2338+
{ ScopeName: 'write', ScopeDescription: 'Write access to gateway tools' },
2339+
],
2340+
});
2341+
2342+
// Domain name is auto-generated using Names.uniqueResourceName()
2343+
template.resourceCountIs('AWS::Cognito::UserPoolDomain', 1);
2344+
});
2345+
});

packages/@aws-cdk/aws-bedrock-agentcore-alpha/test/agentcore/gateway/integ.gateway-with-runtime.js.snapshot/BedrockAgentCoreRuntimeGatewayIntegTest.assets.json renamed to packages/@aws-cdk/aws-bedrock-agentcore-alpha/test/agentcore/gateway/integ.gateway-with-runtime-m2m.js.snapshot/BedrockAgentCoreRuntimeGatewayM2MIntegTest.assets.json

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk/aws-bedrock-agentcore-alpha/test/agentcore/gateway/integ.gateway-with-runtime.js.snapshot/BedrockAgentCoreRuntimeGatewayIntegTest.template.json renamed to packages/@aws-cdk/aws-bedrock-agentcore-alpha/test/agentcore/gateway/integ.gateway-with-runtime-m2m.js.snapshot/BedrockAgentCoreRuntimeGatewayM2MIntegTest.template.json

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,6 @@
117117
"EmailVerificationMessage": "The verification code to your new account is {####}",
118118
"EmailVerificationSubject": "Verify your new account",
119119
"SmsVerificationMessage": "The verification code to your new account is {####}",
120-
"UserPoolName": "integ-test-runtime-gateway-gw-userpool",
121120
"UsernameConfiguration": {
122121
"CaseSensitive": false
123122
},
@@ -134,8 +133,8 @@
134133
"TestGatewayUserPoolResourceServer7A34B6B2": {
135134
"Type": "AWS::Cognito::UserPoolResourceServer",
136135
"Properties": {
137-
"Identifier": "integ-test-runtime-gateway-gateway-resource-server",
138-
"Name": "integ-test-runtime-gateway-GatewayResourceServer",
136+
"Identifier": "BedrockAgentCoreRuntimeGatewayM2MIntegTest-TestGateway-4F82402F",
137+
"Name": "BedrockAgentCoreRuntimeGatewayM2MIntegTest-TestGateway-4F82402F",
139138
"Scopes": [
140139
{
141140
"ScopeDescription": "Read access to gateway tools",
@@ -182,7 +181,6 @@
182181
]
183182
}
184183
],
185-
"ClientName": "integ-test-runtime-gateway-gw-client",
186184
"GenerateSecret": true,
187185
"SupportedIdentityProviders": [
188186
"COGNITO"
@@ -286,7 +284,7 @@
286284
"TestGatewayUserPoolDomainB64B616E": {
287285
"Type": "AWS::Cognito::UserPoolDomain",
288286
"Properties": {
289-
"Domain": "integ-test-runtime-gateway-gw",
287+
"Domain": "bedrockagentcoreruntimegatewaym2mintegtest-testgateway-4f82402f",
290288
"UserPoolId": {
291289
"Ref": "TestGatewayUserPool545AA49A"
292290
}
@@ -321,7 +319,6 @@
321319
}
322320
},
323321
"AuthorizerType": "CUSTOM_JWT",
324-
"Description": "Gateway for Runtime integration test with M2M auth",
325322
"Name": "integ-test-runtime-gateway",
326323
"ProtocolConfiguration": {
327324
"Mcp": {
@@ -420,8 +417,6 @@
420417
"Code": {
421418
"ZipFile": "\n exports.handler = async (event, context) => {\n return {\n statusCode: 200,\n body: JSON.stringify({\n message: 'Hello from Gateway Lambda!',\n timestamp: new Date().toISOString()\n }),\n };\n };\n "
422419
},
423-
"Description": "Simple test function for Gateway M2M authentication test",
424-
"FunctionName": "integ-test-simple-tool",
425420
"Handler": "index.handler",
426421
"Role": {
427422
"Fn::GetAtt": [
@@ -763,7 +758,6 @@
763758
}
764759
},
765760
"AgentRuntimeName": "integ_test_runtime_with_gateway",
766-
"Description": "Runtime using Gateway tools",
767761
"EnvironmentVariables": {
768762
"GATEWAY_URL": {
769763
"Fn::GetAtt": [
@@ -842,7 +836,7 @@
842836
]
843837
},
844838
"Export": {
845-
"Name": "BedrockAgentCoreRuntimeGatewayIntegTest:ExportsOutputFnGetAttTestRuntime65042BB5AgentRuntimeArnE8B3C8DA"
839+
"Name": "BedrockAgentCoreRuntimeGatewayM2MIntegTest:ExportsOutputFnGetAttTestRuntime65042BB5AgentRuntimeArnE8B3C8DA"
846840
}
847841
}
848842
},

packages/@aws-cdk/aws-bedrock-agentcore-alpha/test/agentcore/gateway/integ.gateway-with-runtime.js.snapshot/RuntimeGatewayIntegTestDefaultTestDeployAssert1ACA2D2A.assets.json renamed to packages/@aws-cdk/aws-bedrock-agentcore-alpha/test/agentcore/gateway/integ.gateway-with-runtime-m2m.js.snapshot/RuntimeGatewayIntegTestDefaultTestDeployAssert1ACA2D2A.assets.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk/aws-bedrock-agentcore-alpha/test/agentcore/gateway/integ.gateway-with-runtime.js.snapshot/RuntimeGatewayIntegTestDefaultTestDeployAssert1ACA2D2A.template.json renamed to packages/@aws-cdk/aws-bedrock-agentcore-alpha/test/agentcore/gateway/integ.gateway-with-runtime-m2m.js.snapshot/RuntimeGatewayIntegTestDefaultTestDeployAssert1ACA2D2A.template.json

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk/aws-bedrock-agentcore-alpha/test/agentcore/gateway/integ.gateway-with-runtime.js.snapshot/asset.59ea9be6eec96ed2cb70555aba1b5e0432cb101ab027e5478bc613d570062906/Dockerfile renamed to packages/@aws-cdk/aws-bedrock-agentcore-alpha/test/agentcore/gateway/integ.gateway-with-runtime-m2m.js.snapshot/asset.59ea9be6eec96ed2cb70555aba1b5e0432cb101ab027e5478bc613d570062906/Dockerfile

File renamed without changes.

packages/@aws-cdk/aws-bedrock-agentcore-alpha/test/agentcore/gateway/integ.gateway-with-runtime.js.snapshot/asset.59ea9be6eec96ed2cb70555aba1b5e0432cb101ab027e5478bc613d570062906/app.py renamed to packages/@aws-cdk/aws-bedrock-agentcore-alpha/test/agentcore/gateway/integ.gateway-with-runtime-m2m.js.snapshot/asset.59ea9be6eec96ed2cb70555aba1b5e0432cb101ab027e5478bc613d570062906/app.py

File renamed without changes.

packages/@aws-cdk/aws-bedrock-agentcore-alpha/test/agentcore/gateway/integ.gateway-with-runtime.js.snapshot/asset.59ea9be6eec96ed2cb70555aba1b5e0432cb101ab027e5478bc613d570062906/requirements.txt renamed to packages/@aws-cdk/aws-bedrock-agentcore-alpha/test/agentcore/gateway/integ.gateway-with-runtime-m2m.js.snapshot/asset.59ea9be6eec96ed2cb70555aba1b5e0432cb101ab027e5478bc613d570062906/requirements.txt

File renamed without changes.

packages/@aws-cdk/aws-bedrock-agentcore-alpha/test/agentcore/gateway/integ.gateway-with-runtime.js.snapshot/asset.89f8c437feaf078124252df938abc83ca969185d1730374a4ab70530e6b34616/index.js renamed to packages/@aws-cdk/aws-bedrock-agentcore-alpha/test/agentcore/gateway/integ.gateway-with-runtime-m2m.js.snapshot/asset.89f8c437feaf078124252df938abc83ca969185d1730374a4ab70530e6b34616/index.js

File renamed without changes.

0 commit comments

Comments
 (0)