Skip to content

Commit a93e173

Browse files
committed
feat: Move AgentCore Gateways to CFN stack
1 parent 26b9271 commit a93e173

24 files changed

+233
-4411
lines changed

DEVELOP.md

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -175,16 +175,6 @@ uv pip install -r requirements.txt
175175
cdk deploy --app 'python3 cdk_stack.py'
176176
```
177177

178-
Then, deploy the Bedrock AgentCore Gateway:
179-
180-
```bash
181-
cd gateway_setup/
182-
183-
uv pip install -r requirements.txt
184-
185-
python setup_gateway.py
186-
```
187-
188178
#### Deploy dictionary MCP server
189179

190180
Deploy the Lambda 'dictionary' function - the deployed function will be named "mcp-server-dictionary".
@@ -201,16 +191,6 @@ npm run build
201191
cdk deploy --app 'node lib/dictionary-mcp-server.js'
202192
```
203193

204-
Them, deploy the Bedrock AgentCore Gateway:
205-
206-
```bash
207-
cd gateway_setup/
208-
209-
npm install
210-
211-
npm run setup
212-
```
213-
214194
#### Deploy zen MCP server
215195

216196
Deploy the 'zen' Bedrock AgentCore Gateway.
@@ -220,7 +200,7 @@ cd examples/servers/zen/
220200

221201
uv pip install -r requirements.txt
222202

223-
python setup_gateway.py
203+
cdk deploy --app 'python3 cdk_stack.py'
224204
```
225205

226206
#### Deploy the mcpdoc MCP server

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ Each Lambda function invocation will:
4949
This library supports connecting to Lambda-based MCP servers in four ways:
5050

5151
1. The [MCP Streamable HTTP transport](https://modelcontextprotocol.io/specification/2025-06-18/basic/transports#streamable-http), using Amazon API Gateway. Typically authenticated using OAuth.
52-
1. The MCP Streamable HTTP transport, using Amazon Bedrock AgentCore Gateway (currently in Preview). Authenticated using OAuth.
52+
1. The MCP Streamable HTTP transport, using Amazon Bedrock AgentCore Gateway. Authenticated using OAuth.
5353
1. A custom Streamable HTTP transport with support for SigV4, using a Lambda function URL. Authenticated with AWS IAM.
5454
1. A custom Lambda invocation transport, using the Lambda Invoke API directly. Authenticated with AWS IAM.
5555

e2e_tests/clean_up_integ_test.sh

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,9 @@ cdk destroy --force --app 'python3 cdk_stack.py'
2323

2424
cd ../book-search
2525
cdk destroy --force --app 'python3 cdk_stack.py'
26-
cd gateway_setup/
27-
python teardown_gateway.py
28-
cd ../
2926

3027
cd ../zen
31-
python teardown_gateway.py
28+
cdk destroy --force --app 'python3 cdk_stack.py'
3229

3330
cd ../weather-alerts
3431
cdk destroy --force --app 'node lib/weather-alerts-mcp-server.js'
@@ -41,7 +38,3 @@ cdk destroy --force --app 'node lib/dog-facts-mcp-server.js'
4138

4239
cd ../dictionary
4340
cdk destroy --force --app 'node lib/dictionary-mcp-server.js'
44-
cd gateway_setup/
45-
npm install
46-
npm run teardown
47-
cd ../

e2e_tests/run_integ_test.sh

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,11 @@ cdk deploy --app 'python3 cdk_stack.py' --require-approval never
3333
cd ../book-search
3434
uv pip install -r requirements.txt
3535
cdk deploy --app 'python3 cdk_stack.py' --require-approval never
36-
cd gateway_setup/
37-
uv pip install -r requirements.txt
38-
python setup_gateway.py
39-
cd ../
4036

4137
# Deploy Python-based zen MCP server
4238
cd ../zen
4339
uv pip install -r requirements.txt
44-
python setup_gateway.py
40+
cdk deploy --app 'python3 cdk_stack.py' --require-approval never
4541

4642
######## Deploy Typescript-based example MCP servers ########
4743

@@ -77,10 +73,6 @@ npm ci
7773
npm link @aws/run-mcp-servers-with-aws-lambda
7874
npm run build
7975
cdk deploy --app 'node lib/dictionary-mcp-server.js' --require-approval never
80-
cd gateway_setup/
81-
npm install
82-
npm run setup
83-
cd ../
8476

8577
# Configure integ tests
8678
cd ../../../e2e_tests/

examples/servers/book-search/README.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,6 @@ specification for the [Open Library Search API](https://openlibrary.org/dev/docs
1515
uv pip install -r requirements.txt
1616

1717
cdk deploy --app 'python3 cdk_stack.py'
18-
19-
cd gateway_setup/
20-
21-
uv pip install -r requirements.txt
22-
23-
python ./setup_gateway.py
2418
```
2519

