【发布时间】:2019-03-29 07:39:36
【问题描述】:
我正在使用 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.
【问题讨论】:
标签: python amazon-web-services boto3 amazon-iam