将 ModifyTargetGroup 与 CLI 配合使用 - AWS SDK 代码示例

AWS 文档 SDK 示例 GitHub 存储库中还有更多 AWS SDK 示例。

ModifyTargetGroup 与 CLI 配合使用

以下代码示例演示如何使用 ModifyTargetGroup

CLI
AWS CLI

修改目标组的运行状况检查配置

以下 modify-target-group 示例更改用于评估指定目标组的目标运行状况的运行状况检查的配置。请注意,由于 CLI 解析逗号的方式不同,您必须用单引号(而不是双引号)将 --matcher 选项的范围引起来。

aws elbv2 modify-target-group \ --target-group-arn arn:aws:elasticloadbalancing:us-west-2:123456789012:targetgroup/my-https-targets/2453ed029918f21f \ --health-check-protocol HTTPS \ --health-check-port 443 \ --matcher HttpCode='200,299'

输出:

{ "TargetGroups": [ { "TargetGroupArn": "arn:aws:elasticloadbalancing:us-west-2:123456789012:targetgroup/my-https-targets/2453ed029918f21f", "TargetGroupName": "my-https-targets", "Protocol": "HTTPS", "Port": 443, "VpcId": "vpc-3ac0fb5f", "HealthCheckProtocol": "HTTPS", "HealthCheckPort": "443", "HealthCheckEnabled": true, "HealthCheckIntervalSeconds": 30, "HealthCheckTimeoutSeconds": 5, "HealthyThresholdCount": 5, "UnhealthyThresholdCount": 2, "Matcher": { "HttpCode": "200,299" }, "LoadBalancerArns": [ "arn:aws:elasticloadbalancing:us-west-2:123456789012:loadbalancer/app/my-load-balancer/50dc6c495c0c9188" ], "TargetType": "instance", "ProtocolVersion": "HTTP1", "IpAddressType": "ipv4" } ] }

有关更多信息,请参阅《应用程序负载均衡器指南》中的目标组

  • 有关 API 详细信息,请参阅《AWS CLI 命令参考》中的 ModifyTargetGroup

PowerShell
Tools for PowerShell V4

示例 1:此示例修改指定目标组的属性。

Edit-ELB2TargetGroup -TargetGroupArn 'arn:aws:elasticloadbalancing:us-east-1:123456789012:targetgroup/test-tg/a4e04b3688be1970' -HealthCheckIntervalSecond 60 -HealthCheckPath '/index.html' -HealthCheckPort 8080

输出

HealthCheckEnabled : True HealthCheckIntervalSeconds : 60 HealthCheckPath : /index.html HealthCheckPort : 8080 HealthCheckProtocol : HTTP HealthCheckTimeoutSeconds : 5 HealthyThresholdCount : 5 LoadBalancerArns : {} Matcher : Amazon.ElasticLoadBalancingV2.Model.Matcher Port : 80 Protocol : HTTP TargetGroupArn : arn:aws:elasticloadbalancing:us-east-1:123456789012:targetgroup/test-tg/a4e04b3688be1970 TargetGroupName : test-tg TargetType : instance UnhealthyThresholdCount : 2 VpcId : vpc-2cfd7000
  • 有关 API 详细信息,请参阅《AWS Tools for PowerShell Cmdlet Reference (V4)》中的 ModifyTargetGroup

Tools for PowerShell V5

示例 1:此示例修改指定目标组的属性。

Edit-ELB2TargetGroup -TargetGroupArn 'arn:aws:elasticloadbalancing:us-east-1:123456789012:targetgroup/test-tg/a4e04b3688be1970' -HealthCheckIntervalSecond 60 -HealthCheckPath '/index.html' -HealthCheckPort 8080

输出

HealthCheckEnabled : True HealthCheckIntervalSeconds : 60 HealthCheckPath : /index.html HealthCheckPort : 8080 HealthCheckProtocol : HTTP HealthCheckTimeoutSeconds : 5 HealthyThresholdCount : 5 LoadBalancerArns : {} Matcher : Amazon.ElasticLoadBalancingV2.Model.Matcher Port : 80 Protocol : HTTP TargetGroupArn : arn:aws:elasticloadbalancing:us-east-1:123456789012:targetgroup/test-tg/a4e04b3688be1970 TargetGroupName : test-tg TargetType : instance UnhealthyThresholdCount : 2 VpcId : vpc-2cfd7000
  • 有关 API 详细信息,请参阅《AWS Tools for PowerShell Cmdlet Reference (V5)》中的 ModifyTargetGroup