我正在使用 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.
蛊毒传说
相关分类