The apt lock problem is underrated: on Debian/Ubuntu images, unattended-upgrades can hold the lock right at first boot, which is exactly when cloud-init wants it. The part I like here is that you traced it to timing rather than just retrying — retries hide the root cause until it bites at 3am.