-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlambda_handler.py
More file actions
36 lines (31 loc) · 1.03 KB
/
lambda_handler.py
File metadata and controls
36 lines (31 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import json
import os
from celery_task import crawl_and_store_articles
def handler(event, context):
"""
AWS Lambda handler for news crawling
"""
try:
# EventBridge에서 호출되는 경우 또는 직접 호출
source = event.get('source', 'manual')
# Celery 태스크 실행 (Lambda 환경에서는 동기 실행)
result = crawl_and_store_articles.apply()
return {
'statusCode': 200,
'body': json.dumps({
'message': 'News crawling completed successfully',
'source': source,
'task_id': str(result.id) if hasattr(result, 'id') else 'sync',
'status': 'success'
})
}
except Exception as e:
print(f"Lambda execution error: {str(e)}")
return {
'statusCode': 500,
'body': json.dumps({
'message': 'News crawling failed',
'error': str(e),
'status': 'error'
})
}