DEV Community

Cover image for Day 83: AWS SNS SMS Alerts & Segment Cost Optimization
Eric Rodríguez
Eric Rodríguez

Posted on

Day 83: AWS SNS SMS Alerts & Segment Cost Optimization

Adding SMS alerts to your serverless application is incredibly easy with AWS SNS. Keeping those alerts cheap, however, requires a bit of FinOps knowledge.

Today, I restored the SMS alerting feature for my Serverless Financial Agent. If a user spends more than 100€ in a day, the system sends them a harsh financial reality check via text.

Here are the critical architectural updates I made to secure the pipeline and optimize costs:

The ASCII-Only Rule
Initially, the AI included emojis in the SMS text. This was a costly mistake. Emojis force the message into UCS-2 encoding, shrinking the SMS segment limit from 160 characters to just 70. By refactoring the Python logic to use ASCII-only rotating phrases, I avoided multi-segment billing charges entirely.

Strict IAM Policies
I removed any broad SNS permissions from the Lambda execution role. Instead, I attached a granular inline policy: FinanceAgentSmsPublish. This ensures the Lambda only has the sns:Publish action allowed.

Account-Level Guardrails
AWS SNS can get expensive if a bug causes an infinite loop of messages. I configured the SNS MonthlySpendLimit attribute to a strict $1 limit while operating in the SNS Sandbox environment.

The Lesson: When writing cloud-native code, you must treat your cloud bill as an architectural constraint. Optimize your payload encoding and always lock down your IAM roles.

Top comments (0)