Hostname on AWS CentOS 7 EC2

I was setting up a shiny new CentOS 7 EC2 instance, but when I tried to set the hostname using all of the typical Linux-y ways, none of them stuck after a reboot. It just kept going back to the default EC2 naming convention of ‘ip-172.31.x.x’. Since I am still getting used to CentOS 7 and all of the stuff they changed from 6, I figured it was a CentOS 7 thing. Not so…

Turns out it was due to the EC2 instance being provisioned with cloud-init which AWS uses to configure the AMIs. First I headed over to the cloud-init docs to see what I could glean from RTFM. Meh, pretty useless. So after some searching I came across AWS’ documentation and a few posts that outlined someexamples of parameters to change in the cloud-init configuration. So for me, the config that worked was the following: