'Preventing traffic going to a new ECS task while it still builds a NextJS static site

I have an AWS ECS task that runs a single container. Inside that container runs nginx, as well as a Next.js application.

My problem is that when I deploy, the ECS task spins up and is registered in the load balancer target group before Next.js has finished its "npm run build" command. This results in about 5 minutes of users getting a 502 error on the site, as traffic is going through to nginx and then to Next, which hasn't started yet and is still building.

Is there a way to manually tell ECS that this task should not be in "RUNNING" state until after the build process has completed?



Solution 1:[1]

I just realize that when using csv.DictReader, the function will automatedly treats the first line as the “keys” so there is no need to add next(reader). And after deleted that line, everything works out perfectly now.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1