Reputation: 2534
This page in the docs describes how to set the hostname of an EC2 instance by logging in and running:
sudo hostnamectl set-hostname webserver.mydomain.com
sudo reboot
Is there a way to do this programmatically from outside the instance? I have multiple instances that I need to do this for and logging into each one is not possible.
I'm using Boto3 but can't find the right command.
Upvotes: 1
Views: 701
Reputation: 238309
Usually you would use AWS Systems Manager Run Command for such tasks:
AWS Systems Manager Run Command lets you remotely and securely manage the configuration of your managed instances. Run Command enables you to automate common administrative tasks and perform ad hoc configuration changes at scale.
This would require making your instances to be recognized by AWS Systems Manager (SSM) which requires three things:
AmazonSSMManagedInstanceCore
managed policyUpvotes: 2