Solve: Diagnose Broken TGW Attachments in AWS with One Shell Script
Sometimes the best tools aren’t
born in a lab. They’re born in the wild—when a smart cloud engineer runs into
something weird, digs deep, and asks the right questions.
That’s what happened this week when a developer noticed that their Transit Gateway (TGW) attachment was stuck in a pendingAcceptance state, but there was no way to accept it. Stranger still, the TGW route table linked to that attachment appeared to have been deleted, even though old attachments still referenced it.
After some careful CLI digging, the root cause became clear: the TGW route table had been owned by a central network account. When that table was deleted—without corresponding cleanup in the spoke account—the attachments became stranded. Adding to the confusion, the service-linked role for TGW had also been considered for deletion, which could have made matters worse.
So we built a tool: tgw_check.sh. It’s a guided CLI diagnostic utility designed to help cloud engineers trace TGW attachment issues step by step—with safe commands, clear output, and session logging.
That’s what happened this week when a developer noticed that their Transit Gateway (TGW) attachment was stuck in a pendingAcceptance state, but there was no way to accept it. Stranger still, the TGW route table linked to that attachment appeared to have been deleted, even though old attachments still referenced it.
After some careful CLI digging, the root cause became clear: the TGW route table had been owned by a central network account. When that table was deleted—without corresponding cleanup in the spoke account—the attachments became stranded. Adding to the confusion, the service-linked role for TGW had also been considered for deletion, which could have made matters worse.
So we built a tool: tgw_check.sh. It’s a guided CLI diagnostic utility designed to help cloud engineers trace TGW attachment issues step by step—with safe commands, clear output, and session logging.
What the Tool Does
This simple shell script walks through five core diagnostics:
- Check TGW ownership
- List TGW route tables (see if one’s missing or deleted)
- Inspect TGW attachments and find pendingAcceptance cases
- Create and associate a new route table
- Run all diagnostics and log everything to a timestamped file
Let’s look at what each step returns—simulated for clarity.
Step 1: Check TGW Ownership
Step 2: List TGW Route
Tables
Step 3: Inspect TGW Attachments
Step 4: Create and Associate a New Route Table
Step 5: Run Full Diagnostic
Everything in one go—with a clean, timestamped log you can copy
into Slack, attach to a ticket, or paste in an re:Post question.
Why We Built This
Not every engineer has full visibility across multiple AWS accounts. That’s especially true in larger orgs where infrastructure is centrally managed, but development work is happening in spoke accounts.
This tool gives engineers a simple way to answer the big questions quickly:
- Who owns this TGW?
- What happened to my route table?
- Why is this attachment stuck?
Try the Tool + See the Code
The full tgw_check.sh script is available in this Gist:
👉 Gist: tgw_check Diagnostic Tool
More background on the TGW bug that inspired this tool is here:
👉 Original Blog Post: Solve: When Your Transit Gateway Attachment Stalls
We hope this helps you or someone on your team avoid hours of blind debugging. If you spot something to add, please let us know in a comment on the Gist.
Need AWS Expertise?
We'd love to help you with your AWS projects. Feel free to reach out to us at info@pacificw.com.
Written by Aaron Rose, software engineer and technology writer at Tech-Reader.blog.
Comments
Post a Comment