diff --git a/.jules/bolt.md b/.jules/bolt.md index 693d8da..e2d3ecc 100644 --- a/.jules/bolt.md +++ b/.jules/bolt.md @@ -17,3 +17,7 @@ ## 2026-06-10 - [Stream] Faster Cross-Model Validation with from_attributes **Learning:** When validating a Pydantic model using data from another Pydantic model (e.g., transforming a `SourceItem` to a `DestinationItem`), using `Model.model_validate(other_model, from_attributes=True)` is significantly faster and more memory-efficient than `Model.model_validate(other_model.model_dump())`. It bypasses the overhead of serializing the source model into an intermediate Python dictionary. **Action:** Use `from_attributes=True` for efficient model-to-model transformations, especially in high-throughput data processing paths like DynamoDB Streams or SQS batch processing. + +## 2026-06-11 - [General] Optimized AWS Service Clients with botocore.config.Config +**Learning:** Configuring Boto3 clients with `tcp_keepalive=True` and `retries={"max_attempts": 3, "mode": "standard"}` in the `botocore.config.Config` significantly improves connection resilience and reduces latency in AWS Lambda. TCP keep-alive ensures that connections in the pool remain active, avoiding the overhead of re-establishing TCP/TLS handshakes, while the 'standard' retry mode provides more robust exponential backoff. +**Action:** Always use a centralized `botocore.config.Config` when instantiating Boto3 resources or clients in Lambda templates to optimize performance and reliability. diff --git a/templates/queue.py b/templates/queue.py index 0e1a651..534be9b 100644 --- a/templates/queue.py +++ b/templates/queue.py @@ -1,4 +1,5 @@ from boto3 import client +from botocore.config import Config class Queue: @@ -11,8 +12,10 @@ def __init__(self, queue_url: str, region_name: str = "us-east-1") -> None: queue_url: The URL of the SQS queue. region_name: The region to use. """ + # Optimize connection resilience and performance with TCP keepalive and standard retries + config = Config(tcp_keepalive=True, retries={"max_attempts": 3, "mode": "standard"}) self._queue_url = queue_url - self._client = client("sqs", region_name=region_name) + self._client = client("sqs", region_name=region_name, config=config) def publish(self, message: str) -> None: """Publish a processed message to SQS. diff --git a/templates/repository.py b/templates/repository.py index e59f991..4b5cead 100644 --- a/templates/repository.py +++ b/templates/repository.py @@ -1,4 +1,5 @@ from boto3 import resource +from botocore.config import Config class Repository: @@ -12,7 +13,9 @@ def __init__(self, table_name: str) -> None: Args: table_name: The name of the DynamoDB table to operate on. """ - self._table = resource("dynamodb").Table(table_name) + # Optimize connection resilience and performance with TCP keepalive and standard retries + config = Config(tcp_keepalive=True, retries={"max_attempts": 3, "mode": "standard"}) + self._table = resource("dynamodb", config=config).Table(table_name) def get_item(self, item_id: str) -> dict | None: """Retrieve an item by its ID.