GatewayTarget L2 construct
Defines tools that your gateway will host.
Supports multiple target types:
- Lambda: Wraps a Lambda function as MCP tools
- OpenAPI: Exposes an OpenAPI/REST API as MCP tools
- Smithy: Exposes a Smithy-modeled API as MCP tools
Example
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")
),
});
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"))
)
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());
// 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"))
});
// 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"))),
})
Initializer
new GatewayTarget(scope: Construct, id: string, props: GatewayTargetProps)
GatewayTarget(scope: Construct, id: str, props: GatewayTargetProps)
new GatewayTarget(Construct scope, String id, GatewayTargetProps props)
new GatewayTarget(Construct scope, string id, GatewayTargetProps props)
NewGatewayTarget(Scope Construct, Id *string, Props GatewayTargetProps)
Construct Props
credentialProviderConfigurationsICredentialProviderConfig[]credential_provider_configurationstyping.List[ICredentialProviderConfig]credentialProviderConfigurationsList<ICredentialProviderConfig>CredentialProviderConfigurationsICredentialProviderConfig[]CredentialProviderConfigurations*[]ICredentialProviderConfig= [GatewayCredentialProvider.fromI…#default
Default: [GatewayCredentialProvider.fromIamRole()]
descriptionstringdescriptionstrdescriptionStringDescriptionstringDescription*string= No description#gatewayTargetNamestringgateway_target_namestrgatewayTargetNameStringGatewayTargetNamestringGatewayTargetName*string= auto generate#targetConfigurationITargetConfigurationtarget_configurationITargetConfigurationtargetConfigurationITargetConfigurationTargetConfigurationITargetConfigurationTargetConfigurationITargetConfigurationrequired#Properties
credentialProviderConfigurationsICredentialProviderConfig[]credential_provider_configurationstyping.List[ICredentialProviderConfig]credentialProviderConfigurationsList<ICredentialProviderConfig>CredentialProviderConfigurationsICredentialProviderConfig[]CredentialProviderConfigurations*[]ICredentialProviderConfig#envResourceEnvironmentenvResourceEnvironmentenvResourceEnvironmentEnvResourceEnvironmentEnvResourceEnvironmentrequired#notes
For resources that are created and managed in a Stack (those created by creating new class instances like new Role(), new Bucket(), etc.), this is always the same as the environment of the stack they belong to.
For referenced resources (those obtained from referencing methods like Role.fromRoleArn(), Bucket.fromBucketName(), etc.), they might be different than the stack they were imported into.
gatewayTargetNamestringgateway_target_namestrgatewayTargetNameStringGatewayTargetNamestringGatewayTargetName*stringrequired#gatewayTargetRefGatewayTargetReferencegateway_target_refGatewayTargetReferencegatewayTargetRefGatewayTargetReferenceGatewayTargetRefGatewayTargetReferenceGatewayTargetRefGatewayTargetReferencerequired#PROPERTY_INJECTION_IDstringproperty_injection_idstrPROPERTY_INJECTION_IDStringPROPERTY_INJECTION_IDstringPROPERTY_INJECTION_ID*stringrequiredstatic#statusReasonsstring[]status_reasonstyping.List[str]statusReasonsList<String>StatusReasonsstring[]StatusReasons*[]*string#targetProtocolTypeGatewayTargetProtocolTypetarget_protocol_typeGatewayTargetProtocolTypetargetProtocolTypeGatewayTargetProtocolTypeTargetProtocolTypeGatewayTargetProtocolTypeTargetProtocolTypeGatewayTargetProtocolTyperequired#targetTypeMcpTargetTypetarget_typeMcpTargetTypetargetTypeMcpTargetTypeTargetTypeMcpTargetTypeTargetTypeMcpTargetTyperequired#Methods
applyCrossStackReferenceStrength(strength: ReferenceStrength): voiddef apply_cross_stack_reference_strength(self, strength: ReferenceStrength) -> Nonepublic void applyCrossStackReferenceStrength(ReferenceStrength strength)public void ApplyCrossStackReferenceStrength(ReferenceStrength strength)func ApplyCrossStackReferenceStrength(Strength ReferenceStrength)#notes · 1 parameter
When set, any cross-stack reference to this resource will use the specified mechanism instead of the global default determined by the @aws-cdk/core:defaultCrossStackReferences context key. This is useful for selectively weakening specific references to avoid the "deadly embrace" problem without changing the app-wide default.
Parameters
strengthstrengthstrengthstrengthStrength— - The reference strength to use for this resource.
applyRemovalPolicy(policy: RemovalPolicy): voiddef apply_removal_policy(self, policy: RemovalPolicy) -> Nonepublic void applyRemovalPolicy(RemovalPolicy policy)public void ApplyRemovalPolicy(RemovalPolicy policy)func ApplyRemovalPolicy(Policy RemovalPolicy)#notes
The Removal Policy controls what happens to this resource when it stops being managed by CloudFormation, either because you've removed it from the CDK application or because you've made a change that requires the resource to be replaced.
The resource can be deleted (RemovalPolicy.DESTROY), or left in your AWS account for data recovery and cleanup later (RemovalPolicy.RETAIN).
forApiGateway(scope: Construct, id: string, props: GatewayTargetApiGatewayProps): GatewayTarget // chainable@staticmethod def for_api_gateway(scope: Construct, id: str, props: GatewayTargetApiGatewayProps) -> GatewayTargetpublic static GatewayTarget forApiGateway(Construct scope, String id, GatewayTargetApiGatewayProps props)public static GatewayTarget ForApiGateway(Construct scope, string id, GatewayTargetApiGatewayProps props)func ForApiGateway(Scope Construct, Id *string, Props GatewayTargetApiGatewayProps) GatewayTargetstatic#3 parameters · returns
Parameters
scopescopescopescopeScope— The construct scope.ididididId— The construct id.propspropspropspropsProps— The properties for the API Gateway target.
Returns: A new GatewayTarget instance
forLambda(scope: Construct, id: string, props: GatewayTargetLambdaProps): GatewayTarget // chainable@staticmethod def for_lambda(scope: Construct, id: str, props: GatewayTargetLambdaProps) -> GatewayTargetpublic static GatewayTarget forLambda(Construct scope, String id, GatewayTargetLambdaProps props)public static GatewayTarget ForLambda(Construct scope, string id, GatewayTargetLambdaProps props)func ForLambda(Scope Construct, Id *string, Props GatewayTargetLambdaProps) GatewayTargetstatic#3 parameters · returns
Parameters
scopescopescopescopeScope— The construct scope.ididididId— The construct id.propspropspropspropsProps— The properties for the Lambda target.
Returns: A new GatewayTarget instance
forMcpServer(scope: Construct, id: string, props: GatewayTargetMcpServerProps): GatewayTarget // chainable@staticmethod def for_mcp_server(scope: Construct, id: str, props: GatewayTargetMcpServerProps) -> GatewayTargetpublic static GatewayTarget forMcpServer(Construct scope, String id, GatewayTargetMcpServerProps props)public static GatewayTarget ForMcpServer(Construct scope, string id, GatewayTargetMcpServerProps props)func ForMcpServer(Scope Construct, Id *string, Props GatewayTargetMcpServerProps) GatewayTargetstatic#3 parameters · returns
Parameters
scopescopescopescopeScope— The construct scope.ididididId— The construct id.propspropspropspropsProps— The properties for the MCP server target.
Returns: A new GatewayTarget instance
forOpenApi(scope: Construct, id: string, props: GatewayTargetOpenApiProps): GatewayTarget // chainable@staticmethod def for_open_api(scope: Construct, id: str, props: GatewayTargetOpenApiProps) -> GatewayTargetpublic static GatewayTarget forOpenApi(Construct scope, String id, GatewayTargetOpenApiProps props)public static GatewayTarget ForOpenApi(Construct scope, string id, GatewayTargetOpenApiProps props)func ForOpenApi(Scope Construct, Id *string, Props GatewayTargetOpenApiProps) GatewayTargetstatic#3 parameters · returns
Parameters
scopescopescopescopeScope— The construct scope.ididididId— The construct id.propspropspropspropsProps— The properties for the OpenAPI target.
Returns: A new GatewayTarget instance
forSmithy(scope: Construct, id: string, props: GatewayTargetSmithyProps): GatewayTarget // chainable@staticmethod def for_smithy(scope: Construct, id: str, props: GatewayTargetSmithyProps) -> GatewayTargetpublic static GatewayTarget forSmithy(Construct scope, String id, GatewayTargetSmithyProps props)public static GatewayTarget ForSmithy(Construct scope, string id, GatewayTargetSmithyProps props)func ForSmithy(Scope Construct, Id *string, Props GatewayTargetSmithyProps) GatewayTargetstatic#3 parameters · returns
Parameters
scopescopescopescopeScope— The construct scope.ididididId— The construct id.propspropspropspropsProps— The properties for the Smithy target.
Returns: A new GatewayTarget instance
fromGatewayTargetAttributes(scope: Construct, id: string, attrs: GatewayTargetAttributes): IGatewayTarget@staticmethod def from_gateway_target_attributes(scope: Construct, id: str, attrs: GatewayTargetAttributes) -> IGatewayTargetpublic static IGatewayTarget fromGatewayTargetAttributes(Construct scope, String id, GatewayTargetAttributes attrs)public static IGatewayTarget FromGatewayTargetAttributes(Construct scope, string id, GatewayTargetAttributes attrs)func FromGatewayTargetAttributes(Scope Construct, Id *string, Attrs GatewayTargetAttributes) IGatewayTargetstatic#3 parameters · returns
Parameters
scopescopescopescopeScope— The construct scope.ididididId— The construct id.attrsattrsattrsattrsAttrs— The attributes of the existing Gateway Target.
Returns: An IGatewayTarget instance representing the imported target
grant(grantee: IGrantable, ...actions: string[]): Grantdef grant(self, grantee: IGrantable, actions: str) -> Grantpublic Grant grant(IGrantable grantee, String actions)public Grant Grant(IGrantable grantee, string actions)func Grant(Grantee IGrantable, Actions *string) Grant#[disable-awslint:no-grants]
2 parameters
Parameters
granteegranteegranteegranteeGrantee— The principal to grant permissions to.actionsactionsactionsactionsActions— The IAM actions to grant.
grantManage(grantee: IGrantable): Grantdef grant_manage(self, grantee: IGrantable) -> Grantpublic Grant grantManage(IGrantable grantee)public Grant GrantManage(IGrantable grantee)func GrantManage(Grantee IGrantable) Grant#[disable-awslint:no-grants]
1 parameter
Parameters
granteegranteegranteegranteeGrantee— The principal to grant manage permissions to.
grantRead(grantee: IGrantable): Grantdef grant_read(self, grantee: IGrantable) -> Grantpublic Grant grantRead(IGrantable grantee)public Grant GrantRead(IGrantable grantee)func GrantRead(Grantee IGrantable) Grant#[disable-awslint:no-grants]
1 parameter
Parameters
granteegranteegranteegranteeGrantee— The principal to grant read permissions to.
grantSync(grantee: IGrantable): Grantdef grant_sync(self, grantee: IGrantable) -> Grantpublic Grant grantSync(IGrantable grantee)public Grant GrantSync(IGrantable grantee)func GrantSync(Grantee IGrantable) Grant#This method grants the SynchronizeGatewayTargets permission, which is primarily needed for MCP Server targets when you need to refresh the tool catalog after the MCP server's tools have changed.
[disable-awslint:no-grants]
isConstruct(x: any): boolean@staticmethod def is_construct(x: Any) -> boolpublic static Boolean isConstruct(Object x)public static bool IsConstruct(object x)func IsConstruct(X interface{}) *boolstatic#notes · 1 parameter · returns
Use this method instead of instanceof to properly detect Construct instances, even when the construct library is symlinked.
Explanation: in JavaScript, multiple copies of the constructs library on disk are seen as independent, completely different libraries. As a consequence, the class Construct in each copy of the constructs library is seen as a different class, and an instance of one class will not test as instanceof the other class. npm install will not create installations like this, but users may manually symlink construct libraries together or use a monorepo tool: in those cases, multiple copies of the constructs library can be accidentally installed, and instanceof will behave unpredictably. It is safest to avoid using instanceof, and using this type-testing method instead.
Parameters
xxxxX— Any object.
Returns: true if x is an object created from a class which extends Construct.
isOwnedResource(construct: IConstruct): boolean@staticmethod def is_owned_resource(construct: IConstruct) -> boolpublic static Boolean isOwnedResource(IConstruct construct)public static bool IsOwnedResource(IConstruct construct)func IsOwnedResource(Construct IConstruct) *boolstatic#isResource(construct: IConstruct): boolean@staticmethod def is_resource(construct: IConstruct) -> boolpublic static Boolean isResource(IConstruct construct)public static bool IsResource(IConstruct construct)func IsResource(Construct IConstruct) *boolstatic#toString(): stringdef to_string(self, ) -> strpublic String toString()public string ToString()func ToString() *string#with(...mixins: IMixin[]): IConstructdef with(self, mixins: IMixin) -> IConstructpublic IConstruct with(IMixin mixins)public IConstruct With(IMixin mixins)func With(Mixins IMixin) IConstruct#Mixins are applied in order. The list of constructs is captured at the start of the call, so constructs added by a mixin will not be visited. Use multiple with() calls if subsequent mixins should apply to added constructs.