Creating Unique Hostnames for EC2 Instances in Elastic Beanstalk
By default, Elastic Beanstalk instances share the same hostname, which can be a pain for monitoring and debugging. Here’s how to give each instance a unique hostname using its instance ID.
Add this to .platform/hooks/prebuild/01_set_hostname.sh:
#!/bin/bashINSTANCE_ID=$(curl -s http://169.254.169.254/latest/meta-data/instance-id)sudo hostnamectl set-hostname "www.example.com-${INSTANCE_ID}"This grabs the instance ID from AWS’s metadata service and sets a unique hostname like www.example.com-i-1234567890abcdef0.