in cdk-project/lambda/python-functions/clean_endpoints.py [0:0]
def delete_experiment(client, experiment_name):
trials = client.list_trials(ExperimentName=experiment_name)
for trial in trials["TrialSummaries"]:
trial_name = trial["TrialName"]
trial_components = client.list_trial_components(TrialName=trial_name)
for tc in trial_components["TrialComponentSummaries"]:
tc_name = tc["TrialComponentName"]
client.disassociate_trial_component(
TrialName=trial_name,
TrialComponentName=tc_name,
)
try:
client.delete_trial_component(TrialComponentName=tc_name)
except botocore.exceptions.ClientError as e:
# If the trial component is still linked to another trial,
# ignore it for now. (It will get deleted once completely unlinked.)
linked_tc_msg = (
"An error occurred (ValidationException) when calling the "
"DeleteTrialComponent operation: TrialComponent %s is linked "
"to 1 or more trials and cannot be deleted."
) % tc_name
if linked_tc_msg in str(e):
pass
else:
raise
client.delete_trial(TrialName=trial_name)
client.delete_experiment(ExperimentName=experiment_name)