# distillery_aws
### Overview
The `distillery_aws.py` script is a critical component of the [[Distillery]] system, responsible for managing interactions with various AWS services and handling database operations. It provides a centralized interface for accessing and manipulating data stored in [[AWS RDS]], [[AWS S3]], and [[AWS Memcached]].
The main components and classes within the script include:
- Configuration variables for AWS services and database connection
- `JSONFormatter` and `SimpleMessageFormatter` classes for formatting log messages
- `AWSManager` class for managing AWS interactions and database operations
- `Memcached` class for handling distributed locking using [[AWS Memcached]]
The script utilizes the [[boto3]] and [[aioboto3]] libraries for interacting with AWS services, and the [[aiomysql]] library for asynchronous database operations.
### distillery_aws Dependencies and imports
The `distillery_aws.py` script relies on the following dependencies and imported libraries [[Distillery AWS Dependencies and Imports]]
### distillery_aws Configuration Variables
The `distillery_aws.py` script utilizes various configuration variables to establish connections with AWS services, configure logging, and define application-specific settings.
[[Distillery AWS Configuration Variables]]
### AWS Manager Helper Classes
The `distillery_aws.py` script includes two helper classes, [[JSONFormatter]] and [[SimpleMessageFormatter]], which are used for formatting log messages in different styles.
### AWS Manager Class
This is the main class of the `distillery_aws.py` where the majority of the code is organized. Let's deep dive into its key sections
#### Initialization and Instance Management
The `AWSManager` class follows the singleton pattern, ensuring that only one instance of the class is created throughout the application.
[[AWS Manager Initialization and Instance Management]]
#### Setup Logging
The `setup_logging` method is responsible for setting up the logging configuration for the `AWSManager` class, configuring loggers, handlers, and formatters for sending logs to [[AWS CloudWatch]] and the console.
[[AWS Manager Setup Logging]]
#### Print Log
The `print_log` method is used to log messages with additional metadata using the configured loggers and formatters.
[[AWS Manager Print Log]]
#### Database Connection Management
The `AWSManager` class provides methods for managing database connections, including creating connections, executing queries, and closing connections.
[[AWS Manager Database Connection Management]]
#### User Management
The `AWSManager` class offers methods for managing user-related operations, such as validating users, updating user statistics, and checking request counters.
[[AWS Manager User Management]]
#### Logging and Queueing
The `AWSManager` class implements methods for logging events and managing message queues, including pushing and popping messages from the generation and send queues.
[[AWS Manager Logging and Queueing]]
#### User Statistics and Lora Model Management
The `AWSManager` class provides methods for retrieving user statistics and managing Lora models, including adding, deleting, and updating Lora models and their associated data.
[[AWS Manager User Statistics and Lora Model Management]]
#### Distillery Commands and Lora Acceptance Groups
The `AWSManager` class contains methods for managing Distillery commands and Lora acceptance groups, including adding, deleting, and mapping commands and groups.
[[AWS Manager Distillery Commands and Lora Acceptance Groups]]
#### Rare Token Management and Distill Credits
The `AWSManager` class offers methods for managing rare tokens and distill credits, including adding, deleting, and reserving rare token pairs, and updating distill credits for users.
[[AWS Manager Rare Token Management and Distill Credits]]
#### Memcached Class
The `AWSManager` class includes the `Memcached` class, which handles distributed locking using [[AWS Memcached]].
[[AWS Manager Memcached Class]]