我正在 AWS 上工作,我们有运行 SSM 客户端的实例。为了实现自动化,我不时向这些实例传递某些命令。目前,我已经使用实例 ID 设置了它们。事实证明,这对我们来说不灵活,因为对实例 ID 的任何更改都将迫使我更新存储库代码,而且它是一个硬编码值。
如何用 tag:Name 或类似内容替换 instance-id。
当前代码:
aws ssm send-command --instance-ids 'i-12434546' --region 'eu-central-1' --document-name 'AWS-RunShellScript' --comment 'Restart Pod' --parameters commands='sudo -u ubuntu kubectl rollout restart deployment.v1.apps/supplier-service-deployment' --output text
我要更换
--instance-ids 'i-12434546'
带有标签:名称。你能帮忙的话,我会很高兴。谢谢。 :-)
最佳答案
您的问题的答案直接在文档页面 ( https://docs.aws.amazon.com/cli/latest/reference/ssm/send-command.html ) 上提供
To target a larger number of instances, or if you prefer not to list individual instance IDs, we recommend using the Targets option instead. Using Targets , which accepts tag key-value pairs to identify the instances to send commands to, you can a send command to tens, hundreds, or thousands of instances at once.
您可以使用 --targets
选项代替 --instance-ids
:
aws ssm send-command \
--targets Key=tag:tag-name,Values=tag-value \
[...]
关于amazon-web-services - AWS SSM : Pass tag-name instead of Instance-ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64764638/