Skip to content
v2.278.0

ToolSchema Class ​

**************************************************************************** TOOL SCHEMA CLASS ***************************************************************************.

Example ​

ts
const gateway = new agentcore.Gateway(this, "MyGateway", {
  gatewayName: "my-gateway",
});

const lambdaFunction = new lambda.Function(this, "MyFunction", {
  runtime: lambda.Runtime.NODEJS_22_X,
  handler: "index.handler",
  code: lambda.Code.fromInline(`
        exports.handler = async (event) => {
            return {
                statusCode: 200,
                body: JSON.stringify({ message: 'Hello from Lambda!' })
            };
        };
    `),
});

// Create a gateway target with Lambda and tool schema
const target = agentcore.GatewayTarget.forLambda(this, "MyLambdaTarget", {
  gatewayTargetName: "my-lambda-target",
  description: "Target for Lambda function integration",
  gateway: gateway,
  lambdaFunction: lambdaFunction,
  toolSchema: agentcore.ToolSchema.fromLocalAsset(
    path.join(__dirname, "schemas", "my-tool-schema.json")
  ),
});
python
gateway = agentcore.Gateway(self, "MyGateway",
    gateway_name="my-gateway"
)

lambda_function = lambda_.Function(self, "MyFunction",
    runtime=lambda_.Runtime.NODEJS_22_X,
    handler="index.handler",
    code=lambda_.Code.from_inline("""
                exports.handler = async (event) => {
                    return {
                        statusCode: 200,
                        body: JSON.stringify({ message: 'Hello from Lambda!' })
                    };
                };
            """)
)

# Create a gateway target with Lambda and tool schema
target = agentcore.GatewayTarget.for_lambda(self, "MyLambdaTarget",
    gateway_target_name="my-lambda-target",
    description="Target for Lambda function integration",
    gateway=gateway,
    lambda_function=lambda_function,
    tool_schema=agentcore.ToolSchema.from_local_asset(
        path.join(__dirname, "schemas", "my-tool-schema.json"))
)
java
Gateway gateway = Gateway.Builder.create(this, "MyGateway")
        .gatewayName("my-gateway")
        .build();

Function lambdaFunction = Function.Builder.create(this, "MyFunction")
        .runtime(Runtime.NODEJS_22_X)
        .handler("index.handler")
        .code(Code.fromInline("\n        exports.handler = async (event) => {\n            return {\n                statusCode: 200,\n                body: JSON.stringify({ message: 'Hello from Lambda!' })\n            };\n        };\n    "))
        .build();

// Create a gateway target with Lambda and tool schema
GatewayTarget target = GatewayTarget.forLambda(this, "MyLambdaTarget", GatewayTargetLambdaProps.builder()
        .gatewayTargetName("my-lambda-target")
        .description("Target for Lambda function integration")
        .gateway(gateway)
        .lambdaFunction(lambdaFunction)
        .toolSchema(ToolSchema.fromLocalAsset(path.join(__dirname, "schemas", "my-tool-schema.json")))
        .build());
csharp
// Install: dotnet add package Amazon.CDK.Lib
var gateway = new Gateway(this, "MyGateway", new GatewayProps {
    GatewayName = "my-gateway"
});

