I have a lambda function that I wanted to run everyday at sunset. I tried using eventbridge to trigger it every day and then used time.sleep()
to wait until sunset, but it turns out lambda functions timeout after at most 15 minutes. And as I don't live near the equator, sunset throughout the year varies by more than that. Is there anyway to invoke a lambda function at every sunset? (Preferably it should be free as I'm trying to only use AWS free tier.)
Sunset time changes everyday, so you're going to have to retrieve it on a daily basis (I believe, I'm not an astronomer).
I would create a lambda function that fetches the sunset time, and I would invoke this lambda function daily with an EventBridge rule (in the morning). This lambda function would use the retrieved sunset time to create another EventBridge rule via the boto3 api which invokes the lambda you already have at the desired time. You could also have the lambda function delete already existing rules when it runs before creating the new one.