amazon-web-services - AWS SSM : Pass tag-name instead of Instance-ID

标签 amazon-web-services aws-ssm

我正在 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/

相关文章:

hadoop - 你可以选择 boto3 s3 协议(protocol)吗?

amazon-web-services - 属性验证失败:YAML 中的 AWS::SSM::Parameter [属性值 {/Tags} 与类型 {Map} 不匹配]

aws-cloudformation - Cloudformation 条件以查看是否设置了 SSM 参数

amazon-web-services - 是否有类似于 AWS Systems Manager Session Manager 的 Azure 服务?

amazon-web-services - AWS : AccessDeniedException when calling ssm:GetParameterHistory on SSM Parameter

amazon-web-services - 使用 AWS CLI 指定 t2 实例 VPC

amazon-web-services - Cloudformation 中的循环依赖 |身份管理资源

python - 无法通过 Ansible 将 Cloud Formation 部署为 Jinja 模板

amazon-web-services - 引用 SAM 模板 (YAML) 中的元数据

amazon-web-services - 如果在 VPC 中,AWS 文件网关是否使用 S3 端点?