mirror of
https://github.com/certbot/certbot.git
synced 2026-08-03 03:32:13 +02:00
Fix race condition adding tags to instance. (#7080)
This commit is contained in:
committed by
Adrien Ferrand
parent
7a6545b747
commit
6bcd0415e0
@@ -146,32 +146,19 @@ def make_instance(instance_name,
|
|||||||
subnet_id,
|
subnet_id,
|
||||||
machine_type='t2.micro',
|
machine_type='t2.micro',
|
||||||
userdata=""): #userdata contains bash or cloud-init script
|
userdata=""): #userdata contains bash or cloud-init script
|
||||||
|
block_device_mappings = _get_block_device_mappings(ami_id)
|
||||||
new_instance = EC2.create_instances(
|
tags = [{'Key': 'Name', 'Value': instance_name}]
|
||||||
BlockDeviceMappings=_get_block_device_mappings(ami_id),
|
tag_spec = [{'ResourceType': 'instance', 'Tags': tags}]
|
||||||
ImageId=ami_id,
|
return EC2.create_instances(BlockDeviceMappings=block_device_mappings,
|
||||||
SecurityGroupIds=[security_group_id],
|
ImageId=ami_id,
|
||||||
SubnetId=subnet_id,
|
SecurityGroupIds=[security_group_id],
|
||||||
KeyName=keyname,
|
SubnetId=subnet_id,
|
||||||
MinCount=1,
|
KeyName=keyname,
|
||||||
MaxCount=1,
|
MinCount=1,
|
||||||
UserData=userdata,
|
MaxCount=1,
|
||||||
InstanceType=machine_type)[0]
|
UserData=userdata,
|
||||||
|
InstanceType=machine_type,
|
||||||
# brief pause to prevent rare error on EC2 delay, should block until ready instead
|
TagSpecifications=tag_spec)[0]
|
||||||
time.sleep(1.0)
|
|
||||||
|
|
||||||
# give instance a name
|
|
||||||
try:
|
|
||||||
new_instance.create_tags(Tags=[{'Key': 'Name', 'Value': instance_name}])
|
|
||||||
except ClientError as e:
|
|
||||||
if "InvalidInstanceID.NotFound" in str(e):
|
|
||||||
# This seems to be ephemeral... retry
|
|
||||||
time.sleep(1)
|
|
||||||
new_instance.create_tags(Tags=[{'Key': 'Name', 'Value': instance_name}])
|
|
||||||
else:
|
|
||||||
raise
|
|
||||||
return new_instance
|
|
||||||
|
|
||||||
def _get_block_device_mappings(ami_id):
|
def _get_block_device_mappings(ami_id):
|
||||||
"""Returns the list of block device mappings to ensure cleanup.
|
"""Returns the list of block device mappings to ensure cleanup.
|
||||||
|
|||||||
Reference in New Issue
Block a user