A set of tools providing utils for interacting with AWS tools
Project description
AWS Utils 🚀
A Python library to simplify interaction with AWS services such as SES (Simple Email Service), SSM (Systems Manager Parameter Store), and CloudWatch Logs.
Designed and maintained by Luigi Moro
Features ✨
- SES Email Client: Send emails (with or without attachments) via AWS SES.
- SSM Parameter Manager: Retrieve and manage parameters from AWS Systems Manager Parameter Store.
- CloudWatch Logs Collector: Query and process logs from AWS CloudWatch.
- Type hints and modern Python practices for robust, maintainable code.
- Easily testable with pytest and mocks.
Installation ⚡
pip install -r requirements.txt
Or, if using poetry:
poetry install
Usage 📚
SES Email Client ✉️
Send emails with or without attachments via AWS SES.
from aws_utils.ses.email_manager import SesEmailClient
email_client = SesEmailClient(
region_name="eu-west-1",
aws_access_key_id="YOUR_AWS_ACCESS_KEY_ID",
aws_secret_access_key="YOUR_AWS_SECRET_ACCESS_KEY",
aws_session_token="YOUR_AWS_SESSION_TOKEN"
)
# Send email with attachment
email_client.send_email(
source="sender@example.com",
to_addresses=["recipient@example.com"],
subject="Test Email with Attachment",
body="This is a test email with an attachment.",
attachments=["/path/to/file.txt"]
)
SSM Parameter Manager 🗝️
Retrieve parameters from AWS SSM:
from aws_utils.ssm.parameters_manager import PropertiesManager
manager = PropertiesManager()
value = manager.fetch_parameter_value('parameter_key')
print(value)
CloudWatch Logs Collector 📈
Query CloudWatch logs:
from aws_utils.cloudwatch.log_utils import CloudWatchLogsCollector
collector = CloudWatchLogsCollector(log_group="your-log-group")
logs = collector.collect_raw_logs(
query="fields @timestamp, @message | sort @timestamp desc",
start=datetime(2024, 1, 1),
end=datetime(2024, 1, 2)
)
print(logs)
Testing 🧪
Tests are written with pytest and use mocks for AWS clients.
pytest
Example test for SES email sending (see tests/aws_utils/ses/test_email_manager.py):
from unittest.mock import patch, MagicMock
from aws_utils.ses.email_manager import SesEmailClient
def test_send_email_without_attachment():
with patch("boto3.client") as mock_boto_client:
mock_ses = MagicMock()
mock_boto_client.return_value = mock_ses
client = SesEmailClient("eu-west-1", "key", "secret", "token")
mock_ses.send_email.return_value = {"MessageId": "123"}
result = client.send_email(
source="from@example.com",
to_addresses=["to@example.com"],
subject="Subject",
body="Body"
)
assert result == {"MessageId": "123"}
Documentation 📖
- Project documentation: GitHub Pages
- For access issues, contact:
luigi.moro.1976@gmail.com
Contributing 🤝
- Fork the repo and create your branch:
git checkout -b feature/your-feature - Commit your changes:
git commit -am 'Add some feature' - Push to the branch:
git push origin feature/your-feature - Open a pull request
License 📄
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file aws_services_utils-0.0.6.tar.gz.
File metadata
- Download URL: aws_services_utils-0.0.6.tar.gz
- Upload date:
- Size: 8.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.12.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
45cb2a4df28c3dcc894d2cfb927906b9e67ebfb2452e5aa39a6185bcf29234dd
|
|
| MD5 |
25ac43e26fb9920f5d9a7ceb0a589b7e
|
|
| BLAKE2b-256 |
4c8dd4e3be89d8dd8b1cefbfb235182fcfa388ec73e069e103881c7ae94aec83
|
File details
Details for the file aws_services_utils-0.0.6-py3-none-any.whl.
File metadata
- Download URL: aws_services_utils-0.0.6-py3-none-any.whl
- Upload date:
- Size: 9.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.12.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0823c2ccfcf489e3886eec201d190df46aa5d636ebb330a0982c5ac06c9c2fde
|
|
| MD5 |
b0bb7ccdb18e163628241c7ab55790cb
|
|
| BLAKE2b-256 |
0ef2f2a00d4a802d19206065040ff8023593b0933349d18b0bc350b4194e2890
|