Interview Prep/Shell Scripting/Scenarios: text processing and scheduling decisions

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
  1. from_entries turns the Key/Value tag list into an object.
  2. @csv quotes 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.

All Shell Scripting questions Roadmap: Shell scripting (Bash)

More on Scenarios: text processing and scheduling decisions