Reputation: 429
Hello I'm using the aws cli with pyhon. I need to delete previous jobs from the transcription service to prevent a high invoice. My problem remains when the script starts because yet there isn't any job, I need delete if it exist and if it doesn't exists do nothing.
transcribe_client = boto3.client('transcribe', aws_access_key_id=AWS_ACCESS_KEY_ID,
aws_secret_access_key=AWS_SECRET_ACCESS_KEY, region_name=AWS_DEFAULT_REGION)
JOB_NAME = "Example-job"
try:
transcribe_client.delete_transcription_job(TranscriptionJobName=JOB_NAME)
except ClientError as e:
raise Exception( "boto3 client error el job doesnt exists: " + e.__str__())
except Exception as e:
raise Exception( "Unexpected error deleting job: " + e.__str__())
When the program starts it's throwing a exception because there isn't any job. I need to check if this exists and the delete it, and if this job doesn't exists do nothing and should not exists crashes.
Also I don't know if this jobs has a price, if this jobs doesn't have cost/price I will generate many jobs with unique id and of this way I should prevent crashes.
any idea guys to solve this problem I will appreciate. thanks so much.
Upvotes: -1
Views: 383
Reputation: 78890
You can call list_transcription_jobs to retrieve a list of transcription jobs that match the specified criteria, or a list of all transcription jobs if you don't specify criteria. You can then iterate over the results and decide which jobs need to be deleted.
Alternatively, You can call get_transcription_job which, according to the docs, will throw TranscribeService.Client.exceptions.NotFoundException.
Upvotes: 1