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

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

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

DescribeLoadBalancers 搭配 CLI 使用

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

CLI
AWS CLI

描述您的負載平衡器

此範例說明所有負載平衡器。

命令:

aws elb describe-load-balancers

描述其中一個負載平衡器

此範例說明指定的負載平衡器。

命令:

aws elb describe-load-balancers --load-balancer-name my-load-balancer

下列回應範例適用於 HTTPS 中的 VPC 負載平衡器。

輸出:

{ "LoadBalancerDescriptions": [ { "Subnets": [ "subnet-15aaab61" ], "CanonicalHostedZoneNameID": "Z3DZXE0EXAMPLE", "CanonicalHostedZoneName": "my-load-balancer-1234567890.us-west-2.elb.amazonaws.com", "ListenerDescriptions": [ { "Listener": { "InstancePort": 80, "LoadBalancerPort": 80, "Protocol": "HTTP", "InstanceProtocol": "HTTP" }, "PolicyNames": [] }, { "Listener": { "InstancePort": 443, "SSLCertificateId": "arn:aws:iam::123456789012:server-certificate/my-server-cert", "LoadBalancerPort": 443, "Protocol": "HTTPS", "InstanceProtocol": "HTTPS" }, "PolicyNames": [ "ELBSecurityPolicy-2015-03" ] } ], "HealthCheck": { "HealthyThreshold": 2, "Interval": 30, "Target": "HTTP:80/png", "Timeout": 3, "UnhealthyThreshold": 2 }, "VPCId": "vpc-a01106c2", "BackendServerDescriptions": [ { "InstancePort": 80, "PolicyNames": [ "my-ProxyProtocol-policy" ] } ], "Instances": [ { "InstanceId": "i-207d9717" }, { "InstanceId": "i-afefb49b" } ], "DNSName": "my-load-balancer-1234567890.us-west-2.elb.amazonaws.com", "SecurityGroups": [ "sg-a61988c3" ], "Policies": { "LBCookieStickinessPolicies": [ { "PolicyName": "my-duration-cookie-policy", "CookieExpirationPeriod": 60 } ], "AppCookieStickinessPolicies": [], "OtherPolicies": [ "my-PublicKey-policy", "my-authentication-policy", "my-SSLNegotiation-policy", "my-ProxyProtocol-policy", "ELBSecurityPolicy-2015-03" ] }, "LoadBalancerName": "my-load-balancer", "CreatedTime": "2015-03-19T03:24:02.650Z", "AvailabilityZones": [ "us-west-2a" ], "Scheme": "internet-facing", "SourceSecurityGroup": { "OwnerAlias": "123456789012", "GroupName": "my-elb-sg" } } ] }
PowerShell
for PowerShell 工具

範例 1:此範例會列出負載平衡器的名稱。

Get-ELBLoadBalancer | format-table -property LoadBalancerName

輸出:

LoadBalancerName ---------------- my-load-balancer my-other-load-balancer my-internal-load-balancer

範例 2:此範例說明指定的負載平衡器。

Get-ELBLoadBalancer -LoadBalancerName my-load-balancer

輸出:

AvailabilityZones : {us-west-2a, us-west-2b} BackendServerDescriptions : {Amazon.ElasticLoadBalancing.Model.BackendServerDescription} CanonicalHostedZoneName : my-load-balancer-1234567890.us-west-2.elb.amazonaws.com CanonicalHostedZoneNameID : Z3DZXE0EXAMPLE CreatedTime : 4/11/2015 12:12:45 PM DNSName : my-load-balancer-1234567890.us-west-2.elb.amazonaws.com HealthCheck : Amazon.ElasticLoadBalancing.Model.HealthCheck Instances : {i-207d9717, i-afefb49b} ListenerDescriptions : {Amazon.ElasticLoadBalancing.Model.ListenerDescription} LoadBalancerName : my-load-balancer Policies : Amazon.ElasticLoadBalancing.Model.Policies Scheme : internet-facing SecurityGroups : {sg-a61988c3} SourceSecurityGroup : Amazon.ElasticLoadBalancing.Model.SourceSecurityGroup Subnets : {subnet-15aaab61} VPCId : vpc-a01106c2

範例 3:此範例說明目前 AWS 區域中的所有負載平衡器。

Get-ELBLoadBalancer

範例 4:此範例說明所有可用負載平衡器的所有負載平衡器 AWS 區域。

Get-AWSRegion | % { Get-ELBLoadBalancer -Region $_ }
  • 如需 API 詳細資訊,請參閱 AWS Tools for PowerShell Cmdlet 參考中的 DescribeLoadBalancers