Build It. Break It. Learn It. How 17 AWS Failures Made Me a Better Cloud Engineer
A honest walkthrough of building a production event-driven microservices platform from scratch using ECS Fargate, EventBridge, SQS, SNS, Terraform, and GitHub Actions OIDC. No templates, no shortcuts, just real failures across infrastructure, CI/CD, networking, and application logic, and exactly how each one was fixed. Built so you can learn from the mistakes before you make them.
An empty folder and a decision
I started OrderFlow with no template, no starter kit, and no tutorial open in another tab. Just the AWS docs and a folder called
orderflow-aws . The goal was to build a production-grade event-driven microservices platform on AWS, three Flask services running on ECS Fargate, wired together through EventBridge, SQS, and SNS, provisioned entirely with Terraform, deployed through GitHub Actions with OIDC.I hit 17 distinct failures before it worked.
This article covers what I built, why I made each architecture decision, and specifically what broke, so you can build something like this yourself and spend less time staring at empty SQS queues wondering what went wrong.
The architecture
Three microservices sit behind an Application Load Balancer. The order-service accepts incoming orders. When an order arrives, it fires an
order.created event to EventBridge. That event hits a rule with two targets: an SQS queue for inventory processing, and an SNS topic that fans out to a second SQS queue for notifications. The inventory-service and notification-service each poll their respective queues independently.
The entire infrastructure, VPC, subnets, ECS cluster, ALB, ECR, SQS queues, SNS topic, EventBridge rules, CloudWatch alarms, X-Ray tracing, lives in modular Terraform. No resource was created through the console.
Why EventBridge, SQS, and SNS, and not just one of them
This is worth understanding before you touch any code, because most people just copy a diagram without knowing why each service is there.
EventBridge is an event router. It receives events, matches them against rules, and sends them to targets. It does not queue anything. Use it when you want to decouple the thing that fires an event from everything that reacts to it, and when you might add new consumers later without touching the producer.
SQS is a queue. Messages sit there until a consumer pulls them. If your inventory service goes down for ten minutes, the messages wait. Nothing is lost. Use SQS when the consumer needs guaranteed delivery and you want to control the processing rate.
SNS is a fan-out mechanism. One message published to an SNS topic gets copied to every subscriber simultaneously. Use it when multiple consumers need the same event and you do not want to manage that routing yourself.
In OrderFlow, the three work together. The order-service fires one event to EventBridge. EventBridge routes it to two targets, SQS directly for inventory, and SNS for notifications which fans out to its own SQS queue. If I wanted to add an analytics service later, I would add one more SNS subscriber and the order-service code would not change at all. That is the whole point of this architecture.
Now here is everything that broke.
What actually went wrong
The event that disappeared into nothing
The first real failure was the most confusing. I fired an
order.created event, the API call returned success, and nothing arrived in SQS. The queue sat empty. No errors anywhere.The problem was a one-word mismatch. The EventBridge rule was filtering on source
"orderflow" but the application was sending source "orderflow.order-service" . EventBridge pattern matching is exact, if the source string does not match the rule precisely, the event arrives at the bus, matches nothing, and gets silently dropped. No error, no log, nothing.Before you write a single line of application code, test your EventBridge rule directly from the AWS CLI by manually sending a test event with the exact source and detail-type values your rule expects. If that works, then add the application layer. Testing them together from the start means you cannot tell which side is broken.
The SQS messages that kept coming back
Messages were arriving in the inventory queue, getting processed, and then reappearing a few minutes later and getting processed again. The same order was being handled twice, three times, indefinitely.
This is an SQS visibility timeout issue and it catches almost everyone the first time. When a consumer reads a message from SQS, the message does not disappear, it becomes temporarily invisible to other consumers. If you do not explicitly delete the message after processing it, the visibility window expires and SQS puts it back in the queue as if it was never touched.
The fix is conceptually simple: after you successfully process a message, delete it from the queue using the receipt handle that SQS gave you when you read it. If you skip that delete call, you get infinite reprocessing. This is by design, SQS assumes failure until you prove success by deleting the message.
The dead-letter queue that told me nothing
After sorting the delete issue, messages started going to the dead-letter queue after three failed retries. The notification-service was failing silently on every message. No logs, no errors, just a growing DLQ.
The root cause was the service crashing on a malformed JSON payload with no error handling around it. The exception was swallowed, the message was never acknowledged, SQS retried it three times, and then sent it to the DLQ. From the outside it looked like the messages were just disappearing.
Two lessons from this. First, wrap every message handler in proper error handling and log the raw message body on failure, before you try to parse or process anything. Second, your DLQ is not a trash can, it is a debugging tool. Check it regularly during development. Every message in there is a failure with a story.
ALB health checks that refused to pass
All three ECS services were running. All three target groups showed unhealthy. The ALB was returning 503 on every request.
The ALB health check path was set to
/ by default. The Flask services had their health endpoint at /health . The ALB was polling / every 30 seconds, getting a 404, and marking the targets unhealthy. Services were being deregistered before they ever received real traffic.This is the kind of thing that takes an embarrassing amount of time to find because the services look completely fine in ECS, running, no crashes but the ALB disagrees. Always explicitly set the health check path in your Terraform target group to match whatever endpoint your application actually exposes. Do not rely on defaults.
ECS tasks that crashed immediately on startup
Exit code 1 at launch. Tasks were starting, running for about three seconds, and dying. No useful logs in CloudWatch because the container was not alive long enough to emit any.
The environment variables were not being injected correctly. The applications were trying to read configuration like SQS queue URLs from environment variables at startup, the variables were not there, and the app crashed before it could initialize. The Terraform task definition had the environment block but the variable names did not match what the code expected.
The lesson is not subtle: run your application locally with the exact same environment variables it will have in ECS before you deploy. If it crashes locally with a missing variable, it will crash in ECS. ECS just makes it harder to see because the container is gone before the logs appear.
The OIDC trust policy that rejected GitHub
GitHub Actions could not assume the IAM role. The error was a straight authorization failure on
sts:AssumeRoleWithWebIdentity .The trust policy condition was too restrictive. It was specifying an exact branch and repository combination that did not match the workflow actually running. OIDC trust policies use a
sub condition that encodes the repository, branch, and sometimes environment, if any part of that string does not match exactly, the role refuses the request.When you set this up, verify the exact
sub value that GitHub is sending by checking the OIDC token claims first, then write your trust policy condition to match it. The AWS docs show an example condition, read it carefully, because the format matters and a wrong value gives you no useful error message.Docker builds that worked locally and broke in CI
The Docker build step was failing in GitHub Actions with a dependency resolution error that never appeared locally.
A Python package in
requirements.txt had no pinned version. Locally, pip resolved it to a version that had been cached. In the clean CI environment, pip resolved it to the latest version, which had a different API. The build failed.Pin every dependency version in
requirements.txt . Not approximately but exactly. A requirements file with unpinned versions is a build that works today and randomly breaks next Tuesday when a maintainer pushes a new release.Services that could not talk to each other
The order-service was trying to call the inventory-service internally and the requests were timing out.
The services were using the public ALB DNS name to reach each other, which meant traffic was going out through the internet and back in. The security group rules were not configured for that path and the requests were being dropped.
For a project at this scale, the simplest fix is to route inter-service calls through the ALB and make sure your security groups explicitly allow ALB-to-ECS traffic on the correct ports. For production systems you would use AWS Cloud Map for service discovery or App Mesh, but do not add that complexity until you need it.
The Terraform state lock that would not release
Terraform hung on
terraform apply with a state lock error. A previous run had not exited cleanly and left the lock entry in DynamoDB.Terraform uses a DynamoDB table to prevent two applies from running simultaneously, a sensible safety mechanism that becomes annoying when it gets stuck. The fix is to go into DynamoDB, find the lock table, and manually delete the lock item. Then your next apply will proceed normally.
The broader lesson: when Terraform exits uncleanly, always check the state before running anything again. A partial apply that left some resources created and some not is harder to recover from than a stuck lock.
The part nobody talks about: building from first principles
Every error above came from reading AWS documentation and figuring out what went wrong rather than following a tutorial that had already solved it. That is slower. It is also the only way to actually understand what you are building.
When you copy a working example you learn the shape of the solution. When you read the docs, hit the error, understand why it happened, and fix it yourself, you learn the system. The difference shows up the moment something breaks in production and there is no tutorial to reference.
OrderFlow cost roughly $22–25/month to run with all resources live. The full source code and Terraform modules are on GitHub at github.com/aboodi679/orderflow-aws. Clone it, break it, fix it. That is the point.
Enjoyed reading this content? Let the author know!
Your likes, comments, shares, and saves help creators reach more builders.
Loading recommendations
Loading article