When building AI-powered apps, be very careful with cron jobs.
Today I wanted to make my AI Financial Agent send a daily morning email to all users by default (like traditional finance apps do).
The Problem: Traditional apps send static templates. My app uses Amazon Bedrock to generate custom text. If I loop through 500 inactive users and call Bedrock 500 times just to send emails they won't read, my AWS bill will explode. 💥
The Fix: I added a "FinOps" filter in my EventBridge orchestrator before it sends tasks to the SQS queue.
Before sending to SQS for AI processing, filter out the noise.
valid_users = []
for u in all_users:
wants_email = u.get('wants_daily_email', True) # Opt-out approach
is_test = str(u.get('user_id', '')).startswith('test_')
if wants_email and not is_test:
valid_users.append(u)
By filtering test_ accounts and respecting user Opt-Outs before the SQS queue, my AI worker Lambda only invokes Bedrock for users that actually matter. Code for engagement, architect for cost!

Top comments (0)