51 lines
1.5 KiB
Python

import json
import logging
from datetime import datetime, timedelta, timezone
from typing import Dict, Any
from http import HTTPStatus
logger = logging.getLogger()
logger.setLevel(logging.INFO)
def lambda_handler(event: Dict[str, Any], context: Any) -> Dict[str, Any]:
try:
action_group = event.get("actionGroup")
function = event.get("function")
message_version = event.get("messageVersion", 1)
# Get current UTC time
utc_now = datetime.now(timezone.utc)
# Assume CET is UTC+2 for summer (CEST)
# Use UTC+1 if you want standard time
cet_offset = timezone(timedelta(hours=2)) # Change to +1 in winter
cet_now = utc_now.astimezone(cet_offset)
response_body = {
"TEXT": {
"body": (
f"Current time:\n"
f"- UTC: {utc_now.strftime('%Y-%m-%d %H:%M:%S %Z')}\n"
f"- CET (UTC+2): {cet_now.strftime('%Y-%m-%d %H:%M:%S %Z')}"
)
}
}
return {
"response": {
"actionGroup": action_group,
"function": function,
"functionResponse": {
"responseBody": response_body
}
},
"messageVersion": message_version
}
except Exception as e:
logger.error("Unexpected error: %s", str(e))
return {
"statusCode": HTTPStatus.INTERNAL_SERVER_ERROR,
"body": f"Internal server error: {str(e)}"
}