aws-cdk.aws-bedrock-agentcore-alpha 2.224.0a0__py3-none-any.whl → 2.229.1a0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of aws-cdk.aws-bedrock-agentcore-alpha might be problematic. Click here for more details.

@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: aws-cdk.aws-bedrock-agentcore-alpha
3
- Version: 2.224.0a0
3
+ Version: 2.229.1a0
4
4
  Summary: The CDK Construct Library for Amazon Bedrock
5
5
  Home-page: https://github.com/aws/aws-cdk
6
6
  Author: Amazon Web Services
@@ -22,8 +22,8 @@ Requires-Python: ~=3.9
22
22
  Description-Content-Type: text/markdown
23
23
  License-File: LICENSE
24
24
  License-File: NOTICE
25
- Requires-Dist: aws-cdk-lib <3.0.0,>=2.224.0
26
- Requires-Dist: aws-cdk.aws-bedrock-alpha ==2.224.0.a0
25
+ Requires-Dist: aws-cdk-lib <3.0.0,>=2.229.1
26
+ Requires-Dist: aws-cdk.aws-bedrock-alpha ==2.229.1.a0
27
27
  Requires-Dist: constructs <11.0.0,>=10.0.0
28
28
  Requires-Dist: jsii <2.0.0,>=1.119.0
29
29
  Requires-Dist: publication >=0.0.3
@@ -53,6 +53,8 @@ Requires-Dist: typeguard <4.3.0,>=2.13.3
53
53
 
54
54
  This construct library facilitates the deployment of Bedrock AgentCore primitives, enabling you to create sophisticated AI applications that can interact with your systems and data sources.
55
55
 
56
+ > **Note:** Users need to ensure their CDK deployment role has the `iam:CreateServiceLinkedRole` permission for AgentCore service-linked roles.
57
+
56
58
  ## Table of contents
57
59
 
