I might be looking at this wrong, but the hub looks like it's reporting 172.31.20.9 as its IP, but the node is trying to connect to the hub at
172.31.5.251
This might be due to the Fargate tasks's ENI having a dynamic IP, and each time you launch, it gets a new one. I got around this by having a custom route53 record that the hub writes its internal IP to once the selenium process comes up. That way, you can point the node to the DNS name of the hub and it will resolve its internal IP.
I add environment variables for this on top of the dockerfile that gets downloaded form the Docker Selenium Github, so the node always gets the current IP of the hub at run time. Here's what gets added: