Anyone have any idea about this error. I am using AWS translate, boto3, and Zappa and made a script to convert the language which works fine in local and throw this error on AWS lambda. I seriously don't know why? Anyone face this error before?
Here is my code:
from flask import Flask, jsonify, Blueprint, request, current_app
import os
import boto3
app = Flask(__name__)
translate = boto3.client(service_name='translate')
s3 = boto3.resource('s3')
s3_data = boto3.client('s3')
def check_file(file_name):
s3 = boto3.resource('s3')
my_bucket = s3.Bucket('output-file1')
for s3_filename in my_bucket.objects.all():
if s3_filename.key == file_name:
return True
else:
return False
def convert_data():
BUCKET_NAME = 'output-file1'
my_bucket = s3.Bucket('input-file1')
for s3_object in my_bucket.objects.all():
data = check_file(s3_object.key)
if data == False or data is None:
body = s3_object.get()['Body'].read()
file_data = bytearray(body)
response = translate.translate_text(Text=str(file_data), SourceLanguageCode="en", TargetLanguageCode="fr")
# response = translate.translate_text(Text=str(file_data), TerminologyNames=["testing"],\
# SourceLanguageCode="en", TargetLanguageCode="fr")
print("Translated text: " + response.get('TranslatedText'))
with open('/tmp/' + s3_object.key, 'w') as txtfile:
txtfile.write(str(response.get('TranslatedText')))
txtfile.close()
s3_data.upload_file(Bucket='output-file1',\
Key=s3_object.key, Filename='/tmp/' + s3_object.key)
print('========Upload The File===========')
# convert_data()
def convert_langauge():
with app.app_context():
convert_data()
return True
if __name__ == "__main__":
app.run()