View a markdown version of this page

使用策略引擎创建网关 - Amazon Bedrock AgentCore

使用策略引擎创建网关

本节提供了创建网关的示例,该网关具有与策略实施相关的策略引擎。

注意

* 授权配置的值来自您设置入站授权时的值。* 如果您选择的选项涉及指定公开网关服务角色 ARN,请确保指定已设置的现有网关服务角色 ARN。有关更多信息,请参阅 Amazon Bedrock AgentCore Gateway 服务角色权限。

选择以下方法之一:

AWS CLI
  1. 在终端中运行以下代码,使用 AWS 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" }'

    响应中的 GatewayURL 是您调用网关时要使用的终端节点。

AWS Python SDK (Boto3)
  1. 以下 Python 代码展示了如何使用 Pyt AWS 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' } ) print(f"GATEWAY ARN: {response['gatewayArn']}") print(f"GATEWAY URL: {response['gatewayUrl']}")

    响应中的 GatewayURL 是您调用网关时要使用的终端节点。