profile picture

@clementvial

I'm a full Stack JavaScript developer from Canada ðŸ‡¨ðŸ‡¦ Building with TypeScript, React, AI/ML & more.

Check out my links and posts

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/bash
INSTANCE_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.