def delete_zip_file(key): client = text_to_speech_s3.get_s3_client() try: client.delete_object( Bucket=CloudCanvas.get_setting(PACKAGEDVOICELINES), Key=key) except ClientError as e: return "ERROR: " + e.response['Error']['Message'] return 'success'
def get_custom_mappings(): file_key = 'import_custom_mappings.json' custom_mappings = {} if key_exists(file_key, TTSCACHE): client = text_to_speech_s3.get_s3_client() response = client.get_object(Bucket=CloudCanvas.get_setting(TTSCACHE), Key=file_key) custom_mappings = json.loads(response["Body"].read()) return custom_mappings
def generate_presigned_url(key): ''' Returns a presigned url for the given key in ttscache bucket ''' s3_client = text_to_speech_s3.get_s3_client() if cache_runtime_generated_files(): return s3_client.generate_presigned_url('get_object', Params = { "Bucket" : CloudCanvas.get_setting(TTSCACHE), "Key" : key }) else: return s3_client.generate_presigned_url('get_object', Params = { "Bucket" : CloudCanvas.get_setting(TTSCACHE), "Key" : key }, ExpiresIn = 300)
def get_generated_packages(): s3_client = text_to_speech_s3.get_s3_client() response = s3_client.list_objects( Bucket=CloudCanvas.get_setting(PACKAGEDVOICELINES)) generated_packages = [] for s3_object in response.get('Contents', []): if not ID_PACKAGES_FOLDER in s3_object['Key']: generated_packages.append({ 'name': s3_object['Key'], 'lastModified': s3_object['LastModified'].strftime("%Y-%m-%d %H:%M:%S"), 'size': s3_object['Size'] }) return generated_packages
def __generate_presigned_url(key): s3_client = text_to_speech_s3.get_s3_client() try: presigned_url = s3_client.generate_presigned_url( 'get_object', Params={ 'Bucket': CloudCanvas.get_setting(PACKAGEDVOICELINES), 'Key': key }) except: error_message = 'Could not generate the presigned URL for {}.'.format( key) raise ClientError(error_message) return presigned_url tts.get_bucket(PACKAGEDVOICELINES).put_object(Key=file_key, Body=json.dumps(export_info))
def enable_cache_runtime_generated_files(enable): s3 = text_to_speech_s3.get_s3_client() if enable and not cache_runtime_generated_files(): s3.delete_object(Bucket=CloudCanvas.get_setting(TTSCACHE), Key=RUNTIME_CACHING_FLAG_KEY) elif not enable and cache_runtime_generated_files(): s3.put_object(Bucket=CloudCanvas.get_setting(TTSCACHE), Key=RUNTIME_CACHING_FLAG_KEY)
def enable_runtime_capabilities(enable): s3 = text_to_speech_s3.get_s3_client() if enable and key_exists(RUNTIME_CAPABILITIES_FLAG_KEY, TTSCACHE): s3.delete_object(Bucket=CloudCanvas.get_setting(TTSCACHE), Key=RUNTIME_CAPABILITIES_FLAG_KEY) elif not enable and not key_exists(RUNTIME_CAPABILITIES_FLAG_KEY, TTSCACHE): s3.put_object(Bucket=CloudCanvas.get_setting(TTSCACHE), Key=RUNTIME_CAPABILITIES_FLAG_KEY)