

 从补丁 198 开始，Amazon Redshift 将不再支持创建新的 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
<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}" } ] } `