diff --git a/basic_setup/awsses.sh b/basic_setup/awsses.sh index 13b00dc..8114e64 100755 --- a/basic_setup/awsses.sh +++ b/basic_setup/awsses.sh @@ -114,10 +114,10 @@ if ! aws lambda get-function --function-name "$LAMBDA_NAME" --region "$AWS_REGIO else echo " -> Aktualisiere existierende Lambda-Funktion..." aws lambda update-function-code --function-name "$LAMBDA_NAME" --zip-file fileb://lambda.zip --region "$AWS_REGION" >/dev/null - + # Warte kurz sleep 2 - + aws lambda update-function-configuration --function-name "$LAMBDA_NAME" --region "$AWS_REGION" >/dev/null fi # Aufräumen diff --git a/basic_setup/ses_sns_shim_global.py b/basic_setup/ses_sns_shim_global.py index 0eb0c40..3eb945f 100644 --- a/basic_setup/ses_sns_shim_global.py +++ b/basic_setup/ses_sns_shim_global.py @@ -47,44 +47,44 @@ def lambda_handler(event, context): try: records = event.get('Records', []) logger.info(f"Received event with {len(records)} records.") - + for record in records: ses_data = record.get('ses', {}) if not ses_data: logger.warning(f"Invalid SES event: Missing 'ses' in record: {record}") continue - + mail = ses_data.get('mail', {}) receipt = ses_data.get('receipt', {}) - + # Domain extrahieren (aus erstem Recipient) recipients = receipt.get('recipients', []) or mail.get('destination', []) if not recipients: logger.warning("No recipients in event - skipping") continue - + first_recipient = recipients[0] domain = first_recipient.split('@')[-1].lower() if not domain: logger.error("Could not extract domain from recipient") continue - + # Wichtige Metadaten loggen msg_id = mail.get('messageId', 'unknown') source = mail.get('source', 'unknown') logger.info(f"Processing Message-ID: {msg_id} for domain: {domain}") logger.info(f" From: {source}") logger.info(f" To: {recipients}") - + # SES JSON als String serialisieren ses_json_string = json.dumps(ses_data) - + # Payload Größe loggen und checken (Safeguard) payload_size = len(ses_json_string.encode('utf-8')) logger.info(f" Metadata Payload Size: {payload_size} bytes") if payload_size > 200000: # Arbitrary Limit < SQS 256KB raise ValueError("Payload too large for SQS") - + # Fake SNS Payload fake_sns_payload = { "Type": "Notification", @@ -94,10 +94,10 @@ def lambda_handler(event, context): "Message": ses_json_string, "Timestamp": datetime.utcnow().isoformat() + "Z" } - + # Queue URL dynamisch holen queue_url = get_queue_url(domain) - + # SQS Send mit Retries attempt = 0 while attempt < MAX_RETRIES: @@ -115,9 +115,9 @@ def lambda_handler(event, context): if attempt == MAX_RETRIES: raise time.sleep(exponential_backoff(attempt)) - + return {'status': 'ok'} - + except Exception as e: logger.error(f"❌ Critical Error in Lambda Shim: {str(e)}", exc_info=True) - raise e \ No newline at end of file + raise e \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index c74e700..dc98231 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -13,8 +13,11 @@ services: # Python Dependencies installieren und Worker starten command: > - sh -c "pip install --no-cache-dir boto3 && - python -u worker.py" + sh -c "apt-get update && + apt-get install -y --no-install-recommends procps && + rm -rf /var/lib/apt/lists/* && + pip install --no-cache-dir boto3 && + python -u worker.py" environment: # ⚠️ WICHTIG: WORKER_DOMAIN muss von außen gesetzt werden!