aws ec2 describe-instances --query 'Reservations[*].Instances[*].[InstanceId, Tags[?Key==`Name` && starts_with(Value, `dev`)]]' --output json | jq -r '.[][] | select(.[1] | length > 0) | .[0]' | \
while read instance_id; do
aws ec2 create-tags --resources "$instance_id" --tags Key=Environment,Value=development
done
- jq used to filter out resources that have empty tags and only output the instance ID.