#๐Ÿ”’ Skipp disabled users in aws

6 messages ยท Page 1 of 1 (latest)

west kilnBOT
#

@normal geyser

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

normal geyser
#

I have a script that performs some checks and I need it to skip current aws disabeld users.
I did try with the following but it seems that it is not skipping the disabeld users

code is attached in the file

#

'''
def lambda_handler(event, context):

paginator = iam.get_paginator('list_users')
page = paginator.paginate()
csv_file = [["UserName", "CreationDate", "LastConsoleLogin", "DisabledDate", "MFA Disabled"]]
users_disabled = False  # This flag will track if any users were disabled
for page_user in page:
    users = page_user['Users']
    sort_users = sorted(users, key=lambda user: user['UserName'])
    for user in sort_users:
        username = user['UserName']
        groups = iam.list_groups_for_user(UserName=username)['Groups']
        group_name = [group['GroupName'] for group in groups]
        dry_run = False

        # Checking if users have MFA enabled
        checking_mfa(username, group_name, dry_run, csv_file)

# An email will be sent if either users have been disabled and sends the link with the csv file or not
if not users_disabled:
    goodemail()
    print("no users to disabled")
else:
    print("users to disabled yes")
    emailtobesent(csv_file)

'''

west kilnBOT
#

Hey @normal geyser!

It looks like you are trying to paste code into this channel.

You seem to be using the wrong symbols to indicate where the code block should start. The correct symbols would be ```, not '''.

Furthermore, it looks like you pasted Python code without syntax highlighting. Please use syntax highlighting to improve the legibility of your code and make it easier for us to help you.

To do this, use the following method:
```py
print('Hello, world!')
```

This will result in the following:

print('Hello, world!')```
You can **edit your original message** to correct your code block.
west kilnBOT
#

@normal geyser

Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.