2620
See the [development guide](/DEVELOP.md) for full instructions to deploy and run the examples in this repository.

examples/servers/book-search/cdk_stack.py

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55
DockerVolume,
66
Duration,
77
Environment,
8+
Fn,
89
RemovalPolicy,
910
Stack,
11+
aws_bedrockagentcore as bedrockagentcore,
1012
aws_iam as iam,
1113
aws_lambda as lambda_,
1214
aws_lambda_python_alpha as lambda_python,
@@ -15,6 +17,7 @@
1517
from cdk_nag import AwsSolutionsChecks
1618
from constructs import Construct
1719
import jsii
20+
import json
1821
import os
1922

2023

@@ -88,12 +91,75 @@ def __init__(
8891
),
8992
)
9093

94+
# Load tools configuration
95+
with open(os.path.join(os.path.dirname(__file__), "gateway-tools-list.json"), "r") as f:
96+
tools_config = json.load(f)
97+
98+
# Get gateway name with length limit
99+
gateway_name = f"LambdaMcpServer-BookSearch-Gateway{stack_name_suffix}"
100+
if len(gateway_name) > 48:
101+
gateway_name = gateway_name[:48].rstrip('-')
102+
103+
gateway = bedrockagentcore.CfnGateway(
104+
self,
105+
"Gateway",
106+
name=gateway_name,
107+
role_arn=f"arn:aws:iam::{self.account}:role/mcp-lambda-example-agentcore-gateways",
108+
protocol_type="MCP",
109+
authorizer_type="CUSTOM_JWT",
110+
authorizer_configuration={
111+
"customJwtAuthorizer": {
112+
"allowedClients": [
113+
Fn.import_value("LambdaMcpServer-Auth-InteractiveOAuthClientId"),
114+
Fn.import_value("LambdaMcpServer-Auth-AutomatedOAuthClientId"),
115+
],
116+
"discoveryUrl": Fn.sub(
117+
"${IssuerDomain}/.well-known/openid-configuration",
118+
{
119+
"IssuerDomain": Fn.import_value("LambdaMcpServer-Auth-IssuerDomain"),
120+
}
121+
),
122+
}
123+
},
124+
exception_level="DEBUG",
125+
)
126+
127+
bedrockagentcore.CfnGatewayTarget(
128+
self,
129+
"GatewayTarget",
130+
gateway_identifier=gateway.attr_gateway_identifier,
131+
name="book-search-target",
132+
target_configuration={
133+
"mcp": {
134+
"lambda": {
135+
"lambdaArn": server_function.function_arn,
136+
"toolSchema": {"inlinePayload": tools_config["tools"]},
137+
}
138+
}
139+
},
140+
credential_provider_configurations=[
141+
{"credentialProviderType": "GATEWAY_IAM_ROLE"}
142+
],
143+
)
144+
91145
CfnOutput(
92146
self,
93147
"ServerFunctionOutput",
94148
value=server_function.function_arn,
95149
)
96150

151+
CfnOutput(
152+
self,
153+
"GatewayIdOutput",
154+
value=gateway.attr_gateway_identifier,
155+
)
156+
157+
CfnOutput(
158+
self,
159+
"GatewayUrlOutput",
160+
value=gateway.attr_gateway_url,
161+
)
162+
97163

98164
app = App()
99165
env = Environment(account=os.environ["CDK_DEFAULT_ACCOUNT"], region="us-west-2")

examples/servers/book-search/gateway_setup/tools-list.json renamed to examples/servers/book-search/gateway-tools-list.json

File renamed without changes.

examples/servers/book-search/gateway_setup/requirements.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.

examples/servers/book-search/gateway_setup/setup_gateway.py

Lines changed: 0 additions & 118 deletions
This file was deleted.

examples/servers/book-search/gateway_setup/teardown_gateway.py

Lines changed: 0 additions & 60 deletions
This file was deleted.

0 commit comments

Comments
 (0)