Boto3 IAM服务员不在等待中

时间:2019-03-28 20:51:08

标签: python amazon-web-services boto3 amazon-iam

我正在使用boto3创建一个IAM用户,等到创建IAM用户后,再更新该用户的登录配置文件。我创建用户的python代码工作正常,并且用户创建成功。 IAM最终是一致的,因此我知道我需要等待创建用户之后才能对其执行任何其他操作,并且我正在为此目的使用侍者。但是,当我尝试更新登录配置文件时,错误提示用户还不存在。

所以基本上服务员没有像应该的那样等待。

有人知道我在做什么错吗?

import boto3

password = 'not_the_real_password'

client = boto3.client('iam')

# Create the user
response = client.create_user(
    UserName='someuser'
)

# Creating the user works fine. But IAM is eventually consistent, so we have
# to wait for the user to be created before we can do anything with it.
waiter = client.get_waiter('user_exists')
waiter.wait(UserName='someuser')

# If the waiter worked correctly, then it should have waited for the user
# to be created before updating the login profile.
response = client.update_login_profile(
    UserName='someuser',
    Password=password,
    PasswordResetRequired=True
)

预期结果:服务员应等待足够长的时间以使IAM用户存在,然后更新登录配置文件即可按预期工作。

实际结果:

Traceback (most recent call last):
  File "add_user.py", line 20, in <module>
    PasswordResetRequired=True
  File "/home/myuser/.local/lib/python3.6/site-packages/botocore/client.py", line 357, in _api_call
    return self._make_api_call(operation_name, kwargs)
  File "/home/myuser/.local/lib/python3.6/site-packages/botocore/client.py", line 661, in _make_api_call
    raise error_class(parsed_response, operation_name)
botocore.errorfactory.NoSuchEntityException: An error occurred (NoSuchEntity) when calling the UpdateLoginProfile operation: Login Profile for User someuser cannot be found.

1 个答案:

答案 0 :(得分:1)

错误提示:

  

找不到用户someuser的登录配置文件。

登录配置文件用户是分开的。它需要专门创建。

update_login_profile()更改为create_login_profile()