Sign in
agent:

Evaluate all AWS IAM users and identify any users with directly attached policies

There was a problem that the LLM was not able to address. Please rephrase your prompt and try again.

Evaluates IAM users for directly attached policies and tabulates the results.

import boto3 import json # Initialize boto3 client for IAM client = boto3.client('iam', aws_access_key_id=getEnvVar('AWS_ACCESS_KEY_ID'), aws_secret_access_key=getEnvVar('AWS_SECRET_ACCESS_KEY')) # Get all IAM users users = client.list_users()['Users'] # Prepare table for results compliance_status = 'COMPLIANT' table = context.newtable() table.num_rows = len(users) + 1 # 2 columns: UserName and AttachedPolicies table.num_cols = 2 table.title = "IAM Users with Directly Attached Policies" table.has_header_row = True table.setval(0, 0, "UserName") table.setval(0, 1, "AttachedPolicies") row = 1 for user in users: user_name = user['UserName'] # List attached user policies attached_policies = client.list_attached_user_policies(UserName=user_name)['AttachedPolicies'] if attached_policies: compliance_status = 'NON_COMPLIANT' policy_names = ', '.join([policy['PolicyName'] for policy in attached_policies]) else: policy_names = 'None' table.setval(row, 0, user_name) table.setval(row, 1, policy_names) row += 1 print("Compliance Status:", compliance_status) print("Table created successfully.")
copied