0
我正在使用具有实例配置文件的ec2实例配置文件启动服务器。AWS:如何确保在启动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配置文件错误?
我该如何捕捉一个只有“ClientError”的错误? – Tobi
您需要检查'e'来查看是否有任何可区分的数据。否则,你只需要重新尝试任何这样的错误。 –
嗯...问题是我不能检查'E'没有真正尝试启动一个实例 – Tobi