Update api_usage.py
Browse files- api_usage.py +34 -27
api_usage.py
CHANGED
|
@@ -512,8 +512,9 @@ def check_key_aws_availability(key):
|
|
| 512 |
quarantine = False
|
| 513 |
iam_full_access = False
|
| 514 |
iam_policies_perm = False
|
| 515 |
-
|
| 516 |
-
|
|
|
|
| 517 |
session = boto3.Session(
|
| 518 |
aws_access_key_id=access_id,
|
| 519 |
aws_secret_access_key=access_secret
|
|
@@ -524,7 +525,7 @@ def check_key_aws_availability(key):
|
|
| 524 |
username = check_username(session)
|
| 525 |
#print(username)
|
| 526 |
if not username[0]:
|
| 527 |
-
return False,
|
| 528 |
|
| 529 |
if username[0] == 'root' and username[2]:
|
| 530 |
root = True
|
|
@@ -540,17 +541,15 @@ def check_key_aws_availability(key):
|
|
| 540 |
iam_full_access = True
|
| 541 |
if policy['PolicyName'] == 'AWSCompromisedKeyQuarantineV2':
|
| 542 |
quarantine = True
|
|
|
|
|
|
|
|
|
|
|
|
|
| 543 |
|
| 544 |
enable_region = check_bedrock_invoke(session)
|
| 545 |
-
|
| 546 |
-
if enable_region[0]:
|
| 547 |
-
enable_region_v2 = enable_region[0]
|
| 548 |
-
if enable_region[1]:
|
| 549 |
-
enable_region_sonnet = enable_region[1]
|
| 550 |
cost = check_aws_billing(session)
|
| 551 |
-
|
| 552 |
-
|
| 553 |
-
return True, username[0], root, admin, iam_full_access, quarantine, enable_region_v2, enable_region_sonnet, cost
|
| 554 |
|
| 555 |
def check_username(session):
|
| 556 |
try:
|
|
@@ -592,24 +591,32 @@ def invoke_claude(session, region, modelId):
|
|
| 592 |
#print(e)
|
| 593 |
return
|
| 594 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 595 |
def check_bedrock_invoke(session):
|
| 596 |
-
regions = ['us-east-1', 'us-west-2', 'eu-central-1', 'ap-southeast-1', 'ap-northeast-1']
|
| 597 |
-
|
| 598 |
-
|
| 599 |
-
|
| 600 |
-
|
| 601 |
-
|
| 602 |
-
|
| 603 |
-
|
| 604 |
-
|
| 605 |
-
|
| 606 |
-
|
| 607 |
-
|
| 608 |
-
|
|
|
|
| 609 |
for future in concurrent.futures.as_completed(futures):
|
| 610 |
-
if future.result()
|
| 611 |
-
|
| 612 |
-
|
|
|
|
|
|
|
| 613 |
|
| 614 |
def check_aws_billing(session):
|
| 615 |
try:
|
|
|
|
| 512 |
quarantine = False
|
| 513 |
iam_full_access = False
|
| 514 |
iam_policies_perm = False
|
| 515 |
+
iam_user_change_password = False
|
| 516 |
+
aws_bedrock_full_access = False
|
| 517 |
+
|
| 518 |
session = boto3.Session(
|
| 519 |
aws_access_key_id=access_id,
|
| 520 |
aws_secret_access_key=access_secret
|
|
|
|
| 525 |
username = check_username(session)
|
| 526 |
#print(username)
|
| 527 |
if not username[0]:
|
| 528 |
+
return False, username[1]
|
| 529 |
|
| 530 |
if username[0] == 'root' and username[2]:
|
| 531 |
root = True
|
|
|
|
| 541 |
iam_full_access = True
|
| 542 |
if policy['PolicyName'] == 'AWSCompromisedKeyQuarantineV2':
|
| 543 |
quarantine = True
|
| 544 |
+
if policy['PolicyName'] == 'IAMUserChangePassword':
|
| 545 |
+
iam_user_change_password = True
|
| 546 |
+
if policy['PolicyName'] == 'AmazonBedrockFullAccess':
|
| 547 |
+
aws_bedrock_full_access = True
|
| 548 |
|
| 549 |
enable_region = check_bedrock_invoke(session)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 550 |
cost = check_aws_billing(session)
|
| 551 |
+
|
| 552 |
+
return True, username[0], root, admin, quarantine, iam_full_access, iam_user_change_password, aws_bedrock_full_access, enable_region, cost
|
|
|
|
| 553 |
|
| 554 |
def check_username(session):
|
| 555 |
try:
|
|
|
|
| 591 |
#print(e)
|
| 592 |
return
|
| 593 |
|
| 594 |
+
def invoke_and_collect(session, model_name, region):
|
| 595 |
+
result = invoke_claude(session, region, f"anthropic.{model_name}")
|
| 596 |
+
if result:
|
| 597 |
+
return model_name, result
|
| 598 |
+
|
| 599 |
def check_bedrock_invoke(session):
|
| 600 |
+
regions = ['us-east-1', 'us-west-2', 'eu-central-1', 'eu-west-3', 'ap-southeast-1', 'ap-northeast-1']
|
| 601 |
+
models = {
|
| 602 |
+
"claude-v2": [],
|
| 603 |
+
"claude-3-haiku-20240307-v1:0": [],
|
| 604 |
+
"claude-3-sonnet-20240229-v1:0": [],
|
| 605 |
+
"claude-3-opus-20240229-v1:0": []
|
| 606 |
+
}
|
| 607 |
+
|
| 608 |
+
with concurrent.futures.ThreadPoolExecutor() as executor:
|
| 609 |
+
futures = []
|
| 610 |
+
for region in regions:
|
| 611 |
+
for model in models:
|
| 612 |
+
futures.append(executor.submit(invoke_and_collect, session, model, region))
|
| 613 |
+
|
| 614 |
for future in concurrent.futures.as_completed(futures):
|
| 615 |
+
if future.result():
|
| 616 |
+
model_name, region = future.result()
|
| 617 |
+
models[model_name].append(region)
|
| 618 |
+
|
| 619 |
+
return models
|
| 620 |
|
| 621 |
def check_aws_billing(session):
|
| 622 |
try:
|