AWS SSM:传递标签名称而不是实例 ID

AWS SSM : Pass tag-name instead of Instance-ID

我在 AWS 上工作,我们有实例 运行 SSM 客户端。对于自动化,我不时将某些命令传递给这些实例。目前,我已经为它们设置了 instance-id。这对我们来说是不灵活的,因为对 instance-id 的任何更改都会迫使我更新存储库代码,而且它是一个硬编码值。

如何将实例 ID 替换为 tag:Name 或类似的。

当前代码:

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'

与tag:Name。你能帮忙的话,我会很高兴。谢谢你。 :-)

您问题的答案直接在文档页面上提供 (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 \
[...]