import os import datetime import boto3 import time from botocore.exceptions import ClientError import json AWS_ACCESS_KEY_ID = os.environ['aws_key'] AWS_SECRET_ACCESS_KEY = os.environ['aws_secret'] BUCKET_NAME = 'app-data-storage-354897' def upload_to_s3(current_time): local_file_path = "/db/rasa/rasa.db" s3_object_key = f'data_{current_time}.db' try: s3 = boto3.client('s3', aws_access_key_id=AWS_ACCESS_KEY_ID, aws_secret_access_key=AWS_SECRET_ACCESS_KEY) s3.upload_file(local_file_path, BUCKET_NAME, s3_object_key) print(f"Uploaded '{local_file_path}' to '{s3_object_key}' in bucket '{BUCKET_NAME}' at {current_time}") except FileNotFoundError: print(f"Local file '{local_file_path}' not found at {current_time}") except ClientError as e: print(f"An error occurred during S3 upload: {e} at {current_time}") if __name__ == '__main__': while True: current_time = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") time.sleep(120) print("-" * 20) upload_to_s3(current_time) print("-" * 20) time.sleep(12*60*60)