Skip to content

Commit 6985d58

Browse files
committed
feat(cli): remove unused lambda tool
1 parent dc2999a commit 6985d58

5 files changed

Lines changed: 0 additions & 314 deletions

File tree

examples/integrations/agentcore/gateway/tools/sample_tool/sample_tool_lambda.py

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

examples/integrations/agentcore/gateway/tools/sample_tool/tool_spec.json

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

examples/integrations/agentcore/infra-cdk/lib/backend-stack.ts

Lines changed: 0 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -488,30 +488,12 @@ export class BackendStack extends cdk.NestedStack {
488488
}
489489

490490
private createAgentCoreGateway(config: AppConfig): void {
491-
// Create sample tool Lambda
492-
const toolLambda = new lambda.Function(this, "SampleToolLambda", {
493-
runtime: lambda.Runtime.PYTHON_3_13,
494-
handler: "sample_tool_lambda.handler",
495-
code: lambda.Code.fromAsset(
496-
path.join(__dirname, "../../gateway/tools/sample_tool"),
497-
),
498-
timeout: cdk.Duration.seconds(30),
499-
logGroup: new logs.LogGroup(this, "SampleToolLambdaLogGroup", {
500-
logGroupName: `/aws/lambda/${config.stack_name_base}-sample-tool`,
501-
retention: logs.RetentionDays.ONE_WEEK,
502-
removalPolicy: cdk.RemovalPolicy.DESTROY,
503-
}),
504-
});
505-
506491
// Create comprehensive IAM role for gateway
507492
const gatewayRole = new iam.Role(this, "GatewayRole", {
508493
assumedBy: new iam.ServicePrincipal("bedrock-agentcore.amazonaws.com"),
509494
description: "Role for AgentCore Gateway with comprehensive permissions",
510495
});
511496

512-
// Lambda invoke permission
513-
toolLambda.grantInvoke(gatewayRole);
514-
515497
// Bedrock permissions (region-agnostic)
516498
gatewayRole.addToPolicy(
517499
new iam.PolicyStatement({
@@ -565,15 +547,6 @@ export class BackendStack extends cdk.NestedStack {
565547
}),
566548
);
567549

568-
// Load tool specification from JSON file
569-
const toolSpecPath = path.join(
570-
__dirname,
571-
"../../gateway/tools/sample_tool/tool_spec.json",
572-
);
573-
const apiSpec = JSON.parse(
574-
require("fs").readFileSync(toolSpecPath, "utf8"),
575-
);
576-
577550
// Cognito OAuth2 configuration for gateway
578551
const cognitoIssuer = `https://cognito-idp.${this.region}.amazonaws.com/${this.userPool.userPoolId}`;
579552
const cognitoDiscoveryUrl = `${cognitoIssuer}/.well-known/openid-configuration`;
@@ -703,35 +676,7 @@ export class BackendStack extends cdk.NestedStack {
703676
description: "AgentCore Gateway with MCP protocol and JWT authentication",
704677
});
705678

706-
// Create Gateway Target using L1 construct (CfnGatewayTarget)
707-
const gatewayTarget = new bedrockagentcore.CfnGatewayTarget(
708-
this,
709-
"GatewayTarget",
710-
{
711-
gatewayIdentifier: gateway.attrGatewayIdentifier,
712-
name: "sample-tool-target",
713-
description: "Sample tool Lambda target",
714-
targetConfiguration: {
715-
mcp: {
716-
lambda: {
717-
lambdaArn: toolLambda.functionArn,
718-
toolSchema: {
719-
inlinePayload: apiSpec,
720-
},
721-
},
722-
},
723-
},
724-
credentialProviderConfigurations: [
725-
{
726-
credentialProviderType: "GATEWAY_IAM_ROLE",
727-
},
728-
],
729-
},
730-
);
731-
732679
// Ensure proper creation order
733-
gatewayTarget.addDependency(gateway);
734-
gateway.node.addDependency(toolLambda);
735680
gateway.node.addDependency(this.machineClient);
736681
gateway.node.addDependency(gatewayRole);
737682

examples/integrations/agentcore/infra-terraform/modules/backend/gateway.tf

Lines changed: 0 additions & 138 deletions
Original file line numberDiff line numberDiff line change
@@ -6,81 +6,6 @@
66
# Maps to: backend-stack.ts createAgentCoreGateway()
77
# =============================================================================
88

9-
# -----------------------------------------------------------------------------
10-
# CloudWatch Log Group for Lambda
11-
# -----------------------------------------------------------------------------
12-
13-
resource "aws_cloudwatch_log_group" "tool_lambda" {
14-
name = "/aws/lambda/${var.stack_name_base}-sample-tool"
15-
retention_in_days = local.log_retention_days
16-
17-
}
18-
19-
# -----------------------------------------------------------------------------
20-
# IAM Role for Lambda Function
21-
# -----------------------------------------------------------------------------
22-
23-
data "aws_iam_policy_document" "tool_lambda_assume_role" {
24-
statement {
25-
effect = "Allow"
26-
actions = ["sts:AssumeRole"]
27-
28-
principals {
29-
type = "Service"
30-
identifiers = ["lambda.amazonaws.com"]
31-
}
32-
}
33-
}
34-
35-
resource "aws_iam_role" "tool_lambda" {
36-
name = "${var.stack_name_base}-sample-tool-lambda-role"
37-
assume_role_policy = data.aws_iam_policy_document.tool_lambda_assume_role.json
38-
description = "Execution role for sample tool Lambda"
39-
40-
}
41-
42-
data "aws_iam_policy_document" "tool_lambda_policy" {
43-
statement {
44-
effect = "Allow"
45-
actions = [
46-
"logs:CreateLogStream",
47-
"logs:PutLogEvents"
48-
]
49-
resources = ["${aws_cloudwatch_log_group.tool_lambda.arn}:*"]
50-
}
51-
}
52-
53-
resource "aws_iam_role_policy" "tool_lambda" {
54-
name = "${var.stack_name_base}-sample-tool-lambda-policy"
55-
role = aws_iam_role.tool_lambda.id
56-
policy = data.aws_iam_policy_document.tool_lambda_policy.json
57-
}
58-
59-
# -----------------------------------------------------------------------------
60-
# Lambda Function for Sample Tool
61-
# -----------------------------------------------------------------------------
62-
63-
data "archive_file" "tool_lambda" {
64-
type = "zip"
65-
source_dir = local.gateway_lambda_source_path
66-
output_path = "${path.module}/artifacts/gateway_lambda.zip"
67-
excludes = ["tool_spec.json", "__pycache__", "*.pyc"]
68-
}
69-
70-
resource "aws_lambda_function" "sample_tool" {
71-
function_name = "${var.stack_name_base}-sample-tool"
72-
role = aws_iam_role.tool_lambda.arn
73-
handler = "sample_tool_lambda.handler"
74-
runtime = "python3.13"
75-
timeout = 30
76-
77-
filename = data.archive_file.tool_lambda.output_path
78-
source_code_hash = data.archive_file.tool_lambda.output_base64sha256
79-
80-
depends_on = [aws_cloudwatch_log_group.tool_lambda]
81-
82-
}
83-
849
# -----------------------------------------------------------------------------
8510
# IAM Role for Gateway
8611
# -----------------------------------------------------------------------------
@@ -105,16 +30,6 @@ resource "aws_iam_role" "gateway" {
10530
}
10631

10732
data "aws_iam_policy_document" "gateway_policy" {
108-
# Lambda invoke permission
109-
statement {
110-
sid = "LambdaInvoke"
111-
effect = "Allow"
112-
actions = [
113-
"lambda:InvokeFunction"
114-
]
115-
resources = [aws_lambda_function.sample_tool.arn]
116-
}
117-
11833
# Bedrock permissions (region-agnostic)
11934
statement {
12035
sid = "BedrockInvoke"
@@ -172,7 +87,6 @@ resource "aws_iam_role_policy" "gateway" {
17287

17388
# -----------------------------------------------------------------------------
17489
# Wait for IAM permission propagation
175-
# Gateway Target creation can fail due to IAM role propagation delay
17690
# -----------------------------------------------------------------------------
17791

17892
resource "time_sleep" "gateway_iam_propagation" {
@@ -190,15 +104,13 @@ resource "aws_bedrockagentcore_gateway" "main" {
190104
role_arn = aws_iam_role.gateway.arn
191105
description = "AgentCore Gateway with MCP protocol and JWT authentication"
192106

193-
# Protocol configuration
194107
protocol_type = "MCP"
195108
protocol_configuration {
196109
mcp {
197110
supported_versions = ["2025-03-26"]
198111
}
199112
}
200113

201-
# JWT authorizer with Cognito - uses machine client from auth.tf
202114
authorizer_type = "CUSTOM_JWT"
203115
authorizer_configuration {
204116
custom_jwt_authorizer {
@@ -207,55 +119,5 @@ resource "aws_bedrockagentcore_gateway" "main" {
207119
}
208120
}
209121

210-
211122
depends_on = [time_sleep.gateway_iam_propagation]
212123
}
213-
214-
# -----------------------------------------------------------------------------
215-
# AgentCore Gateway Target
216-
# -----------------------------------------------------------------------------
217-
218-
resource "aws_bedrockagentcore_gateway_target" "sample_tool" {
219-
name = "sample-tool-target"
220-
gateway_identifier = aws_bedrockagentcore_gateway.main.gateway_id
221-
description = "Sample tool Lambda target"
222-
223-
credential_provider_configuration {
224-
gateway_iam_role {}
225-
}
226-
227-
target_configuration {
228-
mcp {
229-
lambda {
230-
lambda_arn = aws_lambda_function.sample_tool.arn
231-
232-
tool_schema {
233-
inline_payload {
234-
name = "text_analysis_tool"
235-
description = "A tool which analyzes an input block of text to count number of words and return the top N frequent characters."
236-
237-
input_schema {
238-
type = "object"
239-
description = "Input parameters for text analysis"
240-
241-
property {
242-
name = "text"
243-
type = "string"
244-
description = "Input block of text to analyze"
245-
required = true
246-
}
247-
248-
property {
249-
name = "N"
250-
type = "integer"
251-
description = "The number of most frequent characters to return (optional, default = 5)"
252-
}
253-
}
254-
}
255-
}
256-
}
257-
}
258-
}
259-
260-
depends_on = [aws_bedrockagentcore_gateway.main]
261-
}

examples/integrations/agentcore/infra-terraform/modules/backend/locals.tf

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,6 @@ locals {
5454
zip_packager_lambda_source_path = "${path.module}/../../lambdas/zip-packager"
5555

5656
# Lambda source paths
57-
gateway_lambda_source_path = "${path.module}/../../../gateway/tools/sample_tool"
58-
gateway_tool_spec_path = "${path.module}/../../../gateway/tools/sample_tool/tool_spec.json"
5957
feedback_lambda_source_path = "${path.module}/../../../infra-cdk/lambdas/feedback"
6058
copilotkit_runtime_source_path = "${path.module}/../../../infra-cdk/lambdas/copilotkit-runtime"
6159

0 commit comments

Comments
 (0)