Produce a CSV of running EC2 instances that are missing an `Owner` tag.
IntermediateScenarioScenarios: text processing and scheduling decisions
Answer
Situation read → Tags are an array of Key/Value pairs; test for the absence of one key.
What I'd do →
echo "region,instance_id,name,type,launch_time" > untagged.csv
for r in $(aws ec2 describe-regions --query 'Regions[].RegionName' --output text); do
aws ec2 describe-instances --region "$r" --filters Name=instance-state-name,Values=running --output json |
jq -r --arg r "$r" '.Reservations[].Instances[]
| select([.Tags[]? | .Key] | index("Owner") | not)
| [$r, .InstanceId, ((.Tags // []) | from_entries | .Name // ""), .InstanceType, .LaunchTime] | @csv' >> untagged.csv
done
from_entriesturns the Key/Value tag list into an object.@csvquotes fields correctly.
Why → Untagged resources have no owner to ask before cost cleanup or incident response.
Interview tip → Mention enforcing tags at creation with AWS Organizations tag policies or SCPs, rather than only reporting.
More on Scenarios: text processing and scheduling decisions
Users report errors in the last hour. From the Nginx access log, find which endpoints produce the most 5xx responses.BeginnerA MySQL slow log is 3 GB. You need the 10 slowest query patterns. What do you do?IntermediateTwo servers that should be identical behave differently. Compare their installed packages.BeginnerFind which pods were OOMKilled in a namespace, with their container names and restart counts.IntermediateYou have access logs from five web servers and need one timeline sorted by time. How?IntermediateA vendor needs application logs, but they contain emails and card numbers. Mask them first.Intermediate