Sign in
agent:

Retrieve a list of all active AWS IAM access keys.

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

Retrieves and prints a list of all active AWS IAM access keys.

import boto3 # 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 users users = client.list_users()['Users'] # List to store active access keys active_access_keys = [] # Check each user's access keys for user in users: user_name = user['UserName'] access_keys = client.list_access_keys(UserName=user_name)['AccessKeyMetadata'] for access_key in access_keys: if access_key['Status'] == 'Active': active_access_keys.append({ 'UserName': user_name, 'AccessKeyId': access_key['AccessKeyId'], 'CreateDate': access_key['CreateDate'] }) # Print the list of active access keys import json print(json.dumps(active_access_keys, indent=4, default=str))
copied