AddLambdaTargetOptions Struct
Options for adding a Lambda target to a gateway.
| Source | aws-bedrockagentcore/lib/gateway/gateway.ts |
|---|---|
| Type last changed |
Example
ts
// Create a gateway first
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!' })
};
};
`),
});
const lambdaTarget = gateway.addLambdaTarget("MyLambdaTarget", {
gatewayTargetName: "my-lambda-target",
description: "Lambda function target",
lambdaFunction: lambdaFunction,
toolSchema: agentcore.ToolSchema.fromInline([
{
name: "hello_world",
description: "A simple hello world tool",
inputSchema: {
type: agentcore.SchemaDefinitionType.OBJECT,
properties: {
name: {
type: agentcore.SchemaDefinitionType.STRING,
description: "The name to greet",
},
},
required: ["name"],
},
},
]),
});
python
# Create a gateway first
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!' })
};
};
""")
)
lambda_target = gateway.add_lambda_target("MyLambdaTarget",
gateway_target_name="my-lambda-target",
description="Lambda function target",
lambda_function=lambda_function,
tool_schema=agentcore.ToolSchema.from_inline([agentcore.ToolDefinition(
name="hello_world",
description="A simple hello world tool",
input_schema=agentcore.SchemaDefinition(
type=agentcore.SchemaDefinitionType.OBJECT,
properties={
"name": agentcore.SchemaDefinition(
type=agentcore.SchemaDefinitionType.STRING,
description="The name to greet"
)
},
required=["name"]
)
)
])
)
java
// Create a gateway first
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();
GatewayTarget lambdaTarget = gateway.addLambdaTarget("MyLambdaTarget", AddLambdaTargetOptions.builder()
.gatewayTargetName("my-lambda-target")
.description("Lambda function target")
.lambdaFunction(lambdaFunction)
.toolSchema(ToolSchema.fromInline(List.of(ToolDefinition.builder()
.name("hello_world")
.description("A simple hello world tool")
.inputSchema(SchemaDefinition.builder()
.type(SchemaDefinitionType.OBJECT)
.properties(Map.of(
"name", SchemaDefinition.builder()
.type(SchemaDefinitionType.STRING)
.description("The name to greet")
.build()))
.required(List.of("name"))
.build())
.build())))
.build());
csharp
// Install: dotnet add package Amazon.CDK.Lib
// Create a gateway first
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!' })
};
};
")
});
var lambdaTarget = gateway.AddLambdaTarget("MyLambdaTarget", new AddLambdaTargetOptions {
GatewayTargetName = "my-lambda-target",
Description = "Lambda function target",
LambdaFunction = lambdaFunction,
ToolSchema = ToolSchema.FromInline(new [] { new ToolDefinition {
Name = "hello_world",
Description = "A simple hello world tool",
InputSchema = new SchemaDefinition {
Type = SchemaDefinitionType.OBJECT,
Properties = new Dictionary<string, SchemaDefinition> {
{ "name", new SchemaDefinition {
Type = SchemaDefinitionType.STRING,
Description = "The name to greet"
} }
},
Required = new [] { "name" }
}
} })
});
go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
// Create a gateway first
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!' })
};
};
`)),
})
lambdaTarget := gateway.AddLambdaTarget(jsii.String("MyLambdaTarget"), &AddLambdaTargetOptions{
GatewayTargetName: jsii.String("my-lambda-target"),
Description: jsii.String("Lambda function target"),
LambdaFunction: lambdaFunction,
ToolSchema: agentcore.ToolSchema_FromInline([]ToolDefinition{
&ToolDefinition{
Name: jsii.String("hello_world"),
Description: jsii.String("A simple hello world tool"),
InputSchema: &SchemaDefinition{
Type: agentcore.SchemaDefinitionType_OBJECT(),
Properties: map[string]SchemaDefinition{
"name": &SchemaDefinition{
"type": agentcore.SchemaDefinitionType_STRING(),
"description": jsii.String("The name to greet"),
},
},
Required: []*string{
jsii.String("name"),
},
},
},
}),
})
Properties
credentialProviderConfigurationsoptionalICredentialProviderConfig[]credential_provider_configurationsoptionaltyping.List[ICredentialProviderConfig]credentialProviderConfigurationsoptionalList<ICredentialProviderConfig>CredentialProviderConfigurationsoptionalICredentialProviderConfig[]CredentialProviderConfigurationsoptional*[]ICredentialProviderConfig #Credential providers for authentication.
Default: [GatewayCredentialProvider.iamRole()]
descriptionoptionalstringdescriptionoptionalstrdescriptionoptionalStringDescriptionoptionalstringDescriptionoptional*string #Optional description for the gateway target.
Default: No description
gatewayTargetNameoptionalstringgateway_target_nameoptionalstrgatewayTargetNameoptionalStringGatewayTargetNameoptionalstringGatewayTargetNameoptional*string #The name of the gateway target Valid characters are a-z, A-Z, 0-9, _ (underscore) and - (hyphen).
Default: auto generate
lambdaFunctionIFunctionlambda_functionIFunctionlambdaFunctionIFunctionLambdaFunctionIFunctionLambdaFunctionIFunction required #The Lambda function to associate with this target.
toolSchemaToolSchematool_schemaToolSchematoolSchemaToolSchemaToolSchemaToolSchemaToolSchemaToolSchema required #The tool schema defining the available tools.