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