使用 Amazon SDK 的 Amazon Redshift 代码示例 - Amazon Redshift
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

使用 Amazon SDK 的 Amazon Redshift 代码示例

以下代码示例演示了如何将 Amazon Redshift 与 Amazon 软件开发工具包(SDK)结合使用。

操作是大型程序的代码摘录,必须在上下文中运行。您可以通过操作了解如何调用单个服务函数,还可以通过函数相关场景和跨服务示例的上下文查看操作。

场景 是展示如何通过在同一服务中调用多个函数来完成特定任务的代码示例。

跨服务示例是指跨多个 Amazon Web Services工作的示例应用程序。

有关 Amazon SDK 开发人员指南和代码示例的完整列表,请参阅 将此服务与 Amazon SDK 结合使用。本主题还包括有关入门的信息以及有关先前的 SDK 版本的详细信息。

开始使用

以下代码示例展示了如何开始使用 Amazon Redshift。

Java
SDK for Java 2.x
注意

查看 GitHub,了解更多信息。查找完整示例,学习如何在 Amazon 代码示例存储库中进行设置和运行。

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())); } }
  • 有关 API 详细信息,请参阅《Amazon SDK for Java 2.x API 参考》中的 describeClusters