Reputation: 175
I'm looking for a way in AWS to run automatic functions every month or so to update my MongoDB database. I built my API on top of the serverless framework.
What's the best bet to solve this problem? Say for instance a user buys a subscription today. In 30 days a function has to run in automatic and update the mongodb document and detract money from the account credit.
Upvotes: 1
Views: 90
Reputation: 852
I don't think there is a perfectly managed way to do this in AWS today.
A couple of options spring to mind. You could create a scheduled task to run from EventBridge to a Lambda every X period, maybe 1 hour in this case. This Lambda could evaluate if any customer's subscription payment should be taken.
Alternatively, you could write a record into DynamoDB with a TTL of the subscription period. You can then use DynamoDB streams to trigger a Lambda function when the record is removed by the TTL. There are caveats about this approach, it's not perfectly accurate.
Upvotes: 1