Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅
中国的 Amazon Web Services 服务入门
(PDF)。
本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
使用策略引擎创建网关
本节提供了创建网关的示例,该网关具有与策略实施相关的策略引擎。
选择以下方法之一:
例
- AgentCore CLI
-
-
在 AgentCore 项目中,添加网关并命名应强制执行的策略引擎:
agentcore add gateway --name my-gateway \
--protocol-type MCP \
--authorizer-type CUSTOM_JWT \
--discovery-url https://cognito-idp.us-west-2.amazonaws.com/some-user-pool/.well-known/openid-configuration \
--allowed-clients clientId \
--policy-engine my_policy_engine \
--policy-engine-mode ENFORCE
-
部署以在您的账户中创建这两个资源:
agentcore deploy --yes
由命名的引擎--policy-engine必须已经存在于项目中,请先添加它agentcore add policy-engine。CLI 会为您解析引擎 ARN,因此您无需事先知道。部署agentcore status后运行以读取网关 URL。
- Amazon CLI
-
-
在终端中运行以下代码,使用 Amazon CLI 创建带有策略引擎的网关:
aws bedrock-agentcore-control create-gateway \
--name my-gateway \
--role-arn arn:aws:iam::123456789012:role/my-gateway-service-role \
--protocol-type MCP \
--authorizer-type CUSTOM_JWT \
--authorizer-configuration '{
"customJWTAuthorizer": {
"discoveryUrl": "https://cognito-idp.us-west-2.amazonaws.com/some-user-pool/.well-known/openid-configuration",
"allowedClients": ["clientId"]
}
}' \
--policy-engine-configuration '{
"mode": "ENFORCE",
"arn": "arn:aws:bedrock-agentcore:us-west-2:123456789012:policy-engine/my_policy_engine-a1b2c3d4e5"
}'
响应gatewayUrl中的是您调用网关时要使用的终端节点。
- Amazon Python SDK (Boto3)
-
-
以下 Python 代码展示了如何使用 Pyt Amazon hon SDK (Boto3) 创建带有策略引擎的网关:
import boto3
gateway_client = boto3.client('bedrock-agentcore-control')
response = gateway_client.create_gateway(
name='my-gateway',
protocolType='MCP',
authorizerType='CUSTOM_JWT',
authorizerConfiguration={
'customJWTAuthorizer': {
'allowedClients': ['clientId'],
'discoveryUrl': 'https://cognito-idp.us-west-2.amazonaws.com/some-user-pool/.well-known/openid-configuration'
}
},
roleArn='arn:aws:iam::123456789012:role/my-gateway-service-role',
policyEngineConfiguration={
'mode': 'ENFORCE',
'arn': 'arn:aws:bedrock-agentcore:us-west-2:123456789012:policy-engine/my_policy_engine-a1b2c3d4e5'
}
)
print(f"GATEWAY ARN: {response['gatewayArn']}")
print(f"GATEWAY URL: {response['gatewayUrl']}")
响应gatewayUrl中的是您调用网关时要使用的终端节点。