

 Amazon Redshift 將不再支援從修補程式 198 開始建立新的 Python UDFs。現有 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
<a name="connecting-with-authentication-profiles"></a>

如果您有許多 Amazon Redshift 連線，則可能難以管理所有連線的設定。每個 JDBC 或 ODBC 連線通常會使用特定的組態選項。透過使用身分驗證設定檔，您可以將連線選項儲存在一起。如此一來，使用者就可以選擇要用來連線的設定檔，而不必管理個別選項的設定。設定檔可以套用至各種案例和使用者類型。

在您建立身分驗證設定檔後，使用者便可以將已可使用的設定檔新增至連線字串。如此一來，其便可以使用每個角色和使用案例的正確設定來連線至 Amazon Redshift。

如需 Amazon Redshift API 資訊，請參閱 [CreateAuthenticationProfile](https://docs.aws.amazon.com/redshift/latest/APIReference/redshift-api.pdf#API_CreateAuthenticationProfile)。

# 建立身分驗證設定檔
<a name="connecting-with-authentication-profiles-creating"></a>

使用 AWS CLI，您可以使用 `create-authentication-profile`命令建立身分驗證設定檔。這會假設您有現有的 Amazon Redshift 叢集和現有的資料庫。您的憑證必須具有可連線至 Amazon Redshift 資料庫的許可，以及可擷取身分驗證設定檔的權限。您可以透過 JSON 字串的形式提供組態選項，也可以參考包含 JSON 字串的檔案。

```
create-authentication-profile --authentication-profile-name<value: String> --authentication-profile-content<value: String>
```

 以下範例會建立名為 `ExampleProfileName` 的設定檔。在這裡，您可以將定義叢集名稱和其他選項設定的金鑰和值新增為 JSON 字串。

```
create-authentication-profile --authentication-profile-name "ExampleProfileName" --authentication-profile-content "{\"AllowDBUserOverride\":\"1\",\"Client_ID\":\"ExampleClientID\",\"App_ID\":\"ExampleAppID\",\"AutoCreate\":false,\"enableFetchRingBuffer\":true,\"databaseMetadataCurrentDbOnly\":true}"
}
```

 此命令會使用指定的 JSON 設定建立設定檔。系統會傳回以下內容，以指出您已建立設定檔。

 `{"AuthenticationProfileName": "ExampleProfileName", "AuthenticationProfileContent": "{\"AllowDBUserOverride\":\"1\",\"Client_ID\":\"ExampleClientID\",\"App_ID\":\"ExampleAppID\",\"AutoCreate\":false,\"enableFetchRingBuffer\":true,\"databaseMetadataCurrentDbOnly\":true}" } ` 

## 建立身分驗證設定檔的限制和配額
<a name="connecting-with-authentication-profiles-limitations"></a>

每位客戶的配額為十 (10) 個身分驗證設定檔。

身分驗證設定檔可能會發生某些錯誤。例如，如果您使用現有名稱建立新的設定檔，或是您超過設定檔配額的話。如需詳細資訊，請參閱 [CreateAuthenticationProfile](https://docs.aws.amazon.com/redshift/latest/APIReference/redshift-api.pdf#API_CreateAuthenticationProfile)。

您無法在身分驗證設定檔存放區中儲存 JDBC、ODBC 和 Python 連線字串的某些選項金鑰和值：
+ `AccessKeyID`
+ `access_key_id`
+ `SecretAccessKey`
+ `secret_access_key_id`
+ `PWD`
+ `Password`
+ `password`

您無法在設定檔存放區中儲存 JDBC 或 ODBC 連線字串的金鑰或值 `AuthProfile`。若為 Python 連線，您無法儲存 `auth_profile`。

身分驗證設定檔存放在 Amazon DynamoDB 中並由 管理 AWS。

# 使用身分驗證設定檔連線
<a name="connecting-with-authentication-profiles-using"></a>

在建立身分驗證設定檔後，便可以在 JDBC 2.0 版 `AuthProfile` 中將設定檔名稱納入為連線選項。使用此連線選項會擷取已儲存的設定。

```
jdbc:redshift:iam://endpoint:port/database?AuthProfile=<Profile-Name>&AccessKeyID=<Caller-Access-Key>&SecretAccessKey=<Caller-Secret-Key>
```

以下是 JDBC URL 字串範例。

```
jdbc:redshift:iam://examplecluster:us-west-2/dev?AuthProfile="ExampleProfile"&AccessKeyID="AKIAIOSFODNN7EXAMPLE"&SecretAccessKey="wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY"
```

在 JDBC URL 中指定 `AccessKeyID` 和 `SecretAccessKey`，以及身分驗證設定檔名稱。

您也可以使用分號分隔符號來分隔組態選項，例如以下範例 (其包含記錄的選項)。

```
jdbc:redshift:iam://my_redshift_end_point:5439/dev?LogLevel=6;LogPath=/tmp;AuthProfile=my_profile;AccessKeyID="AKIAIOSFODNN7EXAMPLE";SecretAccessKey="wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY"
```

**注意**  
 請勿將機密資訊新增至身分驗證設定檔。例如，請勿在身分驗證設定檔中儲存 `AccessKeyID` 或 `SecretAccessKey` 值。身分驗證設定檔存放區具有禁止儲存秘密金鑰的規則。如果您嘗試儲存與敏感資訊相關聯的金鑰和值，就會收到錯誤。

# 取得身分驗證設定檔
<a name="connecting-with-authentication-profiles-getting"></a>

若要列出現有的身分驗證設定檔，請呼叫以下命令。

```
describe-authentication-profiles --authentication-profile-name <value: String>
```

以下範例示範所擷取的兩個設定檔。如果未指定設定檔名稱，則會傳回所有設定檔。

`{ "AuthenticationProfiles": [ { "AuthenticationProfileName": "testProfile1", "AuthenticationProfileContent": "{\"AllowDBUserOverride\":\"1\",\"Client_ID\":\"ExampleClientID\",\"App_ID\":\"ExampleAppID\",\"AutoCreate\":false,\"enableFetchRingBuffer\":true,\"databaseMetadataCurrentDbOnly\":true}" }, { "AuthenticationProfileName": "testProfile2", "AuthenticationProfileContent": "{\"AllowDBUserOverride\":\"1\",\"Client_ID\":\"ExampleClientID\",\"App_ID\":\"ExampleAppID\",\"AutoCreate\":false,\"enableFetchRingBuffer\":true,\"databaseMetadataCurrentDbOnly\":true}" } ] } `