Introduction: Trust Nothing, Verify Everything
One of the most powerful chapters in The Pragmatic Programmer is "Pragmatic Paranoia." You can't write perfect software, so stop trying. Code defensively. Don't trust the code and data of others, nor your own.
In the cloud, this matters more. Your AWS infrastructure depends on networks, APIs, IAM policies, and third-party services. Assume something breaks—because it will.
Here are five pragmatic-paranoia principles applied to AWS.
1. Design by Contract: Make Assumptions Explicit
The book defines Design by Contract as specifying preconditions, postconditions, and invariants. On AWS:
Contract Type | AWS Implementation |
|---|
Preconditions | IAM policies that define who can call what, and when |
Postconditions | CloudWatch alarms that verify expected outcomes |
Invariants | Service Control Policies (SCPs) that enforce non-negotiable rules |
Example: Before a Lambda function writes to DynamoDB, validate the input schema and IAM permissions. Fail fast and clearly. "Dead programs tell no lies."
2. Crash Early: Fail Loudly, Fail Fast
Check things that "cannot happen" and crash if they do. In AWS:
- Use Dead Letter Queues (DLQs) for SQS and EventBridge so failed events don't vanish.
- Set CloudWatch alarms for error rates, not just CPU.
- Log everything—CloudTrail for APIs, VPC Flow Logs for network, application logs in CloudWatch.
Anti-pattern: Silently catching exceptions and logging vague messages. "Don't discard useful error context."
3. Assertive Programming: Validate Assumptions
"Use assertions to ensure that what can't happen, won't happen." On AWS:
- CloudFormation drift detection—alerts when resources change outside IaC.
- AWS Config rules—enforce policies like "S3 buckets must be private."
- Canary deployments—test new versions with a small traffic slice before full rollout.
"Prove your assumptions in the actual environment—with real data."
4. Resource Management: Finish What You Start
The routine that allocates a resource should deallocate it. In AWS:
Resource | Pragmatic Approach |
|---|
EC2 Instances | Auto Scaling Groups with lifecycle hooks |
S3 Temp Files | Lifecycle policies to delete after X days |
RDS Snapshots | Automated retention and expiration |
Lambda Contexts | Clean up external connections in code |
VPC Resources | Use ephemeral environments ( cdk destroy ) |
Can't clean up immediately? Put the resource in a container (like S3 lifecycle) that handles it.
5. Programming by Coincidence: Know Why It Works
"To make sure your program works tomorrow, you must understand why it works today."
Watch out for:
- Copy-pasting IAM policies without understanding each permission.
- Using templates from the internet without full comprehension.
- Manual production fixes instead of updating IaC.
- Using
* in IAM policies because "it was easier."
Instead:
- Document the why behind decisions—including trade-offs.
- Review infrastructure code like application code.
- Run drift detection to catch manual changes.
"Don't rely on anything you need not rely on."
Bonus: The Broken Window Effect
One unrepaired "temporary" fix—an open security group, a public S3 bucket, an unpatched AMI—signals that quality doesn't matter. Others follow.
What to do:
- Always treat infrastructure as code. No exceptions.
- Enforce guardrails with SCPs and Config Rules.
- Leave the infrastructure cleaner than you found it.
Conclusion: Defensive Cloud Architecture
Pragmatic paranoia prepares you for the worst. Assume networks fail, permissions misconfigure, and bugs happen. Build systems that survive.
"The best way to start fixing a bug is to make it reproducible." On AWS, design for failure—and you'll be ready when it comes.
Loading article