Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use S3 storage instead of /data folder #49

Open
bonk1t opened this issue Apr 14, 2024 · 0 comments
Open

Use S3 storage instead of /data folder #49

bonk1t opened this issue Apr 14, 2024 · 0 comments
Labels
enhancement New feature or request good first issue Good for newcomers python Pull requests that update Python code

Comments

@bonk1t
Copy link
Collaborator

bonk1t commented Apr 14, 2024

In the WriteAndSaveProgram skill, we utilize the agency_id to construct a directory path for each agency. However, this is a bad practice and we need a persistent solution. We should establish an external storage solution for each user. Using S3-compliant storage and creating a bucket would be a viable approach.

To integrate S3 storage into our FastAPI application, we can follow these steps:

  1. [us] Choose an S3 Storage Provider: Since we've deployed the app on Heroku, supporting Amazon S3 for storage would be a straightforward choice due to its broad support, scalability, and integration with Heroku.

  2. [end user] Set Up the S3 Bucket: Set up an S3 bucket in our preferred region. Ensure the bucket policy and IAM roles are set up accordingly to allow programmatic access.

  3. [us] Install Boto3: Boto3 is the Amazon Web Services (AWS) SDK for Python, which allows Python developers to write software that uses services like Amazon S3.

  4. [end user] Configure Access Credentials: End users need to securely store their access credentials (such as AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY) in user variables.

  5. [us] Modify the Current File Handling Logic: We currently have the WriteAndSaveProgram skill in /backend/custom_skills/write_and_save_program.py that manages file writing locally. We'll replace the logic in the File class's run method with code to upload files to S3. Here's a basic example of how we might upload files to S3:

import boto3
from botocore.exceptions import NoCredentialsError

def upload_to_s3(bucket_name, file_name, body):
    s3 = boto3.client('s3')
    try:
        s3.put_object(Bucket=bucket_name, Key=file_name, Body=body)
        print(f"File {file_name} uploaded to {bucket_name}")
    except NoCredentialsError:
        print("Credentials not available")

# In the File class's run method, replace the file writing logic with:
upload_to_s3("bucket_name", self.file_name, self.body)
  1. [us] Test the Integration: Before deploying the changes to production, ensure we've tested the S3 integration locally and on a staging environment to confirm that files are being uploaded correctly, and our application can retrieve them as needed.

  2. [us] Update Documentation: Reflect these changes in both the main README.md and the backend's README.md, specifying the requirement for S3 storage and environment variables setup.

Use this branch:
https://github.com/AI-in-Hand/platform/tree/feat/use_s3_storage_instead_of_data_folder
Need to apply the new approach to all the skills that read/write to the local drive.

@bonk1t bonk1t added enhancement New feature or request help wanted Extra attention is needed labels Apr 14, 2024
@bonk1t bonk1t added good first issue Good for newcomers python Pull requests that update Python code and removed help wanted Extra attention is needed labels Apr 23, 2024
@bonk1t bonk1t added sweep and removed sweep labels May 11, 2024
@AI-in-Hand AI-in-Hand deleted a comment from sweep-ai bot May 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers python Pull requests that update Python code
Projects
None yet
Development

No branches or pull requests

1 participant