Cool Message of the day on Amazon Linux

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.


# make this use your server's region
export AWS_DEFAULT_REGION=eu-west-1

# read the instance id from the local http service

# 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

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.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s