Contoh kode untuk Amazon Redshift menggunakan AWS SDKs - 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.

Contoh kode untuk Amazon Redshift menggunakan AWS SDKs

Contoh kode berikut menunjukkan cara menggunakan Amazon Redshift dengan kit pengembangan AWS perangkat lunak ()SDK.

Tindakan adalah kutipan kode dari program yang lebih besar dan harus dijalankan dalam konteks. Meskipun tindakan menunjukkan cara memanggil fungsi layanan individual, Anda dapat melihat tindakan dalam konteks pada skenario terkait dan contoh lintas layanan.

Skenario adalah contoh kode yang menunjukkan cara menyelesaikan tugas tertentu dengan memanggil beberapa fungsi dalam layanan yang sama.

Contoh lintas layanan adalah contoh aplikasi yang bekerja di beberapa AWS layanan.

Sumber daya lainnya

Memulai

Contoh kode berikut menunjukkan cara memulai menggunakan Amazon Redshift.

Java
SDKuntuk Java 2.x
catatan

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

import software.amazon.awssdk.regions.Region; import software.amazon.awssdk.services.redshift.RedshiftClient; import software.amazon.awssdk.services.redshift.paginators.DescribeClustersIterable; /** * Before running this Java V2 code example, set up your development * environment, including your credentials. * * For more information, see the following documentation topic: * * https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/get-started.html */ public class HelloRedshift { public static void main(String[] args) { Region region = Region.US_EAST_1; RedshiftClient redshiftClient = RedshiftClient.builder() .region(region) .build(); listClustersPaginator(redshiftClient); } public static void listClustersPaginator(RedshiftClient redshiftClient) { DescribeClustersIterable clustersIterable = redshiftClient.describeClustersPaginator(); clustersIterable.stream() .flatMap(r -> r.clusters().stream()) .forEach(cluster -> System.out .println(" Cluster identifier: " + cluster.clusterIdentifier() + " status = " + cluster.clusterStatus())); } }
  • Untuk API detailnya, lihat describeClustersdi AWS SDK for Java 2.x APIReferensi.

Python
SDKuntuk Python (Boto3)
catatan

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

import boto3 def hello_redshift(redshift_client): """ Use the AWS SDK for Python (Boto3) to create an Amazon Redshift client and list the clusters in your account. This list might be empty if you haven't created any clusters. This example uses the default settings specified in your shared credentials and config files. :param redshift_client: A Boto3 Redshift Client object. """ print("Hello, Redshift! Let's list your clusters:") paginator = redshift_client.get_paginator("describe_clusters") clusters = [] for page in paginator.paginate(): clusters.extend(page["Clusters"]) print(f"{len(clusters)} cluster(s) were found.") for cluster in clusters: print(f" {cluster['ClusterIdentifier']}") if __name__ == "__main__": hello_redshift(boto3.client("redshift"))