Skip to content
v2.273.0

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 ​

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"))),
})

Initializer ​

ts
new GatewayTarget(scope: Construct, id: string, props: GatewayTargetProps)
python
GatewayTarget(scope: Construct, id: str, props: GatewayTargetProps)
java
new GatewayTarget(Construct scope, String id, GatewayTargetProps props)
csharp
new GatewayTarget(Construct scope, string id, GatewayTargetProps props)
go
NewGatewayTarget(Scope Construct, Id *string, Props GatewayTargetProps)

Construct Props ​

credentialProviderConfigurationsICredentialProviderConfig[]credential_provider_configurationstyping.List[ICredentialProviderConfig]credentialProviderConfigurationsList<ICredentialProviderConfig>CredentialProviderConfigurationsICredentialProviderConfig[]CredentialProviderConfigurations*[]ICredentialProviderConfig= [GatewayCredentialProvider.fromI…#
Credential providers for authentication.
default

Default: [GatewayCredentialProvider.fromIamRole()]

descriptionstringdescriptionstrdescriptionStringDescriptionstringDescription*string= No description#
Optional description for the gateway target The description can have up to 200 characters.
gatewayIGatewaygatewayIGatewaygatewayIGatewayGatewayIGatewayGatewayIGatewayrequired#
The gateway this target belongs to.
gatewayTargetNamestringgateway_target_namestrgatewayTargetNameStringGatewayTargetNamestringGatewayTargetName*string= auto generate#
The name of the gateway target The name must be unique within the gateway Pattern: ^([0-9a-zA-Z][-]?){1,100}$.
targetConfigurationITargetConfigurationtarget_configurationITargetConfigurationtargetConfigurationITargetConfigurationTargetConfigurationITargetConfigurationTargetConfigurationITargetConfigurationrequired#
The target configuration (Lambda, OpenAPI, or Smithy) Use one of the configuration helper classes: - LambdaTargetConfiguration.create() - OpenApiTargetConfiguration.create() - SmithyTargetConfiguration.create().

Properties ​

createdAtstringcreated_atstrcreatedAtStringCreatedAtstringCreatedAt*string#
Timestamp when the gateway target was created.
credentialProviderConfigurationsICredentialProviderConfig[]credential_provider_configurationstyping.List[ICredentialProviderConfig]credentialProviderConfigurationsList<ICredentialProviderConfig>CredentialProviderConfigurationsICredentialProviderConfig[]CredentialProviderConfigurations*[]ICredentialProviderConfig#
The credential providers for this target.
descriptionstringdescriptionstrdescriptionStringDescriptionstringDescription*string#
Optional description for the gateway target.
The environment this resource belongs to.
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.

gatewayIGatewaygatewayIGatewaygatewayIGatewayGatewayIGatewayGatewayIGatewayrequired#
The gateway this target belongs to.
gatewayTargetNamestringgateway_target_namestrgatewayTargetNameStringGatewayTargetNamestringGatewayTargetName*stringrequired#
The name of the gateway target.
gatewayTargetRefGatewayTargetReferencegateway_target_refGatewayTargetReferencegatewayTargetRefGatewayTargetReferenceGatewayTargetRefGatewayTargetReferenceGatewayTargetRefGatewayTargetReferencerequired#
A reference to a GatewayTarget resource.
nodeNodenodeNodenodeNodeNodeNodeNodeNoderequired#
The tree node.
PROPERTY_INJECTION_IDstringproperty_injection_idstrPROPERTY_INJECTION_IDStringPROPERTY_INJECTION_IDstringPROPERTY_INJECTION_ID*stringrequiredstatic#
Uniquely identifies this class.
stackStackstackStackstackStackStackStackStackStackrequired#
The stack in which this resource is defined.
statusstringstatusstrstatusStringStatusstringStatus*string#
The status of the gateway target.
statusReasonsstring[]status_reasonstyping.List[str]statusReasonsList<String>StatusReasonsstring[]StatusReasons*[]*string#
The status reasons for the gateway target.
targetArnstringtarget_arnstrtargetArnStringTargetArnstringTargetArn*stringrequired#
The ARN of the gateway target.
targetIdstringtarget_idstrtargetIdStringTargetIdstringTargetId*stringrequired#
The unique identifier of the gateway target.
targetProtocolTypeGatewayTargetProtocolTypetarget_protocol_typeGatewayTargetProtocolTypetargetProtocolTypeGatewayTargetProtocolTypeTargetProtocolTypeGatewayTargetProtocolTypeTargetProtocolTypeGatewayTargetProtocolTyperequired#
The protocol type (always MCP for now).
targetTypeMcpTargetTypetarget_typeMcpTargetTypetargetTypeMcpTargetTypeTargetTypeMcpTargetTypeTargetTypeMcpTargetTyperequired#
The specific MCP target type (Lambda, OpenAPI, Smithy, or MCP Server).
updatedAtstringupdated_atstrupdatedAtStringUpdatedAtstringUpdatedAt*string#
Timestamp when the gateway target was last updated.

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)#
Override the cross-stack reference strength for this resource.
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)#
Apply the given removal policy to this resource.
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#
Create an API Gateway-based target Convenience method for creating a target that connects to an API Gateway REST API.
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#
Create a Lambda-based MCP target Convenience method for creating a target that wraps a Lambda function.
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#
Create an MCP Server-based target Convenience method for creating a target that connects to an external MCP server.
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#
Create an OpenAPI-based MCP target Convenience method for creating a target that exposes an OpenAPI/REST API.
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#
Create a Smithy-based MCP target Convenience method for creating a target that exposes a Smithy-modeled API.
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#
Import an existing Gateway Target using its attributes This allows you to reference a Gateway Target that was created outside of CDK.
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#
Grants IAM actions to the IAM Principal.

[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#
Grants `Create`, `Update`, and `Delete` actions on the Gateway Target.

[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#
Grants `Get` and `List` actions on the Gateway Target.

[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#
Grants permission to synchronize this gateway's targets.

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#
Checks if `x` is a construct.
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#
Returns true if the construct was created by CDK, and false otherwise.
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#
Check whether the given construct is a Resource.
toString(): stringdef to_string(self, ) -> strpublic String toString()public string ToString()func ToString() *string#
Returns a string representation of this construct.
with(...mixins: IMixin[]): IConstructdef with(self, mixins: IMixin) -> IConstructpublic IConstruct with(IMixin mixins)public IConstruct With(IMixin mixins)func With(Mixins IMixin) IConstruct#
Applies one or more mixins to this construct.

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.