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.

#!/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.

Advertisements

Software developer, stand-up comedian, musician, writer, jolly big cheer-monkey, skeptical thinker, Doctor Who fan, lover of fine sounds.

Tagged with:
Posted in Uncategorized

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s

%d bloggers like this: