我正在使用带有实例配置文件的ec2实例配置文件启动服务器。
问题是简介有时不是"那里"在创建它之后,即使我等了10秒钟:
# Create new Instance Profile
instanceProfile = self.iam.create_instance_profile(InstanceProfileName=instProfName)
instanceProfile.add_role(RoleName="...")
time.sleep(10)
# Create the Instance
instances = self.ec2.create_instances(
# ...
IamInstanceProfile={
"Name":instanceProfile.instance_profile_name
}
)
有没有办法等待它传播?
我的第一次尝试是:
error = 30
dryRun = True
while error > 0:
try:
# Create the Instance
instances = self.ec2.create_instances(
DryRun=dryRun
# ...
IamInstanceProfile={
"Name":instanceProfile.instance_profile_name
}
)
if not dryRun:
break;
dryRun = False
except botocore.exceptions.ClientError as e:
error = error - 1;
但是如何才能获得IAM配置文件错误?
答案 0 :(得分:0)
大部分AWS使用"最终的一致性"。这意味着在进行更改后,需要一些时间才能在系统中传播。
创建实例配置文件后:
iam.get_instance_profile
。get_instance_profile
返回您的信息。你可以做的另一件事是抓住"实例个人资料未找到错误"在ec2.create_instances
通话期间,如果您收到错误,请延迟并重复此操作。