The issue with Cuba was the stationing of nuclear missiles in Cuba, not merely its membership of a pact with the USSR.
The US didn’t invade Cuba, it assisted Cuban exiles to do so in the embarrassing Bay of Pigs disaster which took place before the naval blockade as part of the Cuban Missile Crisis. Naturally, Bay of Pigs should never have happened, and it’s one of the things that led to the CIA’s powers and freedom from oversight being drastically curtailed the following decade.
Furthermore, the world and international law has moved on since the 1960s. That sort of brinkmanship has been much reduced.