in traffic_mirroring/app_helper.py [0:0]
def create_target(ec2, target_subnet_id, config, existing_target_id = None):
target_instance = launch_target_instance(ec2, target_subnet_id, config)
network_interface_id = target_instance["Instances"][0]["NetworkInterfaces"][0]["NetworkInterfaceId"]
try:
target_id = create_target_with_tag(ec2, network_interface_id, target_subnet_id)
remove_subnet_tag(ec2, target_subnet_id, existing_target_id)
log.info("TrafficMirrorTarget %s created", target_id)
return target_id
except Exception as e:
target_instance_id = target_instance["Instances"][0]["InstanceId"]
log.info("Failed to create target. Terminating the launched target instance %s", target_instance_id)
ec2.terminate_instances(InstanceIds=[target_instance_id])
raise e