var lambdaFunction = new Function(this, "MyFunction", new FunctionProps {
    Runtime = Runtime.NODEJS_22_X,
    Handler = "index.handler",
    Code = Code.FromInline(@"
            exports.handler = async (event) => {
                return {
                    statusCode: 200,
                    body: JSON.stringify({ message: 'Hello from Lambda!' })
                };
            };
        ")
});

// Create a gateway target with Lambda and tool schema
var target = GatewayTarget.ForLambda(this, "MyLambdaTarget", new GatewayTargetLambdaProps {
    GatewayTargetName = "my-lambda-target",
    Description = "Target for Lambda function integration",
    Gateway = gateway,
    LambdaFunction = lambdaFunction,
    ToolSchema = ToolSchema.FromLocalAsset(path.Join(__dirname, "schemas", "my-tool-schema.json"))
});
go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
gateway := agentcore.NewGateway(this, jsii.String("MyGateway"), &GatewayProps{
	GatewayName: jsii.String("my-gateway"),
})

lambdaFunction := lambda.NewFunction(this, jsii.String("MyFunction"), &FunctionProps{
	Runtime: lambda.Runtime_NODEJS_22_X(),
	Handler: jsii.String("index.handler"),
	Code: lambda.Code_FromInline(jsii.String(`
	        exports.handler = async (event) => {
	            return {
	                statusCode: 200,
	                body: JSON.stringify({ message: 'Hello from Lambda!' })
	            };
	        };
	    `)),
})

// Create a gateway target with Lambda and tool schema
target := agentcore.GatewayTarget_ForLambda(this, jsii.String("MyLambdaTarget"), &GatewayTargetLambdaProps{
	GatewayTargetName: jsii.String("my-lambda-target"),
	Description: jsii.String("Target for Lambda function integration"),
	Gateway: gateway,
	LambdaFunction: lambdaFunction,
	ToolSchema: agentcore.ToolSchema_FromLocalAsset(path.join(__dirname, jsii.String("schemas"), jsii.String("my-tool-schema.json"))),
})

Properties ​

bucketOwnerAccountIdmay be undefinedstringbucket_owner_account_idmay be undefinedstrbucketOwnerAccountIdmay be undefinedStringBucketOwnerAccountIdmay be undefinedstringBucketOwnerAccountIdmay be undefined*string #
The account ID of the S3 bucket owner for cross-account access.
inlineSchemamay be undefinedToolDefinition[]inline_schemamay be undefinedtyping.List[ToolDefinition]inlineSchemamay be undefinedList<ToolDefinition>InlineSchemamay be undefinedToolDefinition[]InlineSchemamay be undefined*[]ToolDefinition #
The inline tool schema definition as a string, if using an inline schema.

Can be in JSON or YAML format.

s3Filemay be undefinedLocations3_filemay be undefinedLocations3Filemay be undefinedLocationS3Filemay be undefinedLocationS3Filemay be undefinedLocation #
The S3 location of the tool schema file, if using an S3-based schema.

Contains the bucket name and object key information.

Methods ​

bind(scope: Construct): voiddef bind(self, scope: Construct) -> Nonepublic void bind(Construct scope)public void Bind(Construct scope)func Bind(Scope Construct) #
Bind the schema to a construct.
fromInline(schema: ToolDefinition[]): InlineToolSchema@staticmethod def from_inline(schema: typing.List[ToolDefinition]) -> InlineToolSchemapublic static InlineToolSchema fromInline(List<ToolDefinition> schema)public static InlineToolSchema FromInline(ToolDefinition[] schema)func FromInline(Schema *[]ToolDefinition) InlineToolSchema static #
Creates a Tool Schema from an inline string.
1 parameter

Parameters

  • schemaschemaschemaschemaSchema — - the JSON or YAML payload defining the OpenAPI schema for the action group.
fromLocalAsset(path: string): ToolSchema // chainable@staticmethod def from_local_asset(path: str) -> ToolSchemapublic static ToolSchema fromLocalAsset(String path)public static ToolSchema FromLocalAsset(string path)func FromLocalAsset(Path *string) ToolSchema static #
Creates a tool Schema from a local file.
1 parameter

Parameters

  • pathpathpathpathPath — - the path to the local file containing the function schema for the tool.
fromS3File(bucket: IBucket, objectKey: string, bucketOwnerAccountId?: string): S3ToolSchema@staticmethod def from_s3_file(bucket: IBucket, object_key: str, bucket_owner_account_id: typing.Optional[str] = None) -> S3ToolSchemapublic static S3ToolSchema fromS3File(IBucket bucket, String objectKey, String bucketOwnerAccountId)public static S3ToolSchema FromS3File(IBucket bucket, string objectKey, string? bucketOwnerAccountId = null)func FromS3File(Bucket IBucket, ObjectKey *string, BucketOwnerAccountId *string) S3ToolSchema static #
Creates a Tool Schema from an S3 File.
3 parameters

Parameters

  • bucketbucketbucketbucketBucket — - the bucket containing the local file containing the OpenAPI schema for the action group.
  • objectKeyobject_keyobjectKeyobjectKeyObjectKey — - object key in the bucket.
  • bucketOwnerAccountIdbucket_owner_account_idbucketOwnerAccountIdbucketOwnerAccountIdBucketOwnerAccountId — - optional The account ID of the Amazon S3 bucket owner.
grantPermissionsToRole(role: IRole): voiddef grant_permissions_to_role(self, role: IRole) -> Nonepublic void grantPermissionsToRole(IRole role)public void GrantPermissionsToRole(IRole role)func GrantPermissionsToRole(Role IRole) #
Grant permissions to the role.