First, let's implement the private APIs and services that provide common capabilities. We will have two services; both of them should be created in the chalicelib directory:
- StorageService: The StorageService class that's implemented in the storage_service.py file connects to AWS S3 via boto3 to perform tasks on files we need for the applications.
Let's implement StorageService, as follows:
import boto3
class StorageService:
def __init__(self, storage_location):
self.client = boto3.client('s3')
self.bucket_name = storage_location
def get_storage_location(self):
return self.bucket_name
def list_files(self):
response = self.client.list_objects_v2(Bucket = self.bucket_name)
files = []
for content in response['Contents']:
files.append...