Gunakan ModifyLoadBalancerAttributes dengan CLI - AWS Contoh Kode SDK

Ada lebih banyak contoh AWS SDK yang tersedia di repo Contoh SDK AWS Doc. GitHub

Terjemahan disediakan oleh mesin penerjemah. Jika konten terjemahan yang diberikan bertentangan dengan versi bahasa Inggris aslinya, utamakan versi bahasa Inggris.

Gunakan ModifyLoadBalancerAttributes dengan CLI

Contoh kode berikut menunjukkan cara menggunakanModifyLoadBalancerAttributes.

CLI
AWS CLI

Untuk mengaktifkan perlindungan penghapusan

Contoh ini memungkinkan perlindungan penghapusan untuk penyeimbang beban yang ditentukan.

Perintah:

aws elbv2 modify-load-balancer-attributes --load-balancer-arn arn:aws:elasticloadbalancing:us-west-2:123456789012:loadbalancer/app/my-load-balancer/50dc6c495c0c9188 --attributes Key=deletion_protection.enabled,Value=true

Output:

{ "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" } ] }

Untuk mengubah batas waktu idle

Contoh ini mengubah nilai batas waktu idle untuk penyeimbang beban yang ditentukan.

Perintah:

aws elbv2 modify-load-balancer-attributes --load-balancer-arn arn:aws:elasticloadbalancing:us-west-2:123456789012:loadbalancer/app/my-load-balancer/50dc6c495c0c9188 --attributes Key=idle_timeout.timeout_seconds,Value=30

Output:

{ "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" } ] }

Untuk mengaktifkan log akses

Contoh ini memungkinkan log akses untuk penyeimbang beban yang ditentukan. Perhatikan bahwa bucket S3 harus berada di wilayah yang sama dengan penyeimbang beban dan harus memiliki kebijakan yang dilampirkan yang memberikan akses ke layanan Elastic Load Balancing.

Perintah:

aws elbv2 modify-load-balancer-attributes --load-balancer-arn arn:aws:elasticloadbalancing:us-west-2:123456789012:loadbalancer/app/my-load-balancer/50dc6c495c0c9188 --attributes Key=access_logs.s3.enabled,Value=true Key=access_logs.s3.bucket,Value=my-loadbalancer-logs Key=access_logs.s3.prefix,Value=myapp

Output:

{ "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" } ] }
PowerShell
Alat untuk PowerShell

Contoh 1: Contoh ini memodifikasi Atribut penyeimbang beban yang ditentukan.

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