If you want a cool banner showing the machine ID on your Amazon linux box on EC2, then here is how I’ve achieved it. You’ll need to install “figlet” using
sudo yum install figlet -y
Then all you need to do is create the following script in /etc/update-motd.d with a name like 40-name – don’t forget to do a sudo chmod +x 40-name on it to make it executable.
#!/bin/sh # make this use your server's region export AWS_DEFAULT_REGION=eu-west-1 # read the instance id from the local http service EC2_INSTANCE_ID=$(curl http://169.254.169.254/latest/meta-data/instance-id) # query the aws ec2 tags to find the nice name you gave your server and cut it out of the json EC2_INSTANCE_NAME=$(aws ec2 describe-tags --filters Name=resource-id,Values=$EC2_INSTANCE_ID N ame=key,Values=Name | grep "Value" | cut -d'"' -f4) # add an ASCII name of your server to the motd figlet $EC2_INSTANCE_NAME
This assumes that you’ve given your server an IAM role such that it has access to EC2 – otherwise the aws ec2 command cannot run as it doesn’t have rights.