Best Python code snippet using localstack_python
iam_delete_user.py
Source:iam_delete_user.py
...13 - delete-access-key --access-key-id <access-key-id>14 - delete_access_key(AccessKeyId=<access_key_id>)15 * Signing Certificate (DeleteSigningCertificate)16 - delete-signing-certificate --certificate-id <certificate-id>17 - delete_signing_certificate(CertificateId=<certificate_id>)18 * SSH Public Key (DeleteSSHPublicKey)19 - delete-ssh-public-key --user-name <user-name> --ssh-public-key-id <ssh-public-key-id>20 - delete_ssh_public_key(UserName=<user_name>, SSHPublicKeyId=<ssh_public_key_id>)21 * Git Credentials (DeleteServiceSpecificCredential)22 - delete-service-specific-credential --service-specific-credential-id <service-specific-credential-id>23 - delete_service_specific_credentials(ServiceSpecificCredentialId=<service_specific_credential_id>)24 * Multi-factor Authentication (MFA) Device (DeactivateMFADevice, DeleteVirtualMFADevice)25 - deactivate-mfa-device --user-name <user-name> --serial-number <serial-number>26 - deactivate_mfa_device(UserName=<user_name>, SerialNumber=<serial_number>)27 - delete-virtual-mfa-device --serial_number <serial-number>28 - delete_virtual_mfa_device(SerialNumber=<serial_number>)29 * Inline Policies (DeleteUserPolicy)30 - delete-user-policy --user-name <user-name> --policy-name <policy-name>31 - delete_user_policy(UserName=<user_name>, PolicyName=<policy_name>)32 * Attached Managed Policies (DetachUserPolicy)33 - detach-user-policy --user-name <user-name> --policy-arn <policy-arn>34 - detach_user_policy(UserName=<user_name>, PolicyArn=<policy_arn>)35 * Group Memberships (RemoveUserFromGroup)36 - remove-user-from-group --user-name <user-name> --group-name <group-name>37 - remove_user_from_group(UserName=<user_name>, GroupName=<group_name>)38Finally, delete the user:39 * Delete User (DeleteUser)40 - delete-user --user-name <user-name>41 - delete_user(UserName=<user_name>)42"""43import boto344import click45import logging46# configure Logger instance47logger = logging.getLogger()48f = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s')49fh = logging.FileHandler('logs.txt')50fh.setLevel(logging.WARNING)51fh.setFormatter(f)52logger.addHandler(fh)53@click.command()54@click.option('--user-name', default=None, help='Name of the user.')55@click.option('--dry-run',56 is_flag=True,57 help='Echo AWS CLI commands without executing them.')58def main(user_name: str, dry_run: bool) -> None:59 client = boto3.client('iam')60 access_key_ids = \61 [x['AccessKeyId']62 for x in client.list_access_keys(63 UserName=user_name)['AccessKeyMetadata']]64 certificate_ids = \65 [x['CertificateId']66 for x in client.list_signing_certificates(67 UserName=user_name)['Certificates']]68 ssh_public_key_ids = \69 [x['SSHPublicKeyId']70 for x in client.list_ssh_public_keys(71 UserName=user_name)['SSHPublicKeys']]72 service_specific_credential_ids = \73 [x['ServiceSpecificCredentialId']74 for x in client.list_service_specific_credentials(75 UserName=user_name)['ServiceSpecificCredentials']]76 serial_numbers = \77 [x['SerialNumber']78 for x in client.list_mfa_devices(79 UserName=user_name)['MFADevices']]80 policy_names = \81 [x82 for x in client.list_user_policies(83 UserName=user_name)['PolicyNames']]84 policy_arns = \85 [x['PolicyArn']86 for x in client.list_attached_user_policies(87 UserName=user_name)['AttachedPolicies']]88 group_names = \89 [x['GroupName']90 for x in client.list_groups_for_user(91 UserName=user_name)['Groups']]92 if dry_run:93 print('aws iam delete-login-profile --user-name {}'.format(user_name))94 print('aws iam list-access-keys --user-name {}'.format(user_name))95 for access_key_id in access_key_ids:96 print('aws iam delete-access-key --access-key-id {}'.format(97 access_key_id))98 print('aws iam list-signing-certificates --user-name {}'.format(99 user_name))100 for certificate_id in certificate_ids:101 print('aws iam delete-signing-certificate --certificate-id {}'.102 format(certificate_id))103 print('aws iam list-ssh-public-keys --user-name {}'.format(user_name))104 for ssh_public_key_id in ssh_public_key_ids:105 print(106 'aws iam delete-ssh-public-key --user-name --ssh-public-key-id {}'107 .format(user_name, ssh_public_key_id))108 print(109 'aws iam list-service-specific-credentials --user-name {}'.format(110 user_name))111 for service_specific_credential_id in service_specific_credential_ids:112 print(113 'aws iam delete-service-specific-credential --service-specific-credential-id {}'114 .format(service_specific_credential_id))115 print('aws iam list-mfa-devices --user-name {}'.format(user_name))116 for serial_number in serial_numbers:117 print(118 'aws iam deactivate-mfa-device --user-name {} --serial-number {}'119 .format(user_name, serial_number))120 print(121 'aws iam delete-virtual-mfa-device --serial-number {}'.format(122 serial_number))123 print('aws iam list-user-policy --user-name {}'.format(user_name))124 for policy_name in policy_names:125 print('aws iam delete-user-policy --user-name {} --policy-name {}'.126 format(user_name, policy_name))127 print('aws iam list-attached-user-policies --user-name {}'.format(128 user_name))129 for policy_arn in policy_arns:130 print('aws iam detach-user-policy --user-name {} --policy-arn {}'.131 format(user_name, policy_arn))132 print('aws iam list-groups-for-user --user-name {}'.format(user_name))133 for group_name in group_names:134 print(135 'aws iam remove-user-from-group --user-name {} --group-name {}'136 .format(user_name, group_name))137 print('aws iam delete-user --user-name {}'.format(user_name))138 else:139 client.delete_login_profile(UserName=user_name)140 for access_key_id in access_key_ids:141 client.delete_access_key(AccessKeyId=access_key_id)142 for certificate_id in certificate_ids:143 client.delete_signing_certificate(CertificateId=certificate_id)144 for ssh_public_key_id in ssh_public_key_ids:145 client.delete_ssh_public_key(SSHPublicKeyId=ssh_public_key_id)146 for service_specific_credential_id in service_specific_credential_ids:147 client.delete_service_specific_credential(148 ServiceSpecificCredentialId=service_specific_credential_id)149 for serial_number in serial_numbers:150 client.deactivate_mfa_device(UserName=user_name,151 SerialNumber=serial_number)152 client.delete_virtual_mfa_device(SerialNumber=serial_number)153 for policy_name in policy_names:154 client.delete_user_policy(UserName=user_name,155 PolicyName=policy_name)156 for policy_arn in policy_arns:157 client.detach_user_policy(UserName=user_name, PolicyArn=policy_arn)...
aws-delete-users.py
Source:aws-delete-users.py
...44 45 list_signing_certificates = client.list_signing_certificates(46 UserName=row[1]) # Listing signing certificates47 if list_signing_certificates['Certificates']: # Deleting if any48 delete_signing_certificate = [client.delete_signing_certificate(49 UserName=row[1], CertificateId=Id['CertificateId']) for Id in list_signing_certificates['Certificates'] ]50 list_ssh_public_keys = client.list_ssh_public_keys(UserName=row[1]) # Listing public keys51 if list_ssh_public_keys['SSHPublicKeys']:52 delete_ssh_public_key = [client.delete_ssh_public_key(53 UserName=row[1], SSHPublicKeyId= Id['SSHPublicKeyId']) for Id in list_ssh_public_keys['SSHPublicKeys'] ] # Deleting if any54 list_service_specific_credentials = client.list_service_specific_credentials(55 UserName=row[1]) # Listing service specific credentials 56 if list_service_specific_credentials['ServiceSpecificCredentials']: # Deleting if any57 delete_service_specific_credential = [client.delete_service_specific_credential(58 UserName=row[1], ServiceSpecificCredentialId= Id['ServiceSpecificCredentialId']) for Id in list_service_specific_credentials['ServiceSpecificCredentials'] ]59 list_mfa_devices = client.list_mfa_devices(60 UserName=row[1]61 ) # Listing MFA devices62 if list_mfa_devices['MFADevices']: # Deleting if any...
bot.py
Source:bot.py
...23 iam_client.delete_access_key(UserName=user_name, AccessKeyId=accessKey['AccessKeyId'])24 # Step 3)25 signing_certificate_list = iam_client.list_signing_certificates(UserName=user_name, )26 for certificate in signing_certificate_list['Certificates']:27 iam_client.delete_signing_certificate(UserName=user_name, CertificateId=certificate['CertificateId'])28 # Step 4)29 ssh_key_list = iam_client.list_ssh_public_keys(UserName=user_name, )30 for ssh_key in ssh_key_list['SSHPublicKeys']:31 iam_client.delete_ssh_public_key(UserName=user_name, SSHPublicKeyId=ssh_key['SSHPublicKeyId'])32 # Step 5)33 service_specific_credential_list = iam_client.list_service_specific_credentials(UserName=user_name, )34 for service_specific_credential in service_specific_credential_list['ServiceSpecificCredentials']:35 iam_client.delete_service_specific_credential(UserName=user_name,36 ServiceSpecificCredentialId=service_specific_credential[37 'ServiceSpecificCredentialId'])38 # Step 6)39 mfa_list = iam_client.list_mfa_devices(UserName=user_name, )40 for mfa in mfa_list['MFADevices']:41 iam_client.deactivate_mfa_device(UserName=user_name, SerialNumber=mfa['SerialNumber'])...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!