Ejemplos de API de reglas de puerta de enlace
Los siguientes ejemplos muestran cómo administrar las reglas de puerta de enlace mediante la AWS CLI y el SDK de AWS Python (Boto3).
Cree una regla con una anulación del paquete de configuración estática
En el siguiente ejemplo, se crea una regla que vincula una entidad principal de IAM específica a una versión del paquete de configuración. Utilice este enfoque para el control de calidad o la depuración.
ejemplo
- AWS CLI
-
-
Use el siguiente comando:
aws bedrock-agentcore-control create-gateway-rule \
--gateway-identifier my-gateway-abc1234567 \
--priority 100 \
--description "Pin QA role to bundle version" \
--conditions '[
{
"matchPrincipals": {
"anyOf": [
{
"iamPrincipal": {
"arn": "arn:aws:iam::123456789012:role/QARole",
"operator": "StringEquals"
}
}
]
}
}
]' \
--actions '[
{
"configurationBundle": {
"staticOverride": {
"bundleArn": "arn:aws:bedrock-agentcore:us-west-2:123456789012:configuration-bundle/myBundle-abc1234567",
"bundleVersion": "1234abcd-12ab-34cd-56ef-1234567890ab"
}
}
}
]'
- AWS Python SDK (Boto3)
-
-
import boto3
client = boto3.client("bedrock-agentcore-control", region_name="us-west-2")
response = client.create_gateway_rule(
gatewayIdentifier="my-gateway-abc1234567",
priority=100,
description="Pin QA role to bundle version",
conditions=[
{
"matchPrincipals": {
"anyOf": [
{
"iamPrincipal": {
"arn": "arn:aws:iam::123456789012:role/QARole",
"operator": "StringEquals",
}
}
]
}
}
],
actions=[
{
"configurationBundle": {
"staticOverride": {
"bundleArn": "arn:aws:bedrock-agentcore:us-west-2:123456789012:configuration-bundle/myBundle-abc1234567",
"bundleVersion": "1234abcd-12ab-34cd-56ef-1234567890ab",
}
}
}
],
)
print(f"Rule ID: {response['ruleId']}")
Crear una regla general por defecto
En el siguiente ejemplo, se crea una regla sin condiciones. Esta regla coincide con todo el tráfico y es la predeterminada. Asigne un número de alta prioridad para que tengan prioridad las reglas más específicas.
ejemplo
- AWS CLI
-
-
Use el siguiente comando:
aws bedrock-agentcore-control create-gateway-rule \
--gateway-identifier my-gateway-abc1234567 \
--priority 1000000 \
--description "Default configuration bundle for all traffic" \
--actions '[
{
"configurationBundle": {
"staticOverride": {
"bundleArn": "arn:aws:bedrock-agentcore:us-west-2:123456789012:configuration-bundle/myBundle-abc1234567",
"bundleVersion": "1234abcd-12ab-34cd-56ef-1234567890ab"
}
}
}
]'
- AWS Python SDK (Boto3)
-
-
import boto3
client = boto3.client("bedrock-agentcore-control", region_name="us-west-2")
response = client.create_gateway_rule(
gatewayIdentifier="my-gateway-abc1234567",
priority=1000000,
description="Default configuration bundle for all traffic",
actions=[
{
"configurationBundle": {
"staticOverride": {
"bundleArn": "arn:aws:bedrock-agentcore:us-west-2:123456789012:configuration-bundle/myBundle-abc1234567",
"bundleVersion": "1234abcd-12ab-34cd-56ef-1234567890ab",
}
}
}
],
)
print(f"Rule ID: {response['ruleId']}")
Cree una regla con un paquete de configuración ponderado dividido
En el siguiente ejemplo, se crea una regla que divide el tráfico entre dos versiones del paquete de configuración para A/B realizar pruebas. En este ejemplo, el 80% del tráfico usa la variante A y el 20% usa la variante B.
ejemplo
- AWS CLI
-
-
Use el siguiente comando:
aws bedrock-agentcore-control create-gateway-rule \
--gateway-identifier my-gateway-abc1234567 \
--priority 500 \
--description "A/B test: 80/20 traffic split" \
--actions '[
{
"configurationBundle": {
"weightedOverride": {
"trafficSplit": [
{
"name": "variant-a",
"weight": 80,
"configurationBundle": {
"bundleArn": "arn:aws:bedrock-agentcore:us-west-2:123456789012:configuration-bundle/myBundle-abc1234567",
"bundleVersion": "1234abcd-12ab-34cd-56ef-1234567890ab"
},
"description": "Control variant"
},
{
"name": "variant-b",
"weight": 20,
"configurationBundle": {
"bundleArn": "arn:aws:bedrock-agentcore:us-west-2:123456789012:configuration-bundle/myBundle-abc1234567",
"bundleVersion": "12345678-1234-5678-9abc-123456789012"
},
"description": "Treatment variant"
}
]
}
}
}
]'
- AWS Python SDK (Boto3)
-
-
import boto3
client = boto3.client("bedrock-agentcore-control", region_name="us-west-2")
response = client.create_gateway_rule(
gatewayIdentifier="my-gateway-abc1234567",
priority=500,
description="A/B test: 80/20 traffic split",
actions=[
{
"configurationBundle": {
"weightedOverride": {
"trafficSplit": [
{
"name": "variant-a",
"weight": 80,
"configurationBundle": {
"bundleArn": "arn:aws:bedrock-agentcore:us-west-2:123456789012:configuration-bundle/myBundle-abc1234567",
"bundleVersion": "1234abcd-12ab-34cd-56ef-1234567890ab",
},
"description": "Control variant",
},
{
"name": "variant-b",
"weight": 20,
"configurationBundle": {
"bundleArn": "arn:aws:bedrock-agentcore:us-west-2:123456789012:configuration-bundle/myBundle-abc1234567",
"bundleVersion": "12345678-1234-5678-9abc-123456789012",
},
"description": "Treatment variant",
},
]
}
}
}
],
)
print(f"Rule ID: {response['ruleId']}")
Para mantener una experiencia de usuario uniforme durante A/B las pruebas, incluye el X-Amzn-Bedrock-AgentCore-Runtime-Session-Id encabezado en las solicitudes de invocación de tu pasarela. Para obtener más información, consulte Fijación de la sesión para las reglas ponderadas.
Cree una regla con el enrutamiento de destino
En el siguiente ejemplo, se crea una regla que enruta las solicitudes que coinciden con un patrón de ruta específico a un destino.
ejemplo
- AWS CLI
-
-
Use el siguiente comando:
aws bedrock-agentcore-control create-gateway-rule \
--gateway-identifier my-gateway-abc1234567 \
--priority 150 \
--description "Route /my-target-canary requests to canary target" \
--conditions '[
{
"matchPaths": {
"anyOf": [
"/my-target-canary/*"
]
}
}
]' \
--actions '[
{
"routeToTarget": {
"staticRoute": {
"targetName": "my-target-canary"
}
}
}
]'
- AWS Python SDK (Boto3)
-
-
import boto3
client = boto3.client("bedrock-agentcore-control", region_name="us-west-2")
response = client.create_gateway_rule(
gatewayIdentifier="my-gateway-abc1234567",
priority=150,
description="Route /my-target-canary requests to canary target",
conditions=[
{
"matchPaths": {
"anyOf": ["/my-target-canary/*"]
}
}
],
actions=[
{
"routeToTarget": {
"staticRoute": {
"targetName": "my-target-canary",
}
}
}
],
)
print(f"Rule ID: {response['ruleId']}")
Cree una regla con un enrutamiento de destino ponderado
En el siguiente ejemplo, se crea una regla que divide el tráfico entre dos destinos. En este ejemplo, el 90% del tráfico se dirige al objetivo principal y el 10% se dirige al objetivo canario.
ejemplo
- AWS CLI
-
-
Use el siguiente comando:
aws bedrock-agentcore-control create-gateway-rule \
--gateway-identifier my-gateway-abc1234567 \
--priority 300 \
--description "Canary deployment: 90/10 target split" \
--actions '[
{
"routeToTarget": {
"weightedRoute": {
"trafficSplit": [
{
"name": "primary",
"weight": 90,
"targetName": "my-target-primary",
"description": "Primary target"
},
{
"name": "canary",
"weight": 10,
"targetName": "my-target-canary",
"description": "Canary target"
}
]
}
}
}
]'
- AWS Python SDK (Boto3)
-
-
import boto3
client = boto3.client("bedrock-agentcore-control", region_name="us-west-2")
response = client.create_gateway_rule(
gatewayIdentifier="my-gateway-abc1234567",
priority=300,
description="Canary deployment: 90/10 target split",
actions=[
{
"routeToTarget": {
"weightedRoute": {
"trafficSplit": [
{
"name": "primary",
"weight": 90,
"targetName": "my-target-primary",
"description": "Primary target",
},
{
"name": "canary",
"weight": 10,
"targetName": "my-target-canary",
"description": "Canary target",
},
]
}
}
}
],
)
print(f"Rule ID: {response['ruleId']}")
Cree una regla con condiciones y acciones combinadas
El siguiente ejemplo crea una regla con ambos tipos de condiciones y ambos tipos de acciones. La solicitud debe coincidir con al menos una entrada de cada tipo de condición (y con la lógica de todos los tipos).
ejemplo
- AWS CLI
-
-
Use el siguiente comando:
aws bedrock-agentcore-control create-gateway-rule \
--gateway-identifier my-gateway-abc1234567 \
--priority 50 \
--description "QA role on /my-target-canary paths: pin bundle and route to canary" \
--conditions '[
{
"matchPrincipals": {
"anyOf": [
{
"iamPrincipal": {
"arn": "arn:aws:iam::123456789012:role/QARole",
"operator": "StringEquals"
}
}
]
}
},
{
"matchPaths": {
"anyOf": [
"/my-target-canary/*"
]
}
}
]' \
--actions '[
{
"configurationBundle": {
"staticOverride": {
"bundleArn": "arn:aws:bedrock-agentcore:us-west-2:123456789012:configuration-bundle/myBundle-abc1234567",
"bundleVersion": "1234abcd-12ab-34cd-56ef-1234567890ab"
}
}
},
{
"routeToTarget": {
"staticRoute": {
"targetName": "my-target-canary"
}
}
}
]'
- AWS Python SDK (Boto3)
-
-
import boto3
client = boto3.client("bedrock-agentcore-control", region_name="us-west-2")
response = client.create_gateway_rule(
gatewayIdentifier="my-gateway-abc1234567",
priority=50,
description="QA role on /my-target-canary paths: pin bundle and route to canary",
conditions=[
{
"matchPrincipals": {
"anyOf": [
{
"iamPrincipal": {
"arn": "arn:aws:iam::123456789012:role/QARole",
"operator": "StringEquals",
}
}
]
}
},
{
"matchPaths": {
"anyOf": ["/my-target-canary/*"]
},
},
],
actions=[
{
"configurationBundle": {
"staticOverride": {
"bundleArn": "arn:aws:bedrock-agentcore:us-west-2:123456789012:configuration-bundle/myBundle-abc1234567",
"bundleVersion": "1234abcd-12ab-34cd-56ef-1234567890ab",
}
}
},
{
"routeToTarget": {
"staticRoute": {
"targetName": "my-target-canary",
}
}
},
],
)
print(f"Rule ID: {response['ruleId']}")
Esta regla solo coincide cuando la persona que llama tiene el rol de control de calidad Y la ruta de la solicitud coincide/my-target-canary/*. Deben cumplirse ambas condiciones.
Obtenga una regla de puerta de enlace
En el siguiente ejemplo, se recuperan los detalles de una regla de puerta de enlace específica.
ejemplo
- AWS CLI
-
-
Use el siguiente comando:
aws bedrock-agentcore-control get-gateway-rule \
--gateway-identifier my-gateway-abc1234567 \
--rule-id 12345678-1234-1234-1234-123456789012
- AWS Python SDK (Boto3)
-
-
import boto3
client = boto3.client("bedrock-agentcore-control", region_name="us-west-2")
response = client.get_gateway_rule(
gatewayIdentifier="my-gateway-abc1234567",
ruleId="12345678-1234-1234-1234-123456789012",
)
print(f"Priority: {response['priority']}")
print(f"Status: {response['status']}")
print(f"Actions: {response['actions']}")
Actualiza una regla de puerta de enlace
El siguiente ejemplo actualiza la prioridad y la descripción de una regla de puerta de enlace existente.
ejemplo
- AWS CLI
-
-
Use el siguiente comando:
aws bedrock-agentcore-control update-gateway-rule \
--gateway-identifier my-gateway-abc1234567 \
--rule-id 12345678-1234-1234-1234-123456789012 \
--priority 200 \
--description "Updated priority for QA rule"
- AWS Python SDK (Boto3)
-
-
import boto3
client = boto3.client("bedrock-agentcore-control", region_name="us-west-2")
response = client.update_gateway_rule(
gatewayIdentifier="my-gateway-abc1234567",
ruleId="12345678-1234-1234-1234-123456789012",
priority=200,
description="Updated priority for QA rule",
)
print(f"Status: {response['status']}")
Listar las reglas de puerta de enlace
En el siguiente ejemplo, se enumeran todas las reglas de una puerta de enlace. Los resultados se ordenan por prioridad en orden ascendente.
ejemplo
- AWS CLI
-
-
Use el siguiente comando:
aws bedrock-agentcore-control list-gateway-rules \
--gateway-identifier my-gateway-abc1234567
- AWS Python SDK (Boto3)
-
-
import boto3
client = boto3.client("bedrock-agentcore-control", region_name="us-west-2")
response = client.list_gateway_rules(
gatewayIdentifier="my-gateway-abc1234567"
)
for rule in response["gatewayRules"]:
print(f"Rule: {rule['ruleId']}, Priority: {rule['priority']}, Status: {rule['status']}")
Eliminar una regla de puerta de enlace
En el siguiente ejemplo, se elimina una regla de puerta de enlace.
ejemplo
- AWS CLI
-
-
Use el siguiente comando:
aws bedrock-agentcore-control delete-gateway-rule \
--gateway-identifier my-gateway-abc1234567 \
--rule-id 12345678-1234-1234-1234-123456789012
- AWS Python SDK (Boto3)
-
-
import boto3
client = boto3.client("bedrock-agentcore-control", region_name="us-west-2")
response = client.delete_gateway_rule(
gatewayIdentifier="my-gateway-abc1234567",
ruleId="12345678-1234-1234-1234-123456789012",
)
print(f"Status: {response['status']}")