Rather than directly querying the EC2 metadata service, use https://github.com/adamchainz/ec2-metadata to do it. We'll need adamchainz/ec2-metadata#15 for this.