58
60
  * [AgentCore Runtime](#agentcore-runtime)
@@ -78,12 +80,104 @@ This construct library facilitates the deployment of Bedrock AgentCore primitive
78
80
  * [Code Interpreter Network Modes](#code-interpreter-network-modes)
79
81
  * [Basic Code Interpreter Creation](#basic-code-interpreter-creation)
80
82
  * [Code Interpreter IAM permissions](#code-interpreter-iam-permissions)
83
+ * [Gateway](#gateway)
84
+
85
+ * [Gateway Properties](#gateway-properties)
86
+ * [Basic Gateway Creation](#basic-gateway-creation)
87
+ * [Protocol configuration](#protocol-configuration)
88
+ * [Inbound authorization](#inbound-authorization)
89
+ * [Gateway with KMS Encryption](#gateway-with-kms-encryption)
90
+ * [Gateway with Custom Execution Role](#gateway-with-custom-execution-role)
91
+ * [Gateway IAM Permissions](#gateway-iam-permissions)
92
+ * [Gateway Target](#gateway-target)
93
+
94
+ * [Gateway Target Properties](#gateway-target-properties)
95
+ * [Targets types](#targets-types)
96
+ * [Outbound auth](#outbound-auth)
97
+ * [Api schema](#api-schema-for-openapi-and-smithy-target)
98
+ * [Basic Gateway Target Creation](#basic-gateway-target-creation)
99
+
100
+ * [Using addTarget methods (Recommended)](#using-addtarget-methods-recommended)
101
+ * [Using static factory methods](#using-static-factory-methods)
102
+ * [Lambda Target with Tool Schema](#tools-schema-for-lambda-target)
103
+ * [Smithy Model Target with OAuth](#api-schema-for-openapi-and-smithy-target)
104
+ * [Gateway Target IAM Permissions](#gateway-target-iam-permissions)
81
105
  * [Memory](#memory)
82
106
 
83
107
  * [Memory properties](#memory-properties)
84
108
  * [Basic Memory Creation](#basic-memory-creation)
85
109
  * [LTM Memory Extraction Stategies](#ltm-memory-extraction-stategies)
86
110
  * [Memory Strategy Methods](#memory-strategy-methods)
111
+ * [Amazon Bedrock AgentCore Construct Library](#amazon-bedrock-agentcore-construct-library)
112
+
113
+ * [Table of contents](#table-of-contents)
114
+ * [AgentCore Runtime](#agentcore-runtime)
115
+
116
+ * [Runtime Endpoints](#runtime-endpoints)
117
+ * [AgentCore Runtime Properties](#agentcore-runtime-properties)
118
+ * [Runtime Endpoint Properties](#runtime-endpoint-properties)
119
+ * [Creating a Runtime](#creating-a-runtime)
120
+
121
+ * [Option 1: Use an existing image in ECR](#option-1-use-an-existing-image-in-ecr)
122
+ * [Option 2: Use a local asset](#option-2-use-a-local-asset)
123
+ * [Option 3: Use direct code deployment](#option-3-use-direct-code-deployment)
124
+ * [Granting Permissions to Invoke Bedrock Models or Inference Profiles](#granting-permissions-to-invoke-bedrock-models-or-inference-profiles)
125
+ * [Runtime Versioning](#runtime-versioning)
126
+
127
+ * [Managing Endpoints and Versions](#managing-endpoints-and-versions)
128
+
129
+ * [Step 1: Initial Deployment](#step-1-initial-deployment)
130
+ * [Step 2: Creating Custom Endpoints](#step-2-creating-custom-endpoints)
131
+ * [Step 3: Runtime Update Deployment](#step-3-runtime-update-deployment)
132
+ * [Step 4: Testing with Staging Endpoints](#step-4-testing-with-staging-endpoints)
133
+ * [Step 5: Promoting to Production](#step-5-promoting-to-production)
134
+ * [Creating Standalone Runtime Endpoints](#creating-standalone-runtime-endpoints)
135
+
136
+ * [Example: Creating an endpoint for an existing runtime](#example-creating-an-endpoint-for-an-existing-runtime)
137
+ * [Runtime Authentication Configuration](#runtime-authentication-configuration)
138
+
139
+ * [IAM Authentication (Default)](#iam-authentication-default)
140
+ * [Cognito Authentication](#cognito-authentication)
141
+ * [JWT Authentication](#jwt-authentication)
142
+ * [OAuth Authentication](#oauth-authentication)
143
+ * [Using a Custom IAM Role](#using-a-custom-iam-role)
144
+ * [Runtime Network Configuration](#runtime-network-configuration)
145
+
146
+ * [Public Network Mode (Default)](#public-network-mode-default)
147
+ * [VPC Network Mode](#vpc-network-mode)
148
+ * [Managing Security Groups with VPC Configuration](#managing-security-groups-with-vpc-configuration)
149
+ * [Browser](#browser)
150
+
151
+ * [Browser Network modes](#browser-network-modes)
152
+ * [Browser Properties](#browser-properties)
153
+ * [Basic Browser Creation](#basic-browser-creation)
154
+ * [Browser with Tags](#browser-with-tags)
155
+ * [Browser with VPC](#browser-with-vpc)
156
+ * [Browser with Recording Configuration](#browser-with-recording-configuration)
157
+ * [Browser with Custom Execution Role](#browser-with-custom-execution-role)
158
+ * [Browser with S3 Recording and Permissions](#browser-with-s3-recording-and-permissions)
159
+ * [Browser IAM Permissions](#browser-iam-permissions)
160
+ * [Code Interpreter](#code-interpreter)
161
+
162
+ * [Code Interpreter Network Modes](#code-interpreter-network-modes)
163
+ * [Code Interpreter Properties](#code-interpreter-properties)
164
+ * [Basic Code Interpreter Creation](#basic-code-interpreter-creation)
165
+ * [Code Interpreter with VPC](#code-interpreter-with-vpc)
166
+ * [Code Interpreter with Sandbox Network Mode](#code-interpreter-with-sandbox-network-mode)
167
+ * [Code Interpreter with Custom Execution Role](#code-interpreter-with-custom-execution-role)
168
+ * [Code Interpreter IAM Permissions](#code-interpreter-iam-permissions)
169
+ * [Code interpreter with tags](#code-interpreter-with-tags)
170
+ * [Memory](#memory)
171
+
172
+ * [Memory Properties](#memory-properties)
173
+ * [Basic Memory Creation](#basic-memory-creation)
174
+ * [LTM Memory Extraction Stategies](#ltm-memory-extraction-stategies)
175
+ * [Memory with Built-in Strategies](#memory-with-built-in-strategies)
176
+ * [Memory with custom Strategies](#memory-with-custom-strategies)
177
+
178
+ * [Memory with Custom Execution Role](#memory-with-custom-execution-role)
179
+ * [Memory with self-managed Strategies](#memory-with-self-managed-strategies)
180
+ * [Memory Strategy Methods](#memory-strategy-methods)
87
181
 
88
182
  ## AgentCore Runtime
89
183
 
@@ -119,6 +213,8 @@ to production by simply updating the endpoint to point to the newer version.
119
213
  | `authorizerConfiguration` | `RuntimeAuthorizerConfiguration` | No | Authorizer configuration for the agent runtime. Use `RuntimeAuthorizerConfiguration` static methods to create configurations for IAM, Cognito, JWT, or OAuth authentication |
120
214
  | `environmentVariables` | `{ [key: string]: string }` | No | Environment variables for the agent runtime. Maximum 50 environment variables |
121
215
  | `tags` | `{ [key: string]: string }` | No | Tags for the agent runtime. A list of key:value pairs of tags to apply to this Runtime resource |
216
+ | `lifecycleConfiguration` | LifecycleConfiguration | No | The life cycle configuration for the AgentCore Runtime. Defaults to 900 seconds (15 minutes) for idle, 28800 seconds (8 hours) for max life time |
217
+ | `requestHeaderConfiguration` | RequestHeaderConfiguration | No | Configuration for HTTP request headers that will be passed through to the runtime. Defaults to no configuration |
122
218
 
123
219
  ### Runtime Endpoint Properties
124
220
 
@@ -151,28 +247,11 @@ runtime = agentcore.Runtime(self, "MyAgentRuntime",
151
247
  )
152
248
  ```
153
249
 
154
- To grant the runtime permission to invoke a Bedrock model or inference profile:
155
-
156
- ```python
157
- # Note: This example uses @aws-cdk/aws-bedrock-alpha which must be installed separately
158
- # runtime: agentcore.Runtime
159
-
160
-
161
- # Create a cross-region inference profile for Claude 3.7 Sonnet
162
- inference_profile = bedrock.CrossRegionInferenceProfile.from_config(
163
- geo_region=bedrock.CrossRegionInferenceProfileRegion.US,
164
- model=bedrock.BedrockFoundationModel.ANTHROPIC_CLAUDE_3_7_SONNET_V1_0
165
- )
166
-
167
- # Grant the runtime permission to invoke the inference profile
168
- inference_profile.grant_invoke(runtime)
169
- ```
170
-
171
250
  #### Option 2: Use a local asset
172
251
 
173
252
  Reference a local directory containing a Dockerfile.
174
253
  Images are built from a local Docker context directory (with a Dockerfile), uploaded to Amazon Elastic Container Registry (ECR)
175
- by the CDK toolkit,and can be naturally referenced in your CDK app .
254
+ by the CDK toolkit,and can be naturally referenced in your CDK app.
176
255
 
177
256
  ```python
178
257
  agent_runtime_artifact = agentcore.AgentRuntimeArtifact.from_asset(
@@ -184,6 +263,61 @@ runtime = agentcore.Runtime(self, "MyAgentRuntime",
184
263
  )
185
264
  ```
186
265
 
266
+ #### Option 3: Use direct code deployment
267
+
268
+ With the container deployment method, developers create a Dockerfile, build ARM-compatible containers, manage ECR repositories, and upload containers for code changes. This works well where container DevOps pipelines have already been established to automate deployments.
269
+
270
+ However, customers looking for fully managed deployments can benefit from direct code deployment, which can significantly improve developer time and productivity. Direct code deployment provides a secure and scalable path forward for rapid prototyping agent capabilities to deploying production workloads at scale.
271
+
272
+ With direct code deployment, developers create a zip archive of code and dependencies, upload to Amazon S3, and configure the bucket in the agent configuration. A ZIP archive containing Linux arm64 dependencies needs to be uploaded to S3 as a pre-requisite to Create Agent Runtime.
273
+
274
+ For more information, please refer to the [documentation](https://docs.aws.amazon.com/bedrock-agentcore/latest/devguide/runtime-get-started-code-deploy.html).
275
+
276
+ ```python
277
+ # S3 bucket containing the agent core
278
+ code_bucket = s3.Bucket(self, "AgentCode",
279
+ bucket_name="my-code-bucket",
280
+ removal_policy=RemovalPolicy.DESTROY
281
+ )
282
+
283
+ # the bucket above needs to contain the agent code
284
+
285
+ agent_runtime_artifact = agentcore.AgentRuntimeArtifact.from_s3(s3.Location(
286
+ bucket_name=code_bucket.bucket_name,
287
+ object_key="deployment_package.zip"
288
+ ), agentcore.AgentCoreRuntime.PYTHON_3_12, ["opentelemetry-instrument", "main.py"])
289
+
290
+ runtime_instance = agentcore.Runtime(self, "MyAgentRuntime",
291
+ runtime_name="myAgent",
292
+ agent_runtime_artifact=agent_runtime_artifact
293
+ )
294
+ ```
295
+
296
+ ### Granting Permissions to Invoke Bedrock Models or Inference Profiles
297
+
298
+ To grant the runtime permissions to invoke Bedrock models or inference profiles:
299
+
300
+ ```python
301
+ # Note: This example uses @aws-cdk/aws-bedrock-alpha which must be installed separately
302
+ # runtime: agentcore.Runtime
303
+
304
+
305
+ # Define the Bedrock Foundation Model
306
+ model = bedrock.BedrockFoundationModel.ANTHROPIC_CLAUDE_3_7_SONNET_V1_0
307
+
308
+ # Grant the runtime permissions to invoke the model
309
+ model.grant_invoke(runtime)
310
+
311
+ # Create a cross-region inference profile for Claude 3.7 Sonnet
312
+ inference_profile = bedrock.CrossRegionInferenceProfile.from_config(
313
+ geo_region=bedrock.CrossRegionInferenceProfileRegion.US,
314
+ model=bedrock.BedrockFoundationModel.ANTHROPIC_CLAUDE_3_7_SONNET_V1_0
315
+ )
316
+
317
+ # Grant the runtime permissions to invoke the inference profile
318
+ inference_profile.grant_invoke(runtime)
319
+ ```
320
+
187
321
  ### Runtime Versioning
188
322
 
189
323
  Amazon Bedrock AgentCore automatically manages runtime versioning to ensure safe deployments and rollback capabilities.
@@ -479,6 +613,58 @@ runtime.connections.allow_to(database_security_group, ec2.Port.tcp(5432), "Allow
479
613
  runtime.connections.allow_to_any_ipv4(ec2.Port.tcp(443), "Allow HTTPS outbound")
480
614
  ```
481
615
 
616
+ ### Other configuration
617
+
618
+ #### Lifecycle configuration
619
+
620
+ The LifecycleConfiguration input parameter to CreateAgentRuntime lets you manage the lifecycle of runtime sessions and resources in Amazon Bedrock AgentCore Runtime. This configuration helps optimize resource utilization by automatically cleaning up idle sessions and preventing long-running instances from consuming resources indefinitely.
621
+
622
+ You can configure:
623
+
624
+ * idleRuntimeSessionTimeout: Timeout in seconds for idle runtime sessions. When a session remains idle for this duration, it will trigger termination. Termination can last up to 15 seconds due to logging and other process completion. Default: 900 seconds (15 minutes)
625
+ * maxLifetime: Maximum lifetime for the instance in seconds. Once reached, instances will initialize termination. Termination can last up to 15 seconds due to logging and other process completion. Default: 28800 seconds (8 hours)
626
+
627
+ For additional information, please refer to the [documentation](https://docs.aws.amazon.com/bedrock-agentcore/latest/devguide/runtime-lifecycle-settings.html).
628
+
629
+ ```python
630
+ repository = ecr.Repository(self, "TestRepository",
631
+ repository_name="test-agent-runtime"
632
+ )
633
+
634
+ agent_runtime_artifact = agentcore.AgentRuntimeArtifact.from_ecr_repository(repository, "v1.0.0")
635
+
636
+ agentcore.Runtime(self, "test-runtime",
637
+ runtime_name="test_runtime",
638
+ agent_runtime_artifact=agent_runtime_artifact,
639
+ lifecycle_configuration=agentcore.LifecycleConfiguration(
640
+ idle_runtime_session_timeout=Duration.minutes(10),
641
+ max_lifetime=Duration.hours(4)
642
+ )
643
+ )
644
+ ```
645
+
646
+ #### Request header configuration
647
+
648
+ Custom headers let you pass contextual information from your application directly to your agent code without cluttering the main request payload. This includes authentication tokens like JWT (JSON Web Tokens, which contain user identity and authorization claims) through the Authorization header, allowing your agent to make decisions based on who is calling it. You can also pass custom metadata like user preferences, session identifiers, or trace context using headers prefixed with X-Amzn-Bedrock-AgentCore-Runtime-Custom-, giving your agent access to up to 20 pieces of runtime context that travel alongside each request. This information can be also used in downstream systems like AgentCore Memory that you can namespace based on those characteristics like user_id or aud in claims like line of business.
649
+
650
+ For additional information, please refer to the [documentation](https://docs.aws.amazon.com/bedrock-agentcore/latest/devguide/runtime-header-allowlist.html).
651
+
652
+ ```python
653
+ repository = ecr.Repository(self, "TestRepository",
654
+ repository_name="test-agent-runtime"
655
+ )
656
+
657
+ agent_runtime_artifact = agentcore.AgentRuntimeArtifact.from_ecr_repository(repository, "v1.0.0")
658
+
659
+ agentcore.Runtime(self, "test-runtime",
660
+ runtime_name="test_runtime",
661
+ agent_runtime_artifact=agent_runtime_artifact,
662
+ request_header_configuration=agentcore.RequestHeaderConfiguration(
663
+ allowlisted_headers=["X-Amzn-Bedrock-AgentCore-Runtime-Custom-H1"]
664
+ )
665
+ )
666
+ ```
667
+
482
668
  ## Browser
483
669
 
484
670
  The Amazon Bedrock AgentCore Browser provides a secure, cloud-based browser that enables AI agents to interact with websites. It includes security features such as session isolation, built-in observability through live viewing, CloudTrail logging, and session replay capabilities.
@@ -518,6 +704,7 @@ For more information on VPC connectivity for Amazon Bedrock AgentCore Browser, p
518
704
  | `recordingConfig` | `RecordingConfig` | No | Recording configuration for browser. Defaults to no recording |
519
705
  | `executionRole` | `iam.IRole` | No | The IAM role that provides permissions for the browser to access AWS services. A new role will be created if not provided |
520
706
  | `tags` | `{ [key: string]: string }` | No | Tags to apply to the browser resource |
707
+ | `browserSigning` | BrowserSigning | No | Browser signing configuration. Defaults to DISABLED |
521
708
 
522
709
  ### Basic Browser Creation
523
710
 
@@ -641,6 +828,21 @@ browser = agentcore.BrowserCustom(self, "MyBrowser",
641
828
  )
642
829
  ```
643
830
 
831
+ ### Browser with Browser signing
832
+
833
+ AI agents need to browse the web on your behalf. When your agent visits a website to gather information, complete a form, or verify data, it encounters the same defenses designed to stop unwanted bots: CAPTCHAs, rate limits, and outright blocks.
834
+
835
+ Amazon Bedrock AgentCore Browser supports Web Bot Auth. Web Bot Auth is a draft IETF protocol that gives agents verifiable cryptographic identities. When you enable Web Bot Auth in AgentCore Browser, the service issues cryptographic credentials that websites can verify. The agent presents these credentials with every request. The WAF may now additionally check the signature, confirm it matches a trusted directory, and allow the request through if verified bots are allowed by the domain owner and other WAF checks are clear.
836
+
837
+ To enable the browser to sign requests using the Web Bot Auth protocol, create a browser tool with the browserSigning configuration:
838
+
839
+ ```python
840
+ browser = agentcore.BrowserCustom(self, "test-browser",
841
+ browser_custom_name="test_browser",
842
+ browser_signing=agentcore.BrowserSigning.ENABLED
843
+ )
844
+ ```
845
+
644
846
  ### Browser IAM Permissions
645
847
 
646
848
  The Browser construct provides convenient methods for granting IAM permissions:
@@ -822,6 +1024,761 @@ code_interpreter = agentcore.CodeInterpreterCustom(self, "MyCodeInterpreter",
822
1024
  )
823
1025
  ```
824
1026
 
1027
+ ## Gateway
1028
+
1029
+ The Gateway construct provides a way to create Amazon Bedrock Agent Core Gateways, which serve as integration points between agents and external services.
1030
+
1031
+ ### Gateway Properties
1032
+
1033
+ | Name | Type | Required | Description |
1034
+ |------|------|----------|-------------|
1035
+ | `gatewayName` | `string` | Yes | The name of the gateway. Valid characters are a-z, A-Z, 0-9, _ (underscore) and - (hyphen). Maximum 100 characters |
1036
+ | `description` | `string` | No | Optional description for the gateway. Maximum 200 characters |
1037
+ | `protocolConfiguration` | `IGatewayProtocolConfig` | No | The protocol configuration for the gateway. Defaults to MCP protocol |
1038
+ | `authorizerConfiguration` | `IGatewayAuthorizerConfig` | No | The authorizer configuration for the gateway. Defaults to Cognito |
1039
+ | `exceptionLevel` | `GatewayExceptionLevel` | No | The verbosity of exception messages. Use DEBUG mode to see granular exception messages |
1040
+ | `kmsKey` | `kms.IKey` | No | The AWS KMS key used to encrypt data associated with the gateway |
1041
+ | `role` | `iam.IRole` | No | The IAM role that provides permissions for the gateway to access AWS services. A new role will be created if not provided |
1042
+ | `tags` | `{ [key: string]: string }` | No | Tags for the gateway. A list of key:value pairs of tags to apply to this Gateway resource |
1043
+
1044
+ ### Basic Gateway Creation
1045
+
1046
+ The protocol configuration defaults to MCP and the inbound auth configuration uses Cognito (it is automatically created on your behalf).
1047
+
1048
+ ```python
1049
+ # Create a basic gateway with default MCP protocol and Cognito authorizer
1050
+ gateway = agentcore.Gateway(self, "MyGateway",
1051
+ gateway_name="my-gateway"
1052
+ )
1053
+ ```
1054
+
1055
+ ### Protocol configuration
1056
+
1057
+ Currently MCP is the only protocol available. To configure it, use the `protocol` property with `McpProtocolConfiguration`:
1058
+
1059
+ * Instructions: Guidance for how to use the gateway with your tools
1060
+ * Semantic search: Smart tool discovery that finds the right tools without typical limits. It improves accuracy by finding relevant tools based on context
1061
+ * Supported versions: Which MCP protocol versions the gateway can use
1062
+
1063
+ ```python
1064
+ gateway = agentcore.Gateway(self, "MyGateway",
1065
+ gateway_name="my-gateway",
1066
+ protocol_configuration=agentcore.McpProtocolConfiguration(
1067
+ instructions="Use this gateway to connect to external MCP tools",
1068
+ search_type=agentcore.McpGatewaySearchType.SEMANTIC,
1069
+ supported_versions=[agentcore.MCPProtocolVersion.MCP_2025_03_26]
1070
+ )
1071
+ )
1072
+ ```
1073
+
1074
+ ### Inbound authorization
1075
+
1076
+ Before you create your gateway, you must set up inbound authorization. Inbound authorization validates users who attempt to access targets through
1077
+ your AgentCore gateway. By default, if not provided, the construct will create and configure Cognito as the default identity provider
1078
+ (inbound Auth setup). AgentCore supports the following types of inbound authorization:
1079
+
1080
+ **JSON Web Token (JWT)** – A secure and compact token used for authorization. After creating the JWT, you specify it as the authorization
1081
+ configuration when you create the gateway. You can create a JWT with any of the identity providers at Provider setup and configuration.
1082
+
1083
+ You can configure a custom authorization provider using the `inboundAuthorizer` property with `GatewayAuthorizer.usingCustomJwt()`.
1084
+ You need to specify an OAuth discovery server and client IDs/audiences when you create the gateway. You can specify the following:
1085
+
1086
+ * Discovery Url — String that must match the pattern ^.+/.well-known/openid-configuration$ for OpenID Connect discovery URLs
1087
+ * At least one of the below options depending on the chosen identity provider.
1088
+ * Allowed audiences — List of allowed audiences for JWT tokens
1089
+ * Allowed clients — List of allowed client identifiers
1090
+
1091
+ ```python
1092
+ gateway = agentcore.Gateway(self, "MyGateway",
1093
+ gateway_name="my-gateway",
1094
+ authorizer_configuration=agentcore.GatewayAuthorizer.using_custom_jwt(
1095
+ discovery_url="https://auth.example.com/.well-known/openid-configuration",
1096
+ allowed_audience=["my-app"],
1097
+ allowed_clients=["my-client-id"]
1098
+ )
1099
+ )
1100
+ ```
1101
+
1102
+ **IAM** – Authorizes through the credentials of the AWS IAM identity trying to access the gateway.
1103
+
1104
+ ```python
1105
+ gateway = agentcore.Gateway(self, "MyGateway",
1106
+ gateway_name="my-gateway",
1107
+ authorizer_configuration=agentcore.GatewayAuthorizer.using_aws_iam()
1108
+ )
1109
+
1110
+ # Grant access to a Lambda function's role
1111
+ lambda_role = iam.Role(self, "LambdaRole",
1112
+ assumed_by=iam.ServicePrincipal("lambda.amazonaws.com")
1113
+ )
1114
+
1115
+ # The Lambda needs permission to invoke the gateway
1116
+ gateway.grant_invoke(lambda_role)
1117
+ ```
1118
+
1119
+ ### Gateway with KMS Encryption
1120
+
1121
+ You can provide a KMS key, and configure the authorizer as well as the protocol configuration.
1122
+
1123
+ ```python
1124
+ # Create a KMS key for encryption
1125
+ encryption_key = kms.Key(self, "GatewayEncryptionKey",
1126
+ enable_key_rotation=True,
1127
+ description="KMS key for gateway encryption"
1128
+ )
1129
+
1130
+ # Create gateway with KMS encryption
1131
+ gateway = agentcore.Gateway(self, "MyGateway",
1132
+ gateway_name="my-encrypted-gateway",
1133
+ description="Gateway with KMS encryption",
1134
+ protocol_configuration=agentcore.McpProtocolConfiguration(
1135
+ instructions="Use this gateway to connect to external MCP tools",
1136
+ search_type=agentcore.McpGatewaySearchType.SEMANTIC,
1137
+ supported_versions=[agentcore.MCPProtocolVersion.MCP_2025_03_26]
1138
+ ),
1139
+ authorizer_configuration=agentcore.GatewayAuthorizer.using_custom_jwt(
1140
+ discovery_url="https://auth.example.com/.well-known/openid-configuration",
1141
+ allowed_audience=["my-app"],
1142
+ allowed_clients=["my-client-id"]
1143
+ ),
1144
+ kms_key=encryption_key,
1145
+ exception_level=agentcore.GatewayExceptionLevel.DEBUG
1146
+ )
1147
+ ```
1148
+
1149
+ ### Gateway with Custom Execution Role
1150
+
1151
+ ```python
1152
+ # Create a custom execution role
1153
+ execution_role = iam.Role(self, "GatewayExecutionRole",
1154
+ assumed_by=iam.ServicePrincipal("bedrock-agentcore.amazonaws.com"),
1155
+ managed_policies=[
1156
+ iam.ManagedPolicy.from_aws_managed_policy_name("AmazonBedrockAgentCoreGatewayExecutionRolePolicy")
1157
+ ]
1158
+ )
1159
+
1160
+ # Create gateway with custom execution role
1161
+ gateway = agentcore.Gateway(self, "MyGateway",
1162
+ gateway_name="my-gateway",
1163
+ description="Gateway with custom execution role",
1164
+ protocol_configuration=agentcore.McpProtocolConfiguration(
1165
+ instructions="Use this gateway to connect to external MCP tools",
1166
+ search_type=agentcore.McpGatewaySearchType.SEMANTIC,
1167
+ supported_versions=[agentcore.MCPProtocolVersion.MCP_2025_03_26]
1168
+ ),
1169
+ authorizer_configuration=agentcore.GatewayAuthorizer.using_custom_jwt(
1170
+ discovery_url="https://auth.example.com/.well-known/openid-configuration",
1171
+ allowed_audience=["my-app"],
1172
+ allowed_clients=["my-client-id"]
1173
+ ),
1174
+ role=execution_role
1175
+ )
1176
+ ```
1177
+
1178
+ ### Gateway IAM Permissions
1179
+
1180
+ The Gateway construct provides convenient methods for granting IAM permissions:
1181
+
1182
+ ```python
1183
+ # Create a gateway
1184
+ gateway = agentcore.Gateway(self, "MyGateway",
1185
+ gateway_name="my-gateway",
1186
+ description="Gateway for external service integration",
1187
+ protocol_configuration=agentcore.McpProtocolConfiguration(
1188
+ instructions="Use this gateway to connect to external MCP tools",
1189
+ search_type=agentcore.McpGatewaySearchType.SEMANTIC,
1190
+ supported_versions=[agentcore.MCPProtocolVersion.MCP_2025_03_26]
1191
+ ),
1192
+ authorizer_configuration=agentcore.GatewayAuthorizer.using_custom_jwt(
1193
+ discovery_url="https://auth.example.com/.well-known/openid-configuration",
1194
+ allowed_audience=["my-app"],
1195
+ allowed_clients=["my-client-id"]
1196
+ )
1197
+ )
1198
+
1199
+ # Create a role that needs access to the gateway
1200
+ user_role = iam.Role(self, "UserRole",
1201
+ assumed_by=iam.ServicePrincipal("lambda.amazonaws.com")
1202
+ )
1203
+
1204
+ # Grant read permissions (Get and List actions)
1205
+ gateway.grant_read(user_role)
1206
+
1207
+ # Grant manage permissions (Create, Update, Delete actions)
1208
+ gateway.grant_manage(user_role)
1209
+
1210
+ # Grant specific custom permissions
1211
+ gateway.grant(user_role, "bedrock-agentcore:GetGateway")
1212
+ ```
1213
+
1214
+ ## Gateway Target
1215
+
1216
+ After Creating gateways, you can add targets which define the tools that your gateway will host. Gateway supports multiple target
1217
+ types including Lambda functions and API specifications (either OpenAPI schemas or Smithy models). Gateway allows you to attach multiple
1218
+ targets to a Gateway and you can change the targets / tools attached to a gateway at any point. Each target can have its own
1219
+ credential provider attached enabling you to securely access targets whether they need IAM, API Key, or OAuth credentials.
1220
+
1221
+ ### Gateway Target Properties
1222
+
1223
+ | Name | Type | Required | Description |
1224
+ |------|------|----------|-------------|
1225
+ | `gatewayTargetName` | `string` | Yes | The name of the gateway target. Valid characters are a-z, A-Z, 0-9, _ (underscore) and - (hyphen) |
1226
+ | `description` | `string` | No | Optional description for the gateway target. Maximum 200 characters |
1227
+ | `gateway` | `IGateway` | Yes | The gateway this target belongs to |
1228
+ | `targetConfiguration` | `ITargetConfiguration` | Yes | The target configuration (Lambda, OpenAPI, or Smithy). **Note:** Users typically don't create this directly. When using convenience methods like `GatewayTarget.forLambda()`, `GatewayTarget.forOpenApi()`, `GatewayTarget.forSmithy()` or the gateway's `addLambdaTarget()`, `addOpenApiTarget()`, `addSmithyTarget()` methods, this configuration is created internally for you. Only needed when using the GatewayTarget constructor directly for [advanced scenarios](#advanced-usage-direct-configuration-for-gateway-target). |
1229
+ | `credentialProviderConfigurations` | `IGatewayCredentialProvider[]` | No | Credential providers for authentication. Defaults to `[GatewayCredentialProvider.fromIamRole()]`. Use `GatewayCredentialProvider.fromApiKeyIdentityArn()`, `GatewayCredentialProvider.fromOauthIdentityArn()`, or `GatewayCredentialProvider.fromIamRole()` |
1230
+ | `validateOpenApiSchema` | `boolean` | No | (OpenAPI targets only) Whether to validate the OpenAPI schema at synthesis time. Defaults to `true`. Only applies to inline and local asset schemas. For more information refer here [https://docs.aws.amazon.com/bedrock-agentcore/latest/devguide/gateway-schema-openapi.html](https://docs.aws.amazon.com/bedrock-agentcore/latest/devguide/gateway-schema-openapi.html) |
1231
+
1232
+ This approach gives you full control over the configuration but is typically not necessary for most use cases.
1233
+
1234
+ ### Targets types
1235
+
1236
+ You can create the following targets types:
1237
+
1238
+ **Lambda Target**: Lambda targets allow you to connect your gateway to AWS Lambda functions that implement your tools. This is useful
1239
+ when you want to execute custom code in response to tool invocations.
1240
+
1241
+ * Supports GATEWAY_IAM_ROLE credential provider only
1242
+ * Ideal for custom serverless function integration
1243
+ * Need tool schema (tool schema is a blueprint that describes the functions your Lambda provides to AI agents).
1244
+ The construct provide [3 ways to upload a tool schema to Lambda target](#tools-schema-for-lambda-target)
1245
+ * When using the default IAM authentication (no `credentialProviderConfigurations` specified),
1246
+ the construct automatocally grants the gateway role permission to invoke your Lambda function (`lambda:InvokeFunction`).
1247
+
1248
+ **OpenAPI Schema Target** : OpenAPI widely used standard for describing RESTful APIs. Gateway supports OpenAPI 3.0
1249
+ specifications for defining API targets. It connects to REST APIs using OpenAPI specifications
1250
+
1251
+ * Supports OAUTH and API_KEY credential providers (Do not support IAM, you must provide `credentialProviderConfigurations`)
1252
+ * Ideal for integrating with external REST services
1253
+ * Need API schema. The construct provide [3 ways to upload a API schema to OpenAPI target](#api-schema-for-openapi-and-smithy-target)
1254
+
1255
+ **Smithy Model Target** : Smithy is a language for defining services and software development kits (SDKs). Smithy models provide
1256
+ a more structured approach to defining APIs compared to OpenAPI, and are particularly useful for connecting to AWS services.
1257
+ AgentCore Gateway supports built-in AWS service models only. It connects to services using Smithy model definitions
1258
+
1259
+ * Supports OAUTH and API_KEY credential providers
1260
+ * Ideal for AWS service integrations
1261
+ * Need API schema. The construct provide 3 ways to upload a API schema to Smity target
1262
+ * When using the default IAM authentication (no `credentialProviderConfigurations` specified), The construct only
1263
+ grants permission to read the Smithy schema file from S3. You MUST manually grant permissions for the gateway
1264
+ role to invoke the actual Smithy API endpoints
1265
+
1266
+ > Note: For Smithy model targets that access AWS services, your Gateway's execution role needs permissions to access those services.
1267
+ > For example, for a DynamoDB target, your execution role needs permissions to perform DynamoDB operations.
1268
+ > This is not managed by the construct due to the large number of options. Please refer to
1269
+ > [Smithy Model Permission](https://docs.aws.amazon.com/bedrock-agentcore/latest/devguide/gateway-prerequisites-permissions.html) for example.
1270
+
1271
+ **MCP Server Target**: Model Context Protocol (MCP) servers provide external tools, data access, and custom functions for AI agents.
1272
+ MCP servers enable agents to interact with external systems and services through a standardized protocol. Gateway automatically
1273
+ discovers and indexes available tools from MCP servers through synchronization.
1274
+
1275
+ **Key Features:**
1276
+
1277
+ * Requires explicit authentication configuration (OAuth2 recommended, empty array for NoAuth)
1278
+ * Ideal for connecting to external MCP-compliant servers
1279
+ * The endpoint must use HTTPS protocol
1280
+ * Supported MCP protocol versions: 2025-06-18, 2025-03-26
1281
+ * Automatic tool discovery through synchronization
1282
+
1283
+ **Synchronization Behavior:**
1284
+
1285
+ MCP Server targets require synchronization to discover and index available tools:
1286
+
1287
+ * **Implicit Synchronization (Automatic)**: Tool discovery happens automatically during:
1288
+
1289
+ * Target creation (`CreateGatewayTarget`)
1290
+ * Target updates (`UpdateGatewayTarget`)
1291
+ * The Gateway calls the MCP server's `tools/list` endpoint and indexes tools without user intervention
1292
+ * **Explicit Synchronization (Manual)**: When the MCP server's tools change independently (new tools added, schemas modified, tools removed):
1293
+
1294
+ * The Gateway's tool catalog becomes stale
1295
+ * Call the `SynchronizeGatewayTargets` API to refresh the catalog
1296
+ * Use the `grantSync()` method to grant permissions to Lambda functions, CI/CD pipelines, or scheduled tasks that will trigger synchronization
1297
+
1298
+ **Authentication & Permissions:**
1299
+
1300
+ When using OAuth2, the Gateway service role automatically receives:
1301
+
1302
+ * `bedrock-agentcore:GetWorkloadAccessToken`
1303
+ * `bedrock-agentcore:GetResourceOauth2Token`
1304
+ * `secretsmanager:GetSecretValue`
1305
+ * KMS decrypt (if secrets are encrypted)
1306
+
1307
+ For explicit synchronization, use `grantSync()` to grant `bedrock-agentcore:SynchronizeGatewayTargets` permission to your operator roles.
1308
+
1309
+ > For more information, refer to the [MCP Server Target documentation](https://docs.aws.amazon.com/bedrock-agentcore/latest/devguide/gateway-target-MCPservers.html).
1310
+
1311
+ ### Understanding Tool Naming
1312
+
1313
+ When tools are exposed through gateway targets, AgentCore Gateway prefixes each tool name with the target name to ensure uniqueness across multiple targets. This is important to understand when building your application logic.
1314
+
1315
+ **Naming Pattern:**
1316
+
1317
+ **Example:**
1318
+
1319
+ If your target is named `my-lambda-target` and provides a tool called `calculate_price`, agents will discover and invoke it as `my-lambda-target__calculate_price`.
1320
+
1321
+ **Important Considerations:**
1322
+
1323
+ * **For Lambda Targets**: Your Lambda handler must strip the target name prefix before processing the tool request. The full tool name (with prefix) is sent in the event.
1324
+ * **For MCP Server Targets**: The MCP server receives tool calls with the prefixed name from the gateway.
1325
+ * **For OpenAPI/Smithy Targets**: The gateway handles the prefix automatically when mapping to API operations based on the `operationId`.
1326
+
1327
+ This naming convention ensures that:
1328
+
1329
+ * Tools from different targets don't collide even if they have the same name
1330
+ * Agents can access tools from multiple targets through a single gateway
1331
+ * Tool names remain unique in the unified tool catalog
1332
+
1333
+ For more details, see the [Gateway Tool Naming Documentation](https://docs.aws.amazon.com/bedrock-agentcore/latest/devguide/gateway-tool-naming.html).
1334
+
1335
+ ### Tools schema For Lambda target
1336
+
1337
+ The lambda target need tools schema to understand the fuunction lambda provides. You can upload the tool schema by following 3 ways:
1338
+
1339
+ * From a local asset file
1340
+
1341
+ ```python
1342
+ tool_schema = agentcore.ToolSchema.from_local_asset(
1343
+ path.join(__dirname, "schemas", "my-tool-schema.json"))
1344
+ ```
1345
+
1346
+ * From an existing S3 file:
1347
+
1348
+ ```python
1349
+ tool_schema = agentcore.ToolSchema.from_s3_file(
1350
+ s3.Bucket.from_bucket_name(self, "SchemasBucket", "my-schemas-bucket"), "tools/complex-tool-schema.json", "123456789012")
1351
+ ```
1352
+
1353
+ * From Inline:
1354
+
1355
+ ```python
1356
+ tool_schema = agentcore.ToolSchema.from_inline([
1357
+ name="hello_world",
1358
+ description="A simple hello world tool",
1359
+ input_schema=agentcore.SchemaDefinition(
1360
+ type=agentcore.SchemaDefinitionType.OBJECT,
1361
+ properties={
1362
+ "name": agentcore.SchemaDefinition(
1363
+ type=agentcore.SchemaDefinitionType.STRING,
1364
+ description="The name to greet"
1365
+ )
1366
+ },
1367
+ required=["name"]
1368
+ )
1369
+ ])
1370
+ ```
1371
+
1372
+ ### Api schema For OpenAPI and Smithy target
1373
+
1374
+ The OpenAPI and Smithy target need API Schema. The Gateway construct provide three ways to upload API schema for your target:
1375
+
1376
+ * From a local asset file (requires binding to scope):
1377
+
1378
+ ```python
1379
+ # When using ApiSchema.fromLocalAsset, you must bind the schema to a scope
1380
+ schema = agentcore.ApiSchema.from_local_asset(path.join(__dirname, "mySchema.yml"))
1381
+
1382
+ schema.bind(self)
1383
+ ```
1384
+
1385
+ * From an inline schema:
1386
+
1387
+ ```python
1388
+ inline_schema = agentcore.ApiSchema.from_inline("""
1389
+ openapi: 3.0.3
1390
+ info:
1391
+ title: Library API
1392
+ version: 1.0.0
1393
+ paths:
1394
+ /search:
1395
+ get:
1396
+ summary: Search for books
1397
+ operationId: searchBooks
1398
+ parameters:
1399
+ - name: query
1400
+ in: query
1401
+ required: true
1402
+ schema:
1403
+ type: string
1404
+ """)
1405
+ ```
1406
+
1407
+ * From an existing S3 file:
1408
+
1409
+ ```python
1410
+ bucket = s3.Bucket.from_bucket_name(self, "ExistingBucket", "my-schema-bucket")
1411
+ s3_schema = agentcore.ApiSchema.from_s3_file(bucket, "schemas/action-group.yaml")
1412
+ ```
1413
+
1414
+ ### Outbound auth
1415
+
1416
+ Outbound authorization lets Amazon Bedrock AgentCore gateways securely access gateway targets on behalf of users authenticated
1417
+ and authorized during Inbound Auth.
1418
+
1419
+ AgentCore Gateway supports the following types of outbound authorization:
1420
+
1421
+ **IAM-based outbound authorization** – The gateway uses its execution role to authenticate with AWS services. This is the default
1422
+ and most common approach for Lambda targets and AWS service integrations.
1423
+
1424
+ **2-legged OAuth (OAuth 2LO)** – Use OAuth 2.0 two-legged flow (2LO) for targets that require OAuth authentication.
1425
+ The gateway authenticates on its own behalf, not on behalf of a user.
1426
+
1427
+ **API key** – Use the AgentCore service/AWS console to generate an API key to authenticate access to the gateway target.
1428
+
1429
+ **Note > You need to set up the outbound identity before you can create a gateway target.
1430
+
1431
+ ### Basic Gateway Target Creation
1432
+
1433
+ You can create targets in two ways: using the static factory methods on `GatewayTarget` or using the convenient `addTarget` methods on the gateway instance.
1434
+
1435
+ #### Using addTarget methods (Recommended)
1436
+
1437
+ Below are the examples on how you can create Lambda , Smity and OpenAPI target using `addTarget` method.
1438
+
1439
+ ```python
1440
+ # Create a gateway first
1441
+ gateway = agentcore.Gateway(self, "MyGateway",
1442
+ gateway_name="my-gateway"
1443
+ )
1444
+
1445
+ lambda_function = lambda_.Function(self, "MyFunction",
1446
+ runtime=lambda_.Runtime.NODEJS_22_X,
1447
+ handler="index.handler",
1448
+ code=lambda_.Code.from_inline("""
1449
+ exports.handler = async (event) => {
1450
+ return {
1451
+ statusCode: 200,
1452
+ body: JSON.stringify({ message: 'Hello from Lambda!' })
1453
+ };
1454
+ };
1455
+ """)
1456
+ )
1457
+
1458
+ lambda_target = gateway.add_lambda_target("MyLambdaTarget",
1459
+ gateway_target_name="my-lambda-target",
1460
+ description="Lambda function target",
1461
+ lambda_function=lambda_function,
1462
+ tool_schema=agentcore.ToolSchema.from_inline([
1463
+ name="hello_world",
1464
+ description="A simple hello world tool",
1465
+ input_schema=agentcore.SchemaDefinition(
1466
+ type=agentcore.SchemaDefinitionType.OBJECT,
1467
+ properties={
1468
+ "name": agentcore.SchemaDefinition(
1469
+ type=agentcore.SchemaDefinitionType.STRING,
1470
+ description="The name to greet"
1471
+ )
1472
+ },
1473
+ required=["name"]
1474
+ )
1475
+
1476
+ ])
1477
+ )
1478
+ ```
1479
+
1480
+ * OpenAPI Target
1481
+
1482
+ ```python
1483
+ gateway = agentcore.Gateway(self, "MyGateway",
1484
+ gateway_name="my-gateway"
1485
+ )
1486
+
1487
+ # These ARNs are returned when creating the API key credential provider via Console or API
1488
+ api_key_provider_arn = "arn:aws:bedrock-agentcore:us-east-1:123456789012:token-vault/abc123/apikeycredentialprovider/my-apikey"
1489
+ api_key_secret_arn = "arn:aws:secretsmanager:us-east-1:123456789012:secret:my-apikey-secret-abc123"
1490
+
1491
+ bucket = s3.Bucket.from_bucket_name(self, "ExistingBucket", "my-schema-bucket")
1492
+ s3my_schema = agentcore.ApiSchema.from_s3_file(bucket, "schemas/myschema.yaml")
1493
+
1494
+ # Add an OpenAPI target directly to the gateway
1495
+ target = gateway.add_open_api_target("MyTarget",
1496
+ gateway_target_name="my-api-target",
1497
+ description="Target for external API integration",
1498
+ api_schema=s3my_schema,
1499
+ credential_provider_configurations=[
1500
+ agentcore.GatewayCredentialProvider.from_api_key_identity_arn(
1501
+ provider_arn=api_key_provider_arn,
1502
+ secret_arn=api_key_secret_arn,
1503
+ credential_location=agentcore.ApiKeyCredentialLocation.header(
1504
+ credential_parameter_name="X-API-Key"
1505
+ )
1506
+ )
1507
+ ]
1508
+ )
1509
+
1510
+ # This make sure your s3 bucket is available before target
1511
+ target.node.add_dependency(bucket)
1512
+ ```
1513
+
1514
+ * Smithy Target
1515
+
1516
+ ```python
1517
+ gateway = agentcore.Gateway(self, "MyGateway",
1518
+ gateway_name="my-gateway"
1519
+ )
1520
+
1521
+ smithy_schema = agentcore.ApiSchema.from_local_asset(
1522
+ path.join(__dirname, "models", "smithy-model.json"))
1523
+ smithy_schema.bind(self)
1524
+
1525
+ smithy_target = gateway.add_smithy_target("MySmithyTarget",
1526
+ gateway_target_name="my-smithy-target",
1527
+ description="Smithy model target",
1528
+ smithy_model=smithy_schema
1529
+ )
1530
+ ```
1531
+
1532
+ * MCP Server Target
1533
+
1534
+ ```python
1535
+ gateway = agentcore.Gateway(self, "MyGateway",
1536
+ gateway_name="my-gateway"
1537
+ )
1538
+
1539
+ # OAuth2 authentication (recommended)
1540
+ # Note: Create the OAuth provider using AWS console or Identity L2 construct when available
1541
+ oauth_provider_arn = "arn:aws:bedrock-agentcore:us-east-1:123456789012:token-vault/abc123/oauth2credentialprovider/my-oauth"
1542
+ oauth_secret_arn = "arn:aws:secretsmanager:us-east-1:123456789012:secret:my-oauth-secret-abc123"
1543
+
1544
+ # Add an MCP server target directly to the gateway
1545
+ mcp_target = gateway.add_mcp_server_target("MyMcpServer",
1546
+ gateway_target_name="my-mcp-server",
1547
+ description="External MCP server integration",
1548
+ endpoint="https://my-mcp-server.example.com",
1549
+ credential_provider_configurations=[
1550
+ agentcore.GatewayCredentialProvider.from_oauth_identity_arn(
1551
+ provider_arn=oauth_provider_arn,
1552
+ secret_arn=oauth_secret_arn,
1553
+ scopes=["mcp-runtime-server/invoke"]
1554
+ )
1555
+ ]
1556
+ )
1557
+
1558
+ # Grant sync permission to a Lambda function that will trigger synchronization
1559
+ sync_function = lambda_.Function(self, "SyncFunction",
1560
+ runtime=lambda_.Runtime.PYTHON_3_12,
1561
+ handler="index.handler",
1562
+ code=lambda_.Code.from_inline("""
1563
+ import boto3
1564
+
1565
+ def handler(event, context):
1566
+ client = boto3.client('bedrock-agentcore')
1567
+ response = client.synchronize_gateway_targets(
1568
+ gatewayIdentifier=event['gatewayId'],
1569
+ targetIds=[event['targetId']]
1570
+ )
1571
+ return response
1572
+ """)
1573
+ )
1574
+
1575
+ mcp_target.grant_sync(sync_function)
1576
+ ```
1577
+
1578
+ #### Using static factory methods
1579
+
1580
+ Create Gateway target using static convienence method.
1581
+
1582
+ * Lambda Target
1583
+
1584
+ ```python
1585
+ gateway = agentcore.Gateway(self, "MyGateway",
1586
+ gateway_name="my-gateway"
1587
+ )
1588
+
1589
+ lambda_function = lambda_.Function(self, "MyFunction",
1590
+ runtime=lambda_.Runtime.NODEJS_22_X,
1591
+ handler="index.handler",
1592
+ code=lambda_.Code.from_inline("""
1593
+ exports.handler = async (event) => {
1594
+ return {
1595
+ statusCode: 200,
1596
+ body: JSON.stringify({ message: 'Hello from Lambda!' })
1597
+ };
1598
+ };
1599
+ """)
1600
+ )
1601
+
1602
+ # Create a gateway target with Lambda and tool schema
1603
+ target = agentcore.GatewayTarget.for_lambda(self, "MyLambdaTarget",
1604
+ gateway_target_name="my-lambda-target",
1605
+ description="Target for Lambda function integration",
1606
+ gateway=gateway,
1607
+ lambda_function=lambda_function,
1608
+ tool_schema=agentcore.ToolSchema.from_local_asset(
1609
+ path.join(__dirname, "schemas", "my-tool-schema.json"))
1610
+ )
1611
+ ```
1612
+
1613
+ * OpenAPI Target
1614
+
1615
+ ```python
1616
+ gateway = agentcore.Gateway(self, "MyGateway",
1617
+ gateway_name="my-gateway"
1618
+ )
1619
+
1620
+ # outbound auth (Use AWS console to create it, Once Identity L2 construct is available you can use it to create identity)
1621
+ api_key_identity_arn = "arn:aws:bedrock-agentcore:us-east-1:123456789012:token-vault/abc123/apikeycredentialprovider/my-apikey"
1622
+ api_key_secret_arn = "arn:aws:secretsmanager:us-east-1:123456789012:secret:my-apikey-secret-abc123"
1623
+
1624
+ opneapi_schema = agentcore.ApiSchema.from_local_asset(path.join(__dirname, "mySchema.yml"))
1625
+ opneapi_schema.bind(self)
1626
+
1627
+ # Create a gateway target with OpenAPI Schema
1628
+ target = agentcore.GatewayTarget.for_open_api(self, "MyTarget",
1629
+ gateway_target_name="my-api-target",
1630
+ description="Target for external API integration",
1631
+ gateway=gateway, # Note: you need to pass the gateway reference
1632
+ api_schema=opneapi_schema,
1633
+ credential_provider_configurations=[
1634
+ agentcore.GatewayCredentialProvider.from_api_key_identity_arn(
1635
+ provider_arn=api_key_identity_arn,
1636
+ secret_arn=api_key_secret_arn
1637
+ )
1638
+ ]
1639
+ )
1640
+ ```
1641
+
1642
+ * Smithy Target
1643
+
1644
+ ```python
1645
+ gateway = agentcore.Gateway(self, "MyGateway",
1646
+ gateway_name="my-gateway"
1647
+ )
1648
+
1649
+ smithy_schema = agentcore.ApiSchema.from_local_asset(
1650
+ path.join(__dirname, "models", "smithy-model.json"))
1651
+ smithy_schema.bind(self)
1652
+
1653
+ # Create a gateway target with Smithy Model and OAuth
1654
+ target = agentcore.GatewayTarget.for_smithy(self, "MySmithyTarget",
1655
+ gateway_target_name="my-smithy-target",
1656
+ description="Target for Smithy model integration",
1657
+ gateway=gateway,
1658
+ smithy_model=smithy_schema
1659
+ )
1660
+ ```
1661
+
1662
+ * MCP Server Target
1663
+
1664
+ ```python
1665
+ gateway = agentcore.Gateway(self, "MyGateway",
1666
+ gateway_name="my-gateway"
1667
+ )
1668
+
1669
+ # OAuth2 authentication (recommended)
1670
+ # Note: Create the OAuth provider using AWS console or Identity L2 construct when available
1671
+ oauth_provider_arn = "arn:aws:bedrock-agentcore:us-east-1:123456789012:token-vault/abc123/oauth2credentialprovider/my-oauth"
1672
+ oauth_secret_arn = "arn:aws:secretsmanager:us-east-1:123456789012:secret:my-oauth-secret-abc123"
1673
+
1674
+ # Create a gateway target with MCP Server
1675
+ mcp_target = agentcore.GatewayTarget.for_mcp_server(self, "MyMcpServer",
1676
+ gateway_target_name="my-mcp-server",
1677
+ description="External MCP server integration",
1678
+ gateway=gateway,
1679
+ endpoint="https://my-mcp-server.example.com",
1680
+ credential_provider_configurations=[
1681
+ agentcore.GatewayCredentialProvider.from_oauth_identity_arn(
1682
+ provider_arn=oauth_provider_arn,
1683
+ secret_arn=oauth_secret_arn,
1684
+ scopes=["mcp-runtime-server/invoke"]
1685
+ )
1686
+ ]
1687
+ )
1688
+ ```
1689
+
1690
+ ### Advanced Usage: Direct Configuration for gateway target
1691
+
1692
+ For advanced use cases where you need full control over the target configuration, you can create configurations manually using the static factory methods and use the GatewayTarget constructor directly.
1693
+
1694
+ #### Configuration Factory Methods
1695
+
1696
+ Each target type has a corresponding configuration class with a static `create()` method:
1697
+
1698
+ * **Lambda**: `LambdaTargetConfiguration.create(lambdaFunction, toolSchema)`
1699
+ * **OpenAPI**: `OpenApiTargetConfiguration.create(apiSchema, validateSchema?)`
1700
+ * **Smithy**: `SmithyTargetConfiguration.create(smithyModel)`
1701
+
1702
+ #### Example: Lambda Target with Custom Configuration
1703
+
1704
+ ```python
1705
+ gateway = agentcore.Gateway(self, "MyGateway",
1706
+ gateway_name="my-gateway"
1707
+ )
1708
+
1709
+ my_lambda_function = lambda_.Function(self, "MyFunction",
1710
+ runtime=lambda_.Runtime.NODEJS_22_X,
1711
+ handler="index.handler",
1712
+ code=lambda_.Code.from_inline("""
1713
+ exports.handler = async (event) => ({ statusCode: 200 });
1714
+ """)
1715
+ )
1716
+
1717
+ my_tool_schema = agentcore.ToolSchema.from_inline([
1718
+ name="my_tool",
1719
+ description="My custom tool",
1720
+ input_schema=agentcore.SchemaDefinition(
1721
+ type=agentcore.SchemaDefinitionType.OBJECT,
1722
+ properties={}
1723
+ )
1724
+ ])
1725
+
1726
+ # Create a custom Lambda configuration
1727
+ custom_config = agentcore.LambdaTargetConfiguration.create(my_lambda_function, my_tool_schema)
1728
+
1729
+ # Use the GatewayTarget constructor directly
1730
+ target = agentcore.GatewayTarget(self, "AdvancedTarget",
1731
+ gateway=gateway,
1732
+ gateway_target_name="advanced-target",
1733
+ target_configuration=custom_config, # Manually created configuration
1734
+ credential_provider_configurations=[
1735
+ agentcore.GatewayCredentialProvider.from_iam_role()
1736
+ ]
1737
+ )
1738
+ ```
1739
+
1740
+ This approach gives you full control over the configuration but is typically not necessary for most use cases. The convenience methods (`GatewayTarget.forLambda()`, `GatewayTarget.forOpenApi()`, `GatewayTarget.forSmithy()`) handle all of this internally.
1741
+
1742
+ ### Gateway Target IAM Permissions
1743
+
1744
+ The Gateway Target construct provides convenient methods for granting IAM permissions:
1745
+
1746
+ ```python
1747
+ # Create a gateway and target
1748
+ gateway = agentcore.Gateway(self, "MyGateway",
1749
+ gateway_name="my-gateway"
1750
+ )
1751
+
1752
+ smithy_schema = agentcore.ApiSchema.from_local_asset(
1753
+ path.join(__dirname, "models", "smithy-model.json"))
1754
+ smithy_schema.bind(self)
1755
+
1756
+ # Create a gateway target with Smithy Model and OAuth
1757
+ target = agentcore.GatewayTarget.for_smithy(self, "MySmithyTarget",
1758
+ gateway_target_name="my-smithy-target",
1759
+ description="Target for Smithy model integration",
1760
+ gateway=gateway,
1761
+ smithy_model=smithy_schema
1762
+ )
1763
+
1764
+ # Create a role that needs access to the gateway target
1765
+ user_role = iam.Role(self, "UserRole",
1766
+ assumed_by=iam.ServicePrincipal("lambda.amazonaws.com")
1767
+ )
1768
+
1769
+ # Grant read permissions (Get and List actions)
1770
+ target.grant_read(user_role)
1771
+
1772
+ # Grant manage permissions (Create, Update, Delete actions)
1773
+ target.grant_manage(user_role)
1774
+
1775
+ # Grant specific custom permissions
1776
+ target.grant(user_role, "bedrock-agentcore:GetGatewayTarget")
1777
+
1778
+ # Grants permission to invoke this Gateway
1779
+ gateway.grant_invoke(user_role)
1780
+ ```
1781
+
825
1782
  ## Memory
826
1783
 
827
1784
  Memory is a critical component of intelligence. While Large Language Models (LLMs) have impressive capabilities, they lack persistent memory across conversations. Amazon Bedrock AgentCore Memory addresses this limitation by providing a managed service that enables AI agents to maintain context over time, remember important facts, and deliver consistent, personalized experiences.