简体   繁体   English

如何以编程方式(从实例外部)设置 EC2 主机名?

[英]How to set EC2 hostname programmatically (from outside the instance)?

This page in the docs describes how to set the hostname of an EC2 instance by logging in and running:文档中的此页面描述了如何通过登录并运行来设置 EC2 实例的主机名:

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.我正在使用 Boto3,但找不到正确的命令。

Usually you would use AWS Systems Manager Run Command for such tasks:通常,您会使用AWS Systems Manager Run Command执行此类任务:

AWS Systems Manager Run Command lets you remotely and securely manage the configuration of your managed instances. AWS Systems Manager Run Command 让您可以远程安全地管理托管实例的配置。 Run Command enables you to automate common administrative tasks and perform ad hoc configuration changes at scale. Run Command 使您能够自动执行常见的管理任务并大规模执行临时配置更改。

This would require making your instances to be recognized by AWS Systems Manager (SSM) which requires three things:这需要让 AWS Systems Manager (SSM) 识别您的实例,这需要三件事:

  • network connectivity to SSM service. SSM 服务的网络连接。
  • SSM Agent installed and running - common official AMI (ubuntu, amazon linux, ...) already have it running and setup.已安装并运行 SSM 代理 - 常见的官方 AMI(ubuntu、amazon linux 等)已经运行并设置了它。
  • instance role with AmazonSSMManagedInstanceCore managed policy具有AmazonSSMManagedInstanceCore托管策略的实例角色

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM