기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.
속도 제한 API 예제
다음 예제에서는 AWS CLI 및 AWS Python SDK(Boto3)를 사용하여 속도 제한을 관리하는 방법을 보여줍니다.
초당 대상requests-per-second 수 제한 생성
다음 예제에서는 대상별로 초당 요청을 제어하는 속도 제한을 생성합니다. 특정 대상은 100RPS를 가져오고 다른 모든 대상은 각각 자체 10RPS 버킷을 가져옵니다.
예
- AWS CLI
-
-
다음 명령을 실행합니다.
aws bedrock-agentcore-control create-gateway-rate-limit \ --gateway-identifier my-gateway-abc1234567 \ --dimension-keys '["targetName"]' \ --description "Per-target RPS limit" \ --entries '[ { "dimensions": {"targetName": "my-high-traffic-target"}, "requests": [ { "rate": 100, "period": "second" } ] }, { "dimensions": {"targetName": "*"}, "requests": [ { "rate": 10, "period": "second" } ] } ]'
-
- AWS Python SDK (Boto3)
-
-
import boto3 client = boto3.client("bedrock-agentcore-control", region_name="us-west-2") response = client.create_gateway_rate_limit( gatewayIdentifier="my-gateway-abc1234567", dimensionKeys=["targetName"], description="Per-target RPS limit", entries=[ { "dimensions": {"targetName": "my-high-traffic-target"}, "requests": [ { "rate": 100, "period": "second", } ], }, { "dimensions": {"targetName": "*"}, "requests": [ { "rate": 10, "period": "second", } ], }, ], ) print(f"Rate Limit ID: {response['rateLimitId']}")
-
호출자당 requests-per-minute 수 제한 생성
다음 예제에서는 호출자의 JWT sub 클레임을 기반으로 속도 제한을 생성합니다. 프리미엄 사용자는 300RPM을 받고 다른 모든 사용자는 60RPM을 받습니다.
예
- AWS CLI
-
-
다음 명령을 실행합니다.
aws bedrock-agentcore-control create-gateway-rate-limit \ --gateway-identifier my-gateway-abc1234567 \ --dimension-keys '["$.context.jwt.sub"]' \ --description "Per-caller RPM by subscription tier" \ --entries '[ { "dimensions": {"$.context.jwt.sub": "premium-user-001"}, "requests": [ { "rate": 300, "period": "minute" } ] }, { "dimensions": {"$.context.jwt.sub": "premium-user-002"}, "requests": [ { "rate": 300, "period": "minute" } ] }, { "dimensions": {"$.context.jwt.sub": "*"}, "requests": [ { "rate": 60, "period": "minute" } ] } ]'
-
- AWS Python SDK (Boto3)
-
-
import boto3 client = boto3.client("bedrock-agentcore-control", region_name="us-west-2") response = client.create_gateway_rate_limit( gatewayIdentifier="my-gateway-abc1234567", dimensionKeys=["$.context.jwt.sub"], description="Per-caller RPM by subscription tier", entries=[ { "dimensions": {"$.context.jwt.sub": "premium-user-001"}, "requests": [ { "rate": 300, "period": "minute", } ], }, { "dimensions": {"$.context.jwt.sub": "premium-user-002"}, "requests": [ { "rate": 300, "period": "minute", } ], }, { "dimensions": {"$.context.jwt.sub": "*"}, "requests": [ { "rate": 60, "period": "minute", } ], }, ], ) print(f"Rate Limit ID: {response['rateLimitId']}")
-
토큰을 사용하여 다차원 제한 생성
다음 예제에서는 분당 요청과 토큰을 모두 제한하는 차원 키 3개를 사용하여 속도 제한을 생성합니다. 각 호출자는 특정 대상 및 모델로 범위가 지정된 자체 예산을 가져옵니다.
예
- AWS CLI
-
-
다음 명령을 실행합니다.
aws bedrock-agentcore-control create-gateway-rate-limit \ --gateway-identifier my-gateway-abc1234567 \ --dimension-keys '["targetName", "qualifiedModelId", "$.context.jwt.sub"]' \ --description "Per-caller token and request budget per target and model" \ --entries '[ { "dimensions": {"targetName": "my-inference-target", "qualifiedModelId": "anthropic.claude-3-sonnet-20240229-v1:0", "$.context.jwt.sub": "*"}, "requests": [ { "rate": 100, "period": "minute" } ], "tokens": [ { "rate": 50000, "period": "minute" } ] }, { "dimensions": {"targetName": "*", "qualifiedModelId": "*", "$.context.jwt.sub": "*"}, "requests": [ { "rate": 30, "period": "minute" } ], "tokens": [ { "rate": 10000, "period": "minute" } ] } ]'
-
- AWS Python SDK (Boto3)
-
-
import boto3 client = boto3.client("bedrock-agentcore-control", region_name="us-west-2") response = client.create_gateway_rate_limit( gatewayIdentifier="my-gateway-abc1234567", dimensionKeys=["targetName", "qualifiedModelId", "$.context.jwt.sub"], description="Per-caller token and request budget per target and model", entries=[ { "dimensions": {"targetName": "my-inference-target", "qualifiedModelId": "anthropic.claude-3-sonnet-20240229-v1:0", "$.context.jwt.sub": "*"}, "requests": [ { "rate": 100, "period": "minute", } ], "tokens": [ { "rate": 50000, "period": "minute", } ], }, { "dimensions": {"targetName": "*", "qualifiedModelId": "*", "$.context.jwt.sub": "*"}, "requests": [ { "rate": 30, "period": "minute", } ], "tokens": [ { "rate": 10000, "period": "minute", } ], }, ], ) print(f"Rate Limit ID: {response['rateLimitId']}")
-
연결 속도 제한 생성
다음 예제에서는 모델당 연결 속도 제한을 생성합니다. 이렇게 하면 각 모델에 대한 동시 진행 중인 요청 수가 제한되므로 동시성 용량이 제한된 대상을 보호하는 데 유용합니다.
예
- AWS CLI
-
-
다음 명령을 실행합니다.
aws bedrock-agentcore-control create-gateway-rate-limit \ --gateway-identifier my-gateway-abc1234567 \ --dimension-keys '["qualifiedModelId"]' \ --description "Connection rate limit per model" \ --entries '[ { "dimensions": {"qualifiedModelId": "anthropic.claude-3-sonnet-20240229-v1:0"}, "connections": [ { "rate": 50, "period": "second" } ] }, { "dimensions": {"qualifiedModelId": "*"}, "connections": [ { "rate": 20, "period": "second" } ] } ]'
-
- AWS Python SDK (Boto3)
-
-
import boto3 client = boto3.client("bedrock-agentcore-control", region_name="us-west-2") response = client.create_gateway_rate_limit( gatewayIdentifier="my-gateway-abc1234567", dimensionKeys=["qualifiedModelId"], description="Connection rate limit per model", entries=[ { "dimensions": {"qualifiedModelId": "anthropic.claude-3-sonnet-20240229-v1:0"}, "connections": [ { "rate": 50, "period": "second", } ], }, { "dimensions": {"qualifiedModelId": "*"}, "connections": [ { "rate": 20, "period": "second", } ], }, ], ) print(f"Rate Limit ID: {response['rateLimitId']}")
-
속도 0으로 호출자 차단
다음 예제에서는 속도를 0으로 설정하여 특정 호출자를 차단합니다. 이렇게 하면 변경 사항이 전파되면 차단된 호출자의 모든 요청이 거부됩니다(최대 30초).
예
- AWS CLI
-
-
다음 명령을 실행합니다.
aws bedrock-agentcore-control create-gateway-rate-limit \ --gateway-identifier my-gateway-abc1234567 \ --dimension-keys '["$.context.jwt.sub"]' \ --description "Block abusive caller" \ --entries '[ { "dimensions": {"$.context.jwt.sub": "blocked-user-789"}, "requests": [ { "rate": 0, "period": "second" } ] }, { "dimensions": {"$.context.jwt.sub": "*"}, "requests": [ { "rate": 100, "period": "second" } ] } ]'
-
- AWS Python SDK (Boto3)
-
-
import boto3 client = boto3.client("bedrock-agentcore-control", region_name="us-west-2") response = client.create_gateway_rate_limit( gatewayIdentifier="my-gateway-abc1234567", dimensionKeys=["$.context.jwt.sub"], description="Block abusive caller", entries=[ { "dimensions": {"$.context.jwt.sub": "blocked-user-789"}, "requests": [ { "rate": 0, "period": "second", } ], }, { "dimensions": {"$.context.jwt.sub": "*"}, "requests": [ { "rate": 100, "period": "second", } ], }, ], ) print(f"Rate Limit ID: {response['rateLimitId']}")
-
속도 제한 가져오기
다음 예시에서는 특정 속도 제한의 세부 정보를 검색합니다.
예
- AWS CLI
-
-
다음 명령을 실행합니다.
aws bedrock-agentcore-control get-gateway-rate-limit \ --gateway-identifier my-gateway-abc1234567 \ --rate-limit-id rl-abc123def456
-
- AWS Python SDK (Boto3)
-
-
import boto3 client = boto3.client("bedrock-agentcore-control", region_name="us-west-2") response = client.get_gateway_rate_limit( gatewayIdentifier="my-gateway-abc1234567", rateLimitId="rl-abc123def456", ) print(f"Status: {response['status']}") print(f"Dimension Keys: {response['dimensionKeys']}") print(f"Entries: {len(response['entries'])}")
-
속도 제한 업데이트
다음 예시에서는 기존 속도 제한의 항목을 업데이트하여 특정 대상의 속도를 높입니다.
참고
생성 후에는 dimensionKeys 필드를 변경할 수 없습니다. 차원 키를 변경하려면 속도 제한을 삭제하고 새 키를 생성합니다.
예
- AWS CLI
-
-
다음 명령을 실행합니다.
aws bedrock-agentcore-control update-gateway-rate-limit \ --gateway-identifier my-gateway-abc1234567 \ --rate-limit-id rl-abc123def456 \ --description "Updated per-target RPS limit" \ --entries '[ { "dimensions": {"targetName": "my-high-traffic-target"}, "requests": [ { "rate": 200, "period": "second" } ] }, { "dimensions": {"targetName": "*"}, "requests": [ { "rate": 20, "period": "second" } ] } ]'
-
- AWS Python SDK (Boto3)
-
-
import boto3 client = boto3.client("bedrock-agentcore-control", region_name="us-west-2") response = client.update_gateway_rate_limit( gatewayIdentifier="my-gateway-abc1234567", rateLimitId="rl-abc123def456", description="Updated per-target RPS limit", entries=[ { "dimensions": {"targetName": "my-high-traffic-target"}, "requests": [ { "rate": 200, "period": "second", } ], }, { "dimensions": {"targetName": "*"}, "requests": [ { "rate": 20, "period": "second", } ], }, ], ) print(f"Status: {response['status']}")
-
속도 제한 나열
다음 예시에서는 게이트웨이에 대한 모든 속도 제한을 나열합니다.
예
- AWS CLI
-
-
다음 명령을 실행합니다.
aws bedrock-agentcore-control list-gateway-rate-limits \ --gateway-identifier my-gateway-abc1234567
-
- AWS Python SDK (Boto3)
-
-
import boto3 client = boto3.client("bedrock-agentcore-control", region_name="us-west-2") paginator = client.get_paginator("list_gateway_rate_limits") for page in paginator.paginate(gatewayIdentifier="my-gateway-abc1234567"): for rate_limit in page["rateLimits"]: print( f"ID: {rate_limit['rateLimitId']}, " f"Status: {rate_limit['status']}, " f"Dimensions: {rate_limit['dimensionKeys']}" )
-
참고
결과는 페이지 매김될 수 있습니다. 응답의 nextToken 값을 사용하여 추가 페이지를 검색하거나 위와 같이 Boto3 페이지네이터를 사용합니다.
속도 제한 삭제
다음 예시에서는 게이트웨이에서 속도 제한을 삭제합니다.
예
- AWS CLI
-
-
다음 명령을 실행합니다.
aws bedrock-agentcore-control delete-gateway-rate-limit \ --gateway-identifier my-gateway-abc1234567 \ --rate-limit-id rl-abc123def456
-
- AWS Python SDK (Boto3)
-
-
import boto3 client = boto3.client("bedrock-agentcore-control", region_name="us-west-2") response = client.delete_gateway_rate_limit( gatewayIdentifier="my-gateway-abc1234567", rateLimitId="rl-abc123def456", ) print(f"Status: {response['status']}")
-
배치 투입 속도 제한
다음 예제에서는 단일 호출에서 여러 속도 제한을 생성하거나 업데이트합니다. 배치 배치는 업서트 의미 체계를 사용합니다. 차원 키가 동일한 속도 제한이 있는 경우 업데이트되고, 그렇지 않으면 새 속도 제한이 생성됩니다.
참고
배치 배치 배치는 멱등성입니다. 중복 속도 제한을 생성하지 않고도 실패한 호출을 안전하게 재시도할 수 있습니다.
예
- AWS CLI
-
-
다음 명령을 실행합니다.
aws bedrock-agentcore-control batch-put-gateway-rate-limits \ --gateway-identifier my-gateway-abc1234567 \ --rate-limits '[ { "dimensionKeys": ["targetName"], "description": "Per-target RPS", "entries": [ { "dimensions": {"targetName": "*"}, "requests": [{"rate": 50, "period": "second"}] } ] }, { "dimensionKeys": ["$.context.jwt.sub"], "description": "Per-caller RPM", "entries": [ { "dimensions": {"$.context.jwt.sub": "*"}, "requests": [{"rate": 120, "period": "minute"}] } ] } ]'
-
- AWS Python SDK (Boto3)
-
-
import boto3 client = boto3.client("bedrock-agentcore-control", region_name="us-west-2") response = client.batch_put_gateway_rate_limits( gatewayIdentifier="my-gateway-abc1234567", rateLimits=[ { "dimensionKeys": ["targetName"], "description": "Per-target RPS", "entries": [ { "dimensions": {"targetName": "*"}, "requests": [ {"rate": 50, "period": "second"} ], } ], }, { "dimensionKeys": ["$.context.jwt.sub"], "description": "Per-caller RPM", "entries": [ { "dimensions": {"$.context.jwt.sub": "*"}, "requests": [ {"rate": 120, "period": "minute"} ], } ], }, ], ) for result in response["rateLimits"]: print(f"ID: {result['rateLimitId']}, Status: {result['status']}")
-