本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
使用策略引擎更新现有网关
将策略引擎与现有网关关联:
例
- AgentCore CLI
-
-
在已经包含网关的 AgentCore 项目中,将引擎连接到网关:
agentcore add policy-engine --name my_policy_engine \ --attach-to-gateways my-gateway \ --attach-mode ENFORCE -
部署以应用更改:
agentcore deploy --yesCLI 会为您
UpdateGateway发出呼叫并保留网关的其他设置。要仅更改已连接的引擎上的模式,请编辑attachModeagentcore/agentcore.json并重新部署。
-
- Amazon CLI
-
-
在终端中运行以下代码,使用 Amazon CLI 使用策略引擎更新网关:
aws bedrock-agentcore-control update-gateway \ --gateway-identifier my-gateway-id \ --name my-gateway-name \ --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.update_gateway( gatewayIdentifier='my-gateway-id', name='my-gateway-name', 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中的是您调用网关时要使用的终端节点。
-
使用策略引擎创建网关
策略实施模式