With Digital Ocean, I'm able to set a fully qualified domain name before starting it and I sorely miss this feature with AWS EC2.
Currently I manually go into a newly started Ubuntu 16.04 LTS instance and:
sudo hostnamectl set-hostname myhost.example.com
sudo vim /etc/hosts
and appendmyhost.example.com
to the127.0.0.1
line- Optionally goto Route 53 panel & set it up if I want it to resolve
- And then run the chef scripts.
Am I missing a trick? I can't see any Route 53 / EC2 integration either.
To just set the hostname (without Route53), you can use cloud-init configuration in the user-data
You can use the user-data function of the console and/or API to provide a bash script which will be executed on first boot. This script can set the hostname, create a DNS record, and any other actions you desire.
This is really a reply to hendry's comment that it would be nice to see an example of this kind of script, apparently I need more karma or something to add a comment.
I've just had to make this work so I can set the hostname of an EC2 instance and create a DNS record so I can then run rabbitmq on ECS on top of this using the host networking mode (which means the ECS task has the same networking and hostname as the underlying EC2 instance) so I can preserve the rabbitmq hostname through reboots of the underlying infra (and set kernel parameters which aren't show below)
This is my script, it works for me (I say that, but it's not fully tested yet. I'll report back)
To successfully run this the role the EC2 instances start with needs access to route53 to insert records into the private ZONE 'test' this is a security issue and should be mitigated in some way.
One of the caveats I learned whilst writing this is that when this script runs not all the ENV is set as you would expect. In particular HOME is not set, and thus you need to be explicit about paths. I chose to use /tmp but I guess /root might be preferable to some.
The loop round the hostname -f and the test to see it matches what we expect may well be redundant.