-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathlambda_scheduler.py
More file actions
35 lines (28 loc) · 986 Bytes
/
lambda_scheduler.py
File metadata and controls
35 lines (28 loc) · 986 Bytes
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
import json
import logging
from daily_word_bot.app import App
logger = logging.getLogger()
logger.setLevel(logging.INFO)
# Initialize the app outside the handler to reuse it across warm invocations
app = App()
def lambda_handler(event, context):
"""
AWS Lambda handler function for Scheduled Events.
"""
logger.info(f"Received scheduled event: {json.dumps(event)}")
try:
# User requested to read Excel on each request.
logger.info("Updating WordBank from source...")
app.word_bank.update()
# Pass the detail or the whole event to handle different schedules
app.process_send_word()
return {
'statusCode': 200,
'body': json.dumps('Scheduled event processed')
}
except Exception as e:
logger.error(f"Error processing event: {e}", exc_info=True)
return {
'statusCode': 500,
'body': json.dumps(f"Internal server error: {str(e)}")
}