Automated Cognito Hygiene
Developed with the software and tools below.
cognito-clean
stands as a streamlined solution for managing AWS Cognito user pools, specifically targeting the perennial issue of unconfirmed user accounts. It provides a simple, automated way to clean up unconfirmed user accounts, ensuring that only active, verified users remain in the user pool. This project is designed to be run as a scheduled Lambda function, ensuring that user pools are kept clean and efficient without manual intervention.
Feature | Description | |
---|---|---|
⚙️ | Architecture | This project utilises AWS Lambda for cleaning up unconfirmed Cognito user accounts. |
🔩 | Code Quality | Adheres to PEP8 guidelines, enforced by flake8 and pylint. The code is structured around modular Python scripts, enhancing readability and maintainability. |
🔌 | Integrations | Integrates with AWS services like Lambda, S3, SNS and of course, Cognito. GitHub Actions is used for CI/CD, ensuring automated testing and deployment. |
🧪 | Testing | Uses pytest and pytest-cov for running tests and measuring code coverage, ensuring reliability and functionality across updates. |
📦 | Dependencies | Depends on boto3 for AWS interactions, pytest , pytest-cov , and coverage for testing, and flake8 for linting. Managed with poetry for dependency resolution. |
└── cognito-clean/
├── CONTRIBUTING.md
├── LICENSE
├── README.md
├── cognito_clean
│ ├── cognito_cleaner.py
│ ├── cognito_manager.py
│ ├── file_manager.py
│ └── notification_service.py
├── poetry.lock
├── pylintrc
├── pyproject.toml
├── sonar-project.properties
├── template.yaml
└── tests
├── test_cognito_manager.py
├── test_file_manager.py
└── test_notification_service.py
.
File | Summary |
---|---|
pylintrc | The pylintrc file defines linting rules for the cognito-clean repository, aiming to enforce code quality standards and error prevention across the Python modules. |
pyproject.toml | This pyproject.toml configures the cognito-clean project, defining dependencies, build settings, and test configurations. |
poetry.lock | A record of all the exact versions of the dependencies used in cognito-clean |
cognito_clean
File | Summary |
---|---|
notification_service.py | Sends email notifications via AWS SNS for deleted users info. Validates inputs and formats messages before publishing to the specified SNS topic. Handles errors during message sending process. |
cognito_cleaner.py | Configures AWS services, processes unconfirmed users, and handles deletions. Deletes users based on specified criteria, stores data in S3, and sends notifications. Caches processed data for efficient future runs. |
file_manager.py | Writes deleted user data to an S3 bucket in JSON format, logging successful or failed write attempts. Skips write operation if necessary S3 bucket details are missing. |
cognito_manager.py | Manages user listing and deletion in Cognito User Pool based on specified criteria and cache. It filters users older than a set age or since the last run time, handling deletion and cache updates. |
Requirements
Ensure you have the following dependencies installed on your system:
- Python:
version 3.10+
- Poetry:
version 1.8.2+
- Clone the cognito-clean repository:
git clone https://github.com/XargsUK/cognito-clean
- Change to the project directory:
cd cognito-clean
- Install the dependencies with Poetry:
poetry install
Use the following command to run tests:
poetry run pytest
Contributions are welcome! Here are several ways you can contribute:
- Submit Pull Requests: Review open PRs, and submit your own PRs.
- Report Issues: Submit bugs found or log feature requests for the
cognito-clean
project.
Contributing Guidelines
- Fork the Repository: Start by forking the project repository to your github account.
- Clone Locally: Clone the forked repository to your local machine using a git client.
git clone https://github.com/XargsUK/cognito-clean
- Create a New Branch: Always work on a new branch, giving it a descriptive name.
git checkout -b new-feature-x
- Make Your Changes: Develop and test your changes locally.
- Commit Your Changes: Commit with a clear message describing your updates.
git commit -m 'Implemented new feature x.'
- Push to GitHub: Push the changes to your forked repository.
git push origin new-feature-x
- Submit a Pull Request: Create a PR against the original project repository. Clearly describe the changes and their motivations.
Once your PR is reviewed and approved, it will be merged into the main branch.
This project is protected under the MIT License.