我正在尝试获取python脚本以列出AWS账户中的组,然后将这些组添加到用户:
group_list = client.list_groups()
for group in group_list['Groups']:
group_name = group['GroupName']
all_groups.append(group_name)
for group_name in all_groups:
print(group_name)
add_group_name = ''
while add_group_name != 'quit':
add_group_name = input("Enter the group name to add to user %s: " % user_name)
if add_group_name is 'quit':
break
else:
client.add_user_to_group(GroupName=add_group_name,UserName=user_name)
这是一个示例运行:
Enter the group name to add to user tdunphy: jf-admin-group
Enter the group name to add to user tdunphy: quit
脚本确实打印出了组,但是当您尝试退出循环时会出现此错误:
botocore.errorfactory.NoSuchEntityException: An error occurred (NoSuchEntity) when calling the AddUserToGroup operation: The group with name quit cannot be found.
这不符合if语句中的中断。如何正确执行此操作?