I'm struggling to get to grips with Window functions (DDL and DML at end of post).
You never asked a question...
I suppose your actual problem is that
group_key,
sum(amount) over (...)
GROUP BY
group_key
Is giving you an error. This is expected. You must write that fragment
group_key,
sum(sum(amount)) over (...)
GROUP BY group_key
The window sum is not an aggregate from the perspective of group by. In the original you never aggregated "amount" nor was it part of the group by and thus an error. turning "amount" into the aggregate "sum(amount)" is one valid solution.