AWS 文档 SDK 示例
将 ModifyLoadBalancerAttributes 与 CLI 配合使用
以下代码示例演示如何使用 ModifyLoadBalancerAttributes。
- CLI
-
- AWS CLI
-
启用删除保护
此示例为指定负载均衡器启用删除保护。
命令:
aws elbv2 modify-load-balancer-attributes --load-balancer-arnarn:aws:elasticloadbalancing:us-west-2:123456789012:loadbalancer/app/my-load-balancer/50dc6c495c0c9188--attributesKey=deletion_protection.enabled,Value=true输出:
{ "Attributes": [ { "Value": "true", "Key": "deletion_protection.enabled" }, { "Value": "false", "Key": "access_logs.s3.enabled" }, { "Value": "60", "Key": "idle_timeout.timeout_seconds" }, { "Value": "", "Key": "access_logs.s3.prefix" }, { "Value": "", "Key": "access_logs.s3.bucket" } ] }更改空闲超时
此示例更改指定负载均衡器的空闲超时值。
命令:
aws elbv2 modify-load-balancer-attributes --load-balancer-arnarn:aws:elasticloadbalancing:us-west-2:123456789012:loadbalancer/app/my-load-balancer/50dc6c495c0c9188--attributesKey=idle_timeout.timeout_seconds,Value=30输出:
{ "Attributes": [ { "Value": "30", "Key": "idle_timeout.timeout_seconds" }, { "Value": "false", "Key": "access_logs.s3.enabled" }, { "Value": "", "Key": "access_logs.s3.prefix" }, { "Value": "true", "Key": "deletion_protection.enabled" }, { "Value": "", "Key": "access_logs.s3.bucket" } ] }启用访问日志
此示例为指定的负载均衡器启用访问日志。请注意,S3 存储桶必须与负载均衡器位于同一区域,并且必须附加一个授予对 Elastic Load Balancing 服务访问权限的策略。
命令:
aws elbv2 modify-load-balancer-attributes --load-balancer-arnarn:aws:elasticloadbalancing:us-west-2:123456789012:loadbalancer/app/my-load-balancer/50dc6c495c0c9188--attributesKey=access_logs.s3.enabled,Value=trueKey=access_logs.s3.bucket,Value=my-loadbalancer-logsKey=access_logs.s3.prefix,Value=myapp输出:
{ "Attributes": [ { "Value": "true", "Key": "access_logs.s3.enabled" }, { "Value": "my-load-balancer-logs", "Key": "access_logs.s3.bucket" }, { "Value": "myapp", "Key": "access_logs.s3.prefix" }, { "Value": "60", "Key": "idle_timeout.timeout_seconds" }, { "Value": "false", "Key": "deletion_protection.enabled" } ] }-
有关 API 详细信息,请参阅《AWS CLI 命令参考》中的 ModifyLoadBalancerAttributes
。
-
- PowerShell
-
- Tools for PowerShell V4
-
示例 1:此示例修改指定负载均衡器的属性。
Edit-ELB2LoadBalancerAttribute -LoadBalancerArn 'arn:aws:elasticloadbalancing:us-east-1:123456789012:loadbalancer/app/test-alb/3651b4394dd9a24f' -Attribute @{Key = 'deletion_protection.enabled'; Value = 'true'}输出:
Key Value --- ----- deletion_protection.enabled true access_logs.s3.enabled false access_logs.s3.bucket access_logs.s3.prefix idle_timeout.timeout_seconds 60 routing.http2.enabled true routing.http.drop_invalid_header_fields.enabled false-
有关 API 详细信息,请参阅《AWS Tools for PowerShell Cmdlet Reference (V4)》中的 ModifyLoadBalancerAttributes。
-
- Tools for PowerShell V5
-
示例 1:此示例修改指定负载均衡器的属性。
Edit-ELB2LoadBalancerAttribute -LoadBalancerArn 'arn:aws:elasticloadbalancing:us-east-1:123456789012:loadbalancer/app/test-alb/3651b4394dd9a24f' -Attribute @{Key = 'deletion_protection.enabled'; Value = 'true'}输出:
Key Value --- ----- deletion_protection.enabled true access_logs.s3.enabled false access_logs.s3.bucket access_logs.s3.prefix idle_timeout.timeout_seconds 60 routing.http2.enabled true routing.http.drop_invalid_header_fields.enabled false-
有关 API 详细信息,请参阅《AWS Tools for PowerShell Cmdlet Reference (V5)》中的 ModifyLoadBalancerAttributes。
-
ModifyListener
ModifyRule