There are more AWS SDK examples available in the AWS Doc SDK Examples
Use ModifyLoadBalancerAttributes with a CLI
The following code examples show how to use ModifyLoadBalancerAttributes.
- CLI
-
- AWS CLI
-
Example 1: To enable deletion protection
The following
modify-load-balancer-attributesexample enables deletion protection for the specified load balancer.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=trueOutput:
{ "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" } ] }For more information, see Edit attributes for your Application Load Balancer in the Application Load Balancers Guide.
Example 2: To change the idle timeout
The following
modify-load-balancer-attributesexample changes the idle timeout value for the specified load balancer.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=30Output:
{ "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" } ] }For more information, see Edit attributes for your Application Load Balancer in the Application Load Balancers Guide.
Example 3: To enable access logs
The following
modify-load-balancer-attributesexample enables access logs for the specified load balancer. Note that the S3 bucket must exist in the same region as the load balancer and must have a policy attached that grants access to the Elastic Load Balancing service.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=myappOutput:
{ "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" } ] }For more information, see Access logs for your Application Load Balancer in the Application Load Balancers Guide.
-
For API details, see ModifyLoadBalancerAttributes
in AWS CLI Command Reference.
-
- PowerShell
-
- Tools for PowerShell V4
-
Example 1: This example modifes the Attributes of the specified load balancer.
Edit-ELB2LoadBalancerAttribute -LoadBalancerArn 'arn:aws:elasticloadbalancing:us-east-1:123456789012:loadbalancer/app/test-alb/3651b4394dd9a24f' -Attribute @{Key = 'deletion_protection.enabled'; Value = 'true'}Output:
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-
For API details, see ModifyLoadBalancerAttributes in AWS Tools for PowerShell Cmdlet Reference (V4).
-
- Tools for PowerShell V5
-
Example 1: This example modifes the Attributes of the specified load balancer.
Edit-ELB2LoadBalancerAttribute -LoadBalancerArn 'arn:aws:elasticloadbalancing:us-east-1:123456789012:loadbalancer/app/test-alb/3651b4394dd9a24f' -Attribute @{Key = 'deletion_protection.enabled'; Value = 'true'}Output:
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-
For API details, see ModifyLoadBalancerAttributes in AWS Tools for PowerShell Cmdlet Reference (V5).
-