Halo Elastic Load Balancing - AWS SDKContoh Kode

Ada lebih banyak AWS SDK contoh yang tersedia di GitHub repo SDKContoh AWS Dokumen.

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

Halo Elastic Load Balancing

Contoh kode berikut menunjukkan cara memulai menggunakan Elastic Load Balancing.

Java
SDKuntuk Java 2.x
catatan

Ada lebih banyak tentang GitHub. Temukan contoh lengkapnya dan pelajari cara pengaturan dan menjalankannya di Repositori Contoh Kode AWS.

public class HelloLoadBalancer { public static void main(String[] args) { ElasticLoadBalancingV2Client loadBalancingV2Client = ElasticLoadBalancingV2Client.builder() .region(Region.US_EAST_1) .build(); DescribeLoadBalancersResponse loadBalancersResponse = loadBalancingV2Client .describeLoadBalancers(r -> r.pageSize(10)); List<LoadBalancer> loadBalancerList = loadBalancersResponse.loadBalancers(); for (LoadBalancer lb : loadBalancerList) System.out.println("Load Balancer DNS name = " + lb.dnsName()); } }
JavaScript
SDKuntuk JavaScript (v3)
catatan

Ada lebih banyak tentang GitHub. Temukan contoh lengkapnya dan pelajari cara pengaturan dan menjalankannya di Repositori Contoh Kode AWS.

import { ElasticLoadBalancingV2Client, DescribeLoadBalancersCommand, } from "@aws-sdk/client-elastic-load-balancing-v2"; export async function main() { const client = new ElasticLoadBalancingV2Client({}); const { LoadBalancers } = await client.send( new DescribeLoadBalancersCommand({}), ); const loadBalancersList = LoadBalancers.map( (lb) => `• ${lb.LoadBalancerName}: ${lb.DNSName}`, ).join("\n"); console.log( "Hello, Elastic Load Balancing! Let's list some of your load balancers:\n", loadBalancersList, ); } // Call function if run directly import { fileURLToPath } from "node:url"; if (process.argv[1] === fileURLToPath(import.meta.url)) { main(); }
Python
SDKuntuk Python (Boto3)
catatan

Ada lebih banyak tentang GitHub. Temukan contoh lengkapnya dan pelajari cara pengaturan dan menjalankannya di Repositori Contoh Kode AWS.

import boto3 def hello_elbv2(elbv2_client): """ Use the AWS SDK for Python (Boto3) to create an Elastic Load Balancing V2 client and list up to ten of the load balancers for your account. This example uses the default settings specified in your shared credentials and config files. :param elbv2_client: A Boto3 Elastic Load Balancing V2 client object. """ print("Hello, Elastic Load Balancing! Let's list some of your load balancers:") load_balancers = elbv2_client.describe_load_balancers(PageSize=10).get( "LoadBalancers", [] ) if load_balancers: for lb in load_balancers: print(f"\t{lb['LoadBalancerName']}: {lb['DNSName']}") else: print("Your account doesn't have any load balancers.") if __name__ == "__main__": hello_elbv2(boto3.client("elbv2"))