ModifyRule 搭配 CLI 使用 - AWS SDK 程式碼範例

文件 AWS SDK AWS 範例 SDK 儲存庫中有更多可用的 GitHub 範例。

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

ModifyRule 搭配 CLI 使用

下列程式碼範例示範如何使用 ModifyRule

CLI
AWS CLI

若要修改規則

下列modify-rule範例會更新指定規則的動作和條件。

aws elbv2 modify-rule \ --actions Type=forward,TargetGroupArn=arn:aws:elasticloadbalancing:us-west-2:123456789012:targetgroup/my-targets/73e2d6bc24d8a067 \ --conditions Field=path-pattern,Values='/images/*' --rule-arn arn:aws:elasticloadbalancing:us-west-2:123456789012:listener-rule/app/my-load-balancer/50dc6c495c0c9188/f2f7dc8efc522ab2/9683b2d02a6cabee

輸出:

{ "Rules": [ { "Priority": "10", "Conditions": [ { "Field": "path-pattern", "Values": [ "/images/*" ] } ], "RuleArn": "arn:aws:elasticloadbalancing:us-west-2:123456789012:listener-rule/app/my-load-balancer/50dc6c495c0c9188/f2f7dc8efc522ab2/9683b2d02a6cabee", "IsDefault": false, "Actions": [ { "TargetGroupArn": "arn:aws:elasticloadbalancing:us-west-2:123456789012:targetgroup/my-targets/73e2d6bc24d8a067", "Type": "forward" } ] } ] }
  • 如需 API 詳細資訊,請參閱 AWS CLI 命令參考中的 ModifyRule

PowerShell
for PowerShell 工具

範例 1:此範例會修改指定的接聽程式規則組態。

$newRuleCondition = [Amazon.ElasticLoadBalancingV2.Model.RuleCondition]@{ "PathPatternConfig" = @{ "Values" = "/login1","/login2","/login3" } "Field" = "path-pattern" } Edit-ELB2Rule -RuleArn 'arn:aws:elasticloadbalancing:us-east-1:123456789012:listener-rule/app/testALB/3e2f03b558e19676/1c84f02aec143e80/f4f51dfaa033a8cc' -Condition $newRuleCondition

輸出:

Actions : {Amazon.ElasticLoadBalancingV2.Model.Action} Conditions : {Amazon.ElasticLoadBalancingV2.Model.RuleCondition} IsDefault : False Priority : 10 RuleArn : arn:aws:elasticloadbalancing:us-east-1:123456789012:listener-rule/app/testALB/3e2f03b558e19676/1c84f02aec143e80/f4f51dfaa033a8cc
  • 如需 API 詳細資訊,請參閱 AWS Tools for PowerShell Cmdlet 參考中的 ModifyRule