

Doc AWS SDK 예제 GitHub 리포지토리에서 더 많은 SDK 예제를 사용할 수 있습니다. [AWS](https://github.com/awsdocs/aws-doc-sdk-examples) 

기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.

# SDK for Kotlin을 사용한 Amazon Redshift 예제
<a name="kotlin_1_redshift_code_examples"></a>

다음 코드 예제에서는 Amazon Redshift와 함께 AWS SDK for Kotlin을 사용하여 작업을 수행하고 일반적인 시나리오를 구현하는 방법을 보여줍니다.

*작업*은 대규모 프로그램에서 발췌한 코드이며 컨텍스트에 맞춰 실행해야 합니다. 작업은 개별 서비스 함수를 직접 호출하는 방법을 보여주며, 관련 시나리오의 컨텍스트에 맞는 작업을 볼 수 있습니다.

*시나리오*는 동일한 서비스 내에서 또는 다른 AWS 서비스와 결합된 상태에서 여러 함수를 직접적으로 호출하여 특정 태스크를 수행하는 방법을 보여주는 코드 예제입니다.

각 예시에는 전체 소스 코드에 대한 링크가 포함되어 있으며, 여기에서 컨텍스트에 맞춰 코드를 설정하고 실행하는 방법에 대한 지침을 찾을 수 있습니다.

**Topics**
+ [작업](#actions)
+ [시나리오](#scenarios)

## 작업
<a name="actions"></a>

### `CreateCluster`
<a name="redshift_CreateCluster_kotlin_1_topic"></a>

다음 코드 예시는 `CreateCluster`의 사용 방법을 보여줍니다.

**SDK for Kotlin**  
 GitHub에 더 많은 내용이 있습니다. [AWS 코드 예 리포지토리](https://github.com/awsdocs/aws-doc-sdk-examples/tree/main/kotlin/services/redshift#code-examples)에서 전체 예를 찾고 설정 및 실행하는 방법을 배워보세요.
클러스터를 생성합니다.  

```
suspend fun createCluster(
    clusterId: String?,
    masterUsernameVal: String?,
    masterUserPasswordVal: String?,
) {
    val clusterRequest =
        CreateClusterRequest {
            clusterIdentifier = clusterId
            availabilityZone = "us-east-1a"
            masterUsername = masterUsernameVal
            masterUserPassword = masterUserPasswordVal
            nodeType = "ra3.4xlarge"
            publiclyAccessible = true
            numberOfNodes = 2
        }

    RedshiftClient.fromEnvironment { region = "us-east-1" }.use { redshiftClient ->
        val clusterResponse = redshiftClient.createCluster(clusterRequest)
        println("Created cluster ${clusterResponse.cluster?.clusterIdentifier}")
    }
}
```
+  API 세부 정보는 *AWS SDK for Kotlin API 참조*의 [CreateCluster](https://sdk.amazonaws.com/kotlin/api/latest/index.html)를 참조하세요.

### `DeleteCluster`
<a name="redshift_DeleteCluster_kotlin_1_topic"></a>

다음 코드 예시는 `DeleteCluster`의 사용 방법을 보여줍니다.

**SDK for Kotlin**  
 GitHub에 더 많은 내용이 있습니다. [AWS 코드 예 리포지토리](https://github.com/awsdocs/aws-doc-sdk-examples/tree/main/kotlin/services/redshift#code-examples)에서 전체 예를 찾고 설정 및 실행하는 방법을 배워보세요.
클러스터를 삭제합니다.  

```
suspend fun deleteRedshiftCluster(clusterId: String?) {
    val request =
        DeleteClusterRequest {
            clusterIdentifier = clusterId
            skipFinalClusterSnapshot = true
        }

    RedshiftClient.fromEnvironment { region = "us-west-2" }.use { redshiftClient ->
        val response = redshiftClient.deleteCluster(request)
        println("The status is ${response.cluster?.clusterStatus}")
    }
}
```
+  API 세부 정보는 *AWS SDK for Kotlin API 참조*의 [DeleteCluster](https://sdk.amazonaws.com/kotlin/api/latest/index.html)를 참조하세요.

### `DescribeClusters`
<a name="redshift_DescribeClusters_kotlin_1_topic"></a>

다음 코드 예시는 `DescribeClusters`의 사용 방법을 보여줍니다.

**SDK for Kotlin**  
 GitHub에 더 많은 내용이 있습니다. [AWS 코드 예 리포지토리](https://github.com/awsdocs/aws-doc-sdk-examples/tree/main/kotlin/services/redshift#code-examples)에서 전체 예를 찾고 설정 및 실행하는 방법을 배워보세요.
클러스터를 설명하세요.  

```
suspend fun describeRedshiftClusters() {
    RedshiftClient.fromEnvironment { 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}")
            }
        }
    }
}
```
+  API 세부 정보는 *AWS SDK for Kotlin API 참조*의 [DescribeClusters](https://sdk.amazonaws.com/kotlin/api/latest/index.html)를 참조하세요.

### `ModifyCluster`
<a name="redshift_ModifyCluster_kotlin_1_topic"></a>

다음 코드 예시는 `ModifyCluster`의 사용 방법을 보여줍니다.

**SDK for Kotlin**  
 GitHub에 더 많은 내용이 있습니다. [AWS 코드 예 리포지토리](https://github.com/awsdocs/aws-doc-sdk-examples/tree/main/kotlin/services/redshift#code-examples)에서 전체 예를 찾고 설정 및 실행하는 방법을 배워보세요.
클러스터를 수정합니다.  

```
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",
        )
    }
}
```
+  API 세부 정보는 *AWS SDK for Kotlin API 참조*의 [ModifyCluster](https://sdk.amazonaws.com/kotlin/api/latest/index.html)를 참조하세요.

## 시나리오
<a name="scenarios"></a>

### Amazon Redshift 데이터를 추적하는 웹 애플리케이션 만들기
<a name="cross_RedshiftDataTracker_kotlin_1_topic"></a>

다음 코드 예제에서는 Amazon Redshift 데이터베이스를 사용하는 작업 항목을 추적하고 보고하는 웹 애플리케이션을 만드는 방법을 보여줍니다.

**SDK for Kotlin**  
 Amazon Redshift 데이터베이스에 저장된 작업 항목을 추적하고 보고하는 웹 애플리케이션을 만드는 방법을 보여줍니다.  
 Amazon Redshift 데이터를 쿼리하고 React 애플리케이션에서 사용하도록 Spring REST API를 설정하는 방법에 대한 지침과 전체 소스 코드는 [GitHub](https://github.com/awsdocs/aws-doc-sdk-examples/tree/main/kotlin/usecases/creating_redshift_application)에서 전체 예제를 참조하세요.  

**이 예제에서 사용되는 서비스**
+ Amazon Redshift
+ Amazon SES