If you run a serverless SaaS on AWS, create an account-wide log retention policy today, try it first with --dry-run, and check which log groups had a longer retention on purpose. Since 9 November 2026 it’s a single command, it costs nothing, and it stops depending on every new Lambda being configured properly.
The problem
Every Lambda function writes its logs to a CloudWatch Logs group called /aws/lambda/<function-name>. Unless someone says otherwise, that group keeps the data forever: the AWS documentation states that retention defaults to “Never Expire”.
With three functions you won’t notice. In a SaaS with dozens of functions, test environments and deployments that create new groups, log storage grows every month and nobody looks at it until it shows up on the bill. Until now there were two fixes: set retention group by group in your infrastructure as code, or run a script over every group now and then. Both depend on nobody forgetting.
What changed
AWS announced account-level retention policies on 9 November. The key points:
- A policy applies to every group in the account, or only to groups whose names start with a prefix such as
/aws/lambda. - You choose whether it also covers existing groups (
RETROACTIVE) or only new ones (NEW_ONLY). - You can have up to 20 policies per region.
- There is no additional charge.
- It takes 24 hours to apply, both when you create it and when you change it.
- The minimum retention for an account policy is 30 days.
- It’s available in all commercial regions except Middle East (Bahrain) and Middle East (UAE).
How to use it
1. Check the impact before applying anything. The same command with --dry-run tells you how many groups would get a longer, shorter or unchanged retention, and which 20 groups store the most data. It doesn’t create or change anything:
aws logs put-account-policy \
--policy-name LambdaRetentionPolicy \
--policy-type RETENTION_POLICY \
--policy-document '{"retentionInDays": 90, "enforcementMode": "RETROACTIVE"}' \
--selection-criteria 'LogGroupNamePrefix="/aws/lambda"' \
--dry-run
2. Apply it. Drop --dry-run and run it. retentionInDays only accepts a fixed list: 30, 60, 90, 120, 150, 180, 365, 400, 545, 731 and so on up to 3653 days, or NEVER_EXPIRE.
3. Check which policies you have.
aws logs describe-account-policies --policy-type RETENTION_POLICY
4. Grant only the permissions needed. Creating or updating a policy needs logs:PutAccountPolicy and logs:PutRetentionPolicy; deleting one needs logs:DeleteAccountPolicy and logs:DeleteRetentionPolicy.
The trap: the policy overrides the group
This is the part I care about most. An account policy replaces each group’s own retention, even when the group’s setting was longer. AWS gives the example plainly: if a group was set to keep events for 10 years and you create a 90-day policy that covers it, CloudWatch “deletes the log events in that log group that are older than 90 days”.
Think about which groups someone extended for a reason: audit, payment or access logs. If a 90-day RETROACTIVE policy with no prefix reaches them, a day later you’ve lost what had been kept for years. And deletion can’t be undone.
The rule for combining policies helps: when several apply to the same group, the longest retention wins, and NEVER_EXPIRE counts as the longest of all. So the safe pattern is a baseline for everything plus longer exceptions by prefix. AWS suggests something along those lines: 90 days for the account and one year for groups starting with /security.
My take
I would apply this to any account running Lambda before the week is out. It’s the kind of change I like: a decision you used to repeat in every function now gets made once, in one place. Infrastructure as code still handles the special cases, but the baseline no longer depends on every new template carrying its retentionInDays.
My order would be:
- List the groups with an explicit retention longer than the baseline and decide whether they still need it.
- Create the longer prefix policies for those cases first.
- Run the baseline with
--dry-run, read the result, and only then apply it.
As for the number, 90 days seems a reasonable baseline for application logs in a small SaaS: it covers an incident you spot late without keeping years of noise. But the right number depends on your legal obligations and your customer contracts, not on a blog post. If you keep personal data in your logs, that’s a separate problem, and a retention policy won’t fix it.
What I don’t know yet is when infrastructure-as-code tools will catch up. In Terraform, as of 12 November, support sits in an open pull request on the AWS provider, not yet merged. Until then the CLI is enough: it’s one policy per account and region, not something you change every week.
Sources
- AWS What’s New: Amazon CloudWatch Logs announces account-level retention policies (9 November 2026)
- AWS documentation: Working with log groups and log streams
- Terraform AWS provider: pull request #50873, RETENTION_POLICY support
If you’re interested in how I build SaaS on AWS serverless without a team, follow me on LinkedIn.
