Contoh API aturan gateway
Contoh berikut menunjukkan cara mengelola aturan gateway menggunakan AWS CLI dan AWS Python SDK (Boto3).
Buat aturan dengan penggantian bundel konfigurasi statis
Contoh berikut membuat aturan yang menyematkan prinsipal IAM tertentu ke versi bundel konfigurasi. Gunakan pendekatan ini untuk QA atau debugging.
contoh
- AWS CLI
-
-
Jalankan perintah berikut:
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']}")
-
Buat aturan default catch-all
Contoh berikut membuat aturan tanpa kondisi. Aturan ini cocok dengan semua lalu lintas dan berfungsi sebagai default. Tetapkan nomor prioritas tinggi sehingga aturan yang lebih spesifik diutamakan.
contoh
- AWS CLI
-
-
Jalankan perintah berikut:
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']}")
-
Buat aturan dengan pemisahan bundel konfigurasi tertimbang
Contoh berikut membuat aturan yang membagi lalu lintas antara dua versi bundel konfigurasi untuk A/B pengujian. Dalam contoh ini, 80% lalu lintas menggunakan varian A dan 20% menggunakan varian B.
contoh
- AWS CLI
-
-
Jalankan perintah berikut:
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']}")
-
catatan
Untuk mempertahankan pengalaman pengguna yang konsisten selama A/B pengujian, sertakan X-Amzn-Bedrock-AgentCore-Runtime-Session-Id header dalam permintaan pemanggilan gateway Anda. Untuk informasi selengkapnya, lihat Sesi lengket untuk aturan tertimbang.
Buat aturan dengan perutean target
Contoh berikut membuat aturan yang merutekan permintaan yang cocok dengan pola jalur tertentu ke target.
contoh
- AWS CLI
-
-
Jalankan perintah berikut:
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']}")
-
Buat aturan dengan perutean target tertimbang
Contoh berikut membuat aturan yang membagi lalu lintas antara dua target. Dalam contoh ini, 90% rute lalu lintas ke target utama dan 10% rute ke target kenari.
contoh
- AWS CLI
-
-
Jalankan perintah berikut:
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']}")
-
Buat aturan dengan kondisi dan tindakan gabungan
Contoh berikut membuat aturan dengan kedua jenis kondisi dan kedua jenis tindakan. Permintaan harus cocok dengan setidaknya satu entri dari setiap jenis kondisi (DAN logika di seluruh jenis).
contoh
- AWS CLI
-
-
Jalankan perintah berikut:
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']}")
-
catatan
Aturan ini hanya cocok jika pemanggil adalah peran QA DAN jalur permintaan cocok. /my-target-canary/* Kedua kondisi tersebut harus dipenuhi.
Dapatkan aturan gateway
Contoh berikut mengambil rincian aturan gateway tertentu.
contoh
- AWS CLI
-
-
Jalankan perintah berikut:
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']}")
-
Perbarui aturan gateway
Contoh berikut memperbarui prioritas dan deskripsi aturan gateway yang ada.
contoh
- AWS CLI
-
-
Jalankan perintah berikut:
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']}")
-
Daftar aturan gateway
Contoh berikut mencantumkan semua aturan untuk gateway. Hasil diurutkan berdasarkan prioritas dalam urutan menaik.
contoh
- AWS CLI
-
-
Jalankan perintah berikut:
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']}")
-
Hapus aturan gateway
Contoh berikut menghapus aturan gateway.
contoh
- AWS CLI
-
-
Jalankan perintah berikut:
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']}")
-