Heyo, I'm looking to trigger a lambda function at ...
# help
j
Heyo, I'm looking to trigger a lambda function at some point in the future. E.g. I want to run it 6 months from when a user creates an account in cognito. In the past, I've done this by using step functions but it was quite costly. So just wondering if anyone here has another idea on how to do this?
c
You can use eventbus to create a cronjob, dono how much it will cost though
r
Could be done with step functions, I think
a
I usually have a cron job that checks every “x days” if a condition is met. For example you could save the date for the check you want to do somewhere, and the cron job will run the desired action for all users where that “date for check” is “today”.
k
Depending on the amount of checks you have, you might need to store the users somewhere (dynamoDB, S3-folder structure organized by action date ...) together with the action date + then use the approach Arpad suggested. There are some 3rd party services for that as well (e.g. SO mentioned posthook.io), but if cost is your concern, then rolling out your own solution might be cheaper
j
Cool, thanks for the advice! The cronjob and just checking something everyday is a good idea! I think I may end up doing that. Allows me to also update that schedule by just updating a database/S3 record instead of having to cancel a step function and re-instate it. Posthook seems like it would solve the issue, although yea, cost-wise I think it might be cheaper to just roll my own solution.
m
Why is Step Functions expensive for this use case? You can have a Wait step that pauses for six months and pay nothing (but if I’m not mistaken this will count against the limit of 1 million open executions).
j
So my reasoning I guess was based on my previous experience with it. I believe it was charged per state change and then whatever cost it is for the Lambda as well. My previous use case did have a lot more step changes as it was an order/delivery service with multiple states. I guess I may have asked this question a bit too early as I haven't fully worked out the cost yet, but was more looking for alternatives as last time, the cost was considerably high compared to all the other services we had.
k
I haven't tried this, but wondering if you could alternatively set a TTL attribute for 6 months in the future on DynamoDB items that contained the user info, then process them in a lambda function within a stream
It should achieve the same effect as cron jobs and step functions and the main cost is for item storage... though if there aren't any material tradeoffs between the 3 from a cost or capability POV, I suppose it will come down to your level of familiarity with each service and speed to setup
a
Hmm actually TTL sounds like an interesting approach for automating this a bit. Might try this
r
Be aware that TTL removals can take up to 48 hours according to the docs
a
Good point, nevermind then lol
But still a cool functionality
k
Ahh wasn't aware of the 48 hr lag, helpful bite @Ross Coundon
j
Ah damn, yea if it wasn't for the 48 hr lag, that would actually be pretty cool too!
k
For sure! Might need to find myself an excuse to try it out 😃