Package 'build-essential' has no installation candidate while build AWS AMI image

I build an AMI image with packer and the build fails due to some packages (including build-essential) on Ubuntu 18.04 LTS are not found. But if I sleep while build and ssh into the instance created by packer I’m able to apt install build-essential.

Have I missed something? What could be the reason?

This was Ubuntu related issue. That’s solved by twice apt-get update in a row.