Amazon Redshift examples using SDK for Kotlin - AWS SDK Code Examples

There are more AWS SDK examples available in the AWS Doc SDK Examples GitHub repo.

Amazon Redshift examples using SDK for Kotlin

The following code examples show you how to perform actions and implement common scenarios by using the AWS SDK for Kotlin with Amazon Redshift.

Actions are code excerpts from larger programs and must be run in context. While actions show you how to call individual service functions, you can see actions in context in their related scenarios.

Scenarios are code examples that show you how to accomplish specific tasks by calling multiple functions within a service or combined with other AWS services.

Each example includes a link to the complete source code, where you can find instructions on how to set up and run the code in context.

Actions

The following code example shows how to use CreateCluster.

SDK for Kotlin
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

Create the cluster.

suspend fun createCluster( clusterId: String?, masterUsernameVal: String?, masterUserPasswordVal: String?, ) { val clusterRequest = CreateClusterRequest { clusterIdentifier = clusterId masterUsername = masterUsernameVal masterUserPassword = masterUserPasswordVal nodeType = "ra3.4xlarge" publiclyAccessible = true numberOfNodes = 2 } RedshiftClient { region = "us-east-1" }.use { redshiftClient -> val clusterResponse = redshiftClient.createCluster(clusterRequest) println("Created cluster ${clusterResponse.cluster?.clusterIdentifier}") } }
  • For API details, see CreateCluster in AWS SDK for Kotlin API reference.

The following code example shows how to use DeleteCluster.

SDK for Kotlin
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

Delete the cluster.

suspend fun deleteRedshiftCluster(clusterId: String?) { val request = DeleteClusterRequest { clusterIdentifier = clusterId skipFinalClusterSnapshot = true } RedshiftClient { region = "us-west-2" }.use { redshiftClient -> val response = redshiftClient.deleteCluster(request) println("The status is ${response.cluster?.clusterStatus}") } }
  • For API details, see DeleteCluster in AWS SDK for Kotlin API reference.

The following code example shows how to use DescribeClusters.

SDK for Kotlin
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

Describe the cluster.

suspend fun describeRedshiftClusters() { RedshiftClient { region = "us-west-2" }.use { redshiftClient -> val clusterResponse = redshiftClient.describeClusters(DescribeClustersRequest {}) val clusterList = clusterResponse.clusters if (clusterList != null) { for (cluster in clusterList) { println("Cluster database name is ${cluster.dbName}") println("Cluster status is ${cluster.clusterStatus}") } } } }

The following code example shows how to use ModifyCluster.

SDK for Kotlin
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

Modify a cluster.

suspend fun modifyCluster(clusterId: String?) { val modifyClusterRequest = ModifyClusterRequest { clusterIdentifier = clusterId preferredMaintenanceWindow = "wed:07:30-wed:08:00" } RedshiftClient { region = "us-west-2" }.use { redshiftClient -> val clusterResponse = redshiftClient.modifyCluster(modifyClusterRequest) println( "The modified cluster was successfully modified and has ${clusterResponse.cluster?.preferredMaintenanceWindow} as the maintenance window", ) } }
  • For API details, see ModifyCluster in AWS SDK for Kotlin API reference.

Scenarios

The following code example shows how to create a web application that tracks and reports on work items using an Amazon Redshift database.

SDK for Kotlin

Shows how to create a web application that tracks and reports on work items stored in an Amazon Redshift database.

For complete source code and instructions on how to set up a Spring REST API that queries Amazon Redshift data and for use by a React application, see the full example on GitHub.

Services used in this example
  • Amazon Redshift

  • Amazon SES