

 Amazon Redshift は、パッチ 198 以降、新しい Python UDF の作成をサポートしなくなります。既存の Python UDF は、2026 年 6 月 30 日まで引き続き機能します。詳細については、[ブログ記事](https://aws.amazon.com/blogs/big-data/amazon-redshift-python-user-defined-functions-will-reach-end-of-support-after-june-30-2026/)を参照してください。

# プロビジョニングされたクラスターを Amazon Redshift Serverless へ移行する
<a name="serverless-migration"></a>

既存のプロビジョニングされたクラスターを Amazon Redshift Serverless に移行して、コンピューティングリソースのオンデマンドおよび自動スケーリングを有効にできます。プロビジョニングされたクラスターを Amazon Redshift Serverless に移行すると、使用するリソースに対してのみ料金を支払うことでコストを最適化し、ワークロードの需要に基づいて容量を自動的にスケーリングできます。移行の一般的なユースケースには、アドホッククエリの実行、定期的なデータ処理ジョブ、リソースの過剰プロビジョニングのない予測不可能なワークロードの処理などがあります。プロビジョニングされた Amazon Redshift クラスターをサーバーレスデプロイオプションに移行するには、次のタスクセットを実行します。

## プロビジョニングされたクラスターのスナップショットを作成する
<a name="serverless-migration-snapshots"></a>

**注記**  
Amazon Redshift は、プロビジョニングされたクラスタースナップショットをサーバーレス名前空間に復元するときに、インターリーブキーを自動的に複合キーに変換します。

 プロビジョニングされたクラスターから Amazon Redshift Serverless にデータを転送するには、プロビジョニングされたクラスターのスナップショットを作成し、Amazon Redshift Serverless でスナップショットを復元します。

**注記**  
データをサーバーレスワークグループに移行する前に、プロビジョニングしたクラスターのニーズが Amazon Redshift Serverless で選択した RPU の量と互換性があることを確認してください。

プロビジョニングされたクラスターのスナップショットを作成するには

1. AWS マネジメントコンソール にサインインして、[https://console.aws.amazon.com/redshiftv2/](https://console.aws.amazon.com/redshiftv2/) で Amazon Redshift コンソールを開きます。

1. ナビゲーションメニューで、**[Clusters]** (クラスター)、**[Snapshots]** (スナップショット)、次に **[Create snapshot]** (スナップショットの作成) を選択します。

1. スケジュール定義のプロパティを入力してから、[**スナップショットの作成**] を選択します。スナップショットが使用できるようになるまではしばらくかかります。

プロビジョニングされたクラスタースナップショットをサーバーレス名前空間に復元するには以下の内容を実行します。

1. AWS マネジメントコンソール にサインインして、[https://console.aws.amazon.com/redshiftv2/](https://console.aws.amazon.com/redshiftv2/) で Amazon Redshift コンソールを開きます。

1. Amazon Redshift でプロビジョニングされたクラスターのコンソールを開き、**[Clusters]** (クラスター) ページ、**[Snapshots]** (スナップショット) ページの順に移動します。

1. 使用するスナップショットを選択します。

1. **[Restore snapshot]** (スナップショットから復元)、**[Restore to serverless namespace]** (サーバーレス名前空間に復元) の順にクリックします。

1. スナップショットの復元先の名前空間を選択します。

1. スナップショットから復元することを確認します。この操作により、サーバーレスエンドポイント内のすべてのデータベースが、プロビジョニングされたクラスターのデータで置き換えられます。**[復元]** を選択します。

プロビジョニングされたクラスタースナップショットの詳細については、「[Amazon Redshift スナップショット](https://docs.aws.amazon.com/redshift/latest/mgmt/working-with-snapshots.html)」を参照してください。

## ドライバーでの Amazon Redshift Serverless への接続
<a name="serverless-migration-drivers"></a>

 好みの SQL クライアントを使用して Amazon Redshift Serverless に接続するには、Amazon Redshift が提供する [JDBC ドライバーバージョン 2.x](https://docs.aws.amazon.com/redshift/latest/mgmt/jdbc20-install.html) を使用することができます。Amazon Redshift JDBC ドライバーバージョン 2.x の最新バージョンを使用して Amazon Redshift に接続することをお勧めします。ポート番号はオプションです。そのドライバーが含まれていない場合、Amazon Redshift Serverless のデフォルトのポート番号は 5439 です。5431-5455 または 8191-8215 のポート範囲から別のポートに変更できます。サーバーレスエンドポイントのデフォルトのポートを変更するには、AWS CLI と Amazon Redshift API を使用します。

 JDBC、ODBC、または Python ドライバーに使用する正確なエンドポイントを見つけるには、Amazon Redshift Serverless の「**Workgroup configuration** (ワークグループの設定)」を参照してください。Amazon Redshift Serverless API オペレーションの `GetWorkgroup` または AWS CLI オペレーション `get-workgroups` を使用して、ワークグループに関する情報を戻してから接続することもできます。

### パスワードベースの認証を使用した接続
<a name="serverless-migration-drivers-password-auth"></a>

パスワードベースの認証で Amazon Redshift JDBC ドライバーバージョン 2.x を使用して接続を確立するには、次の構文を使用します。

```
jdbc:redshift://<{{workgroup-name}}>.<{{account-number}}>.<{{aws-region}}>.redshift-serverless.amazonaws.com:5439/?username={{username}}&password={{password}}
```

パスワードベースの認証で Amazon Redshift Python コネクタを使用して接続を確立するには、次の構文を使用します。

```
import redshift_connector
with redshift_connector.connect(
    host='<{{workgroup-name}}>.<{{account-number}}>.<{{aws-region}}>.redshift-serverless.amazonaws.com',
    database='<{{database-name}}>',
    user='{{username}}',
    password='{{password}}'
    # port value of 5439 is specified by default
) as conn:
    pass
```

パスワードベースの認証で Amazon Redshift ODBC ドライバーバージョン 2.x を使用して接続を確立するには、次の構文を使用します。

```
Driver={Amazon Redshift ODBC Driver (x64)}; Server=<{{workgroup-name}}>.<{{account-number}}>.<{{aws-region}}>.redshift-serverless.amazonaws.com; Database={{database-name}}; User={{username}}; Password={{password}}
```

### IAM を使用した接続
<a name="serverless-migration-drivers-iam"></a>

 IAM でログインする場合は、Amazon Redshift Serverless [https://docs.aws.amazon.com//redshift-serverless/latest/APIReference/API_GetCredentials.html](https://docs.aws.amazon.com//redshift-serverless/latest/APIReference/API_GetCredentials.html) API オペレーションを使用します。

IAM 認証を使用するには、次の例に示すように、`jdbc:redshift:` に続いて Amazon Redshift JDBC URL に `iam:` を追加します。

```
jdbc:redshift:iam://<{{workgroup-name}}>.<{{account-number}}>.<{{aws-region}}>.redshift-serverless.amazonaws.com:5439/<{{database-name}}>
```

この Amazon Redshift Serverless エンドポイントは、dbUser、dbGroup、または自動作成のカスタマイズをサポートしていません。デフォルトでは、ドライバーはログイン時にデータベースユーザーを自動的に作成します。次に、IAM で指定されたタグ、または ID プロバイダー (IdP) で定義されたグループに基づいて、Amazon Redshift データベースロールにユーザーを割り当てます。

AWS ID が `redshift-serverless:GetCredentials` アクションに対する正しい IAM ポリシーを保持していることを確認します。次に、AWS ID に Amazon Redshift Serverless に接続するための正しいアクセス権限を付与する IAM ポリシーの例を示します。IAM アクセス許可の詳細については、「*IAM ユーザーガイド*」の「[IAM ID のアクセス許可の追加および削除](https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_manage-attach-detach.html)」を参照してください。

------
#### [ JSON ]

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Sid": "",
            "Effect": "Allow",
            "Action": "redshift-serverless:GetCredentials",
            "Resource": "*"
        }
    ]
}
```

------

IAM ベースの認証で Amazon Redshift Python コネクタを使用して接続を確立するには、次の構文に示すように、コード内で `iam=true` を使用します。

```
import redshift_connector
with redshift_connector.connect(
    iam=True,
    host='<{{workgroup-name}}>.<{{account-number}}>.<{{aws-region}}>.redshift-serverless.amazonaws.com',
    database='<{{database-name}}>'
    <{{IAM credentials}}>
) as conn:
    pass
```

`IAM credentials` では、以下を含む任意の認証情報を使用できます。
+  AWS プロファイル設定。
+  IAM 認証情報 (アクセスキー ID、シークレットアクセスキー、およびオプションでセッショントークン)。
+  アイデンティティプロバイダーフェデレーション。

Amazon Redshift ODBC ドライバーバージョン 2.x を使用して IAM ベースの認証とプロファイルで接続を確立するには、次の構文を使用します。

```
Driver={Amazon Redshift ODBC Driver (x64)}; IAM=true; Server=<{{workgroup-name}}>.<{{account-number}}>.<{{aws-region}}>.redshift-serverless.amazonaws.com; Database={{database-name}}; Profile={{aws-profile-name}};
```

### GetClusterCredentials API で IAM を使用して接続する
<a name="serverless-migration-drivers-iam-dbuser-group"></a>

**注記**  
Amazon Redshift Serverless に接続するときは、[https://docs.aws.amazon.com//redshift-serverless/latest/APIReference/API_GetCredentials.html](https://docs.aws.amazon.com//redshift-serverless/latest/APIReference/API_GetCredentials.html) API を使用することをお勧めします。この API は、包括的なロールベースのアクセスコントロール (RBAC) 機能と、`GetClusterCredentials` では利用できないその他の新機能を提供します。プロビジョニングされたクラスターからサーバーレスワークグループへの移行を簡素化するために `GetClusterCredentials` API をサポートしていますが、互換性を最適化するために、できるだけ早く `GetCredentials` の使用に移行することを強くお勧めします。

[https://docs.aws.amazon.com//redshift/latest/APIReference/API_GetClusterCredentials.html](https://docs.aws.amazon.com//redshift/latest/APIReference/API_GetClusterCredentials.html) API を使用して Amazon Redshift Serverless への接続を確立できます。この認証方法を実装するには、次のパラメータを組み込んでクライアントまたはアプリケーションを変更します。
+  `iam=true` 
+  `clusterid/cluster_identifier=redshift-serverless-<{{workgroup-name}}>` 
+  `region=<{{aws-region}}>` 

次の例は、3 つのドライバーすべてにわたる BrowserSAML プラグインを示しています。これは、利用可能な認証アプローチの 1 つを表します。特定の要件に応じて、別の認証方法またはプラグインを使用するように例を変更できます。

#### GetClusterCredentials の IAM ポリシーアクセス許可
<a name="serverless-migration-drivers-iam-dbuser-group-iam"></a>

以下は、Amazon Redshift Serverless で `GetClusterCredentials` を使用するために必要なアクセス許可を持つ IAM ポリシーの例です。

------
#### [ JSON ]

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Sid": "VisualEditor0",
            "Effect": "Allow",
            "Action": [
                "redshift-serverless:GetWorkgroup",
                "redshift-serverless:GetNamespace",
                "redshift:GetClusterCredentials",
                "redshift:CreateClusterUser",
                "redshift:JoinGroup",
                "redshift:ExecuteQuery",
                "redshift:FetchResults",
                "redshift:DescribeClusters",
                "redshift:DescribeTable"
            ],
            "Resource": [
                "arn:aws:redshift-serverless:us-east-1:{{111122223333}}:workgroup/{{workgroup-name}}",
                "arn:aws:redshift-serverless:us-east-1:{{111122223333}}:namespace/{{namespace-name}}",
                "arn:aws:redshift:us-east-1:{{111122223333}}:cluster:{{cluster-name}}",
                "arn:aws:redshift:us-east-1:{{111122223333}}:dbuser:{{database-name}}/${redshift:DbUser}"
            ]
        }
    ]
}
```

------

Amazon Redshift JDBC ドライバーバージョン 2.x を使用して、`GetClusterCredentials` で接続を確立するには、次の構文を使用します。

```
jdbc:redshift:iam://redshift-serverless-<{{workgroup-name}}>:<{{aws-region}}>/<{{database-name}}>?plugin_name=com.amazon.redshift.plugin.BrowserSamlCredentialsProvider&login_url=<{{single sign-on URL from IdP}}>"
```

Amazon Redshift Python コネクタを使用して、`GetClusterCredentials` で接続を確立するには、次の構文を使用します。

```
import redshift_connector
with redshift_connector.connect(
    iam=True,
    cluster_identifier='redshift-serverless-<{{workgroup-name}}>',
    region='<{{aws-region}}>',
    database='<{{database-name}}>',
    credentials_provider='BrowserSamlCredentialsProvider'
    login_url='<{{single sign-on URL from IdP}}>'
    # port value of 5439 is specified by default
) as conn:
    pass
```

Amazon Redshift ODBC ドライバーバージョン 2.x を使用して、`GetClusterCredentials` で接続を確立するには、次の構文を使用します。

```
Driver= {Amazon Redshift ODBC Driver (x64)}; IAM=true; isServerless=true; ClusterId=redshift-serverless-<{{workgroup-name}}>; region=<{{aws-region}}>; plugin_name=BrowserSAML;login_url=<{{single sign-on URL from IdP}}>
```

Windows での ODBC DSN 設定の例を次に示します。

![Windows 用 Amazon Redshift ODBC ドライバーの接続タブ。上記のサンプル構文に対応するフィールドが入力されます。](http://docs.aws.amazon.com/ja_jp/redshift/latest/mgmt/images/GetClusterCredentials-odbc-windows.png)


## Amazon Redshift Serverless SDK を使用する
<a name="serverless-migration-sdk"></a>

Amazon Redshift SDK を使用して管理スクリプトを作成した場合は、新しい Amazon Redshift Serverless SDK を使用して Amazon Redshift Serverless と関連リソースを管理する必要があります。利用可能なAPI オペレーションの詳細については、「[Amazon Redshift Serverless API のリファレンスガイド](https://docs.aws.amazon.com/redshift-serverless/latest/APIReference/Welcome.html)」を参照してください。