使用 CDK 创建的 AWS Glue JDBC 连接需要在控制台中输入密码才能生效

AWS Glue JDBC connection created with CDK needs password in the console before it becomes valid

我正在使用用户名和密码的秘密在 Glue 中创建一个 JDBC 连接。我可以在控制台中看到从机密中正确读取了用户名,所以这不是问题。一旦我编辑了详细信息并在控制台中输入密码,它就生效了。我的方法有问题吗?

glue.CfnConnection(
        self,
        id="JDBCConnection",
        catalog_id=self.account,
        connection_input=glue.CfnConnection.ConnectionInputProperty(
            name="jdbc_connection",
            connection_type="JDBC",
            physical_connection_requirements=glue.CfnConnection.PhysicalConnectionRequirementsProperty(
                subnet_id=cdk.Fn.import_value("PrivateSubnet1"),
                security_group_id_list=[jdbc_connection_security_group.attr_group_id],
            ),
            connection_properties={
                "JDBC_CONNECTION_URL": "jdbc:<JDBC_URL>",
                "USERNAME": "{{resolve:secretsmanager:jdbc_username}}",
                "PASSWORD": "{{resolve:secretsmanager:jdbc_password}}",
            },
        ),
)

我遇到了同样的问题,但我意识到问题根本不在于密码,而是我们提供安全组和子网值的方式。

一旦我将所有安全组和子网更改为 IResource 而不是字符串,它对我来说工作正常。

As written, when I edit the connection in the console, without changing anything (just press edit and save) the issue is solved I solved the issue as well.

也许问题出在 Require SSL connection。当我在控制台中按下编辑并保存时,添加了 Require SSL connection: False,但我不知道如何通过 CDK 设置它。

就我而言,我缺少 SSL 和可用性区域。我发现一个有用的工具是使用 aws cli 获取有关先前创建的(或 cdk 创建的和控制台更新的)有效连接的信息。

$> aws glue get-connection --name <connection-name> --profile <profile-name>

这列出了有关可接受(工作)连接的完整信息。

{
    "Connection": {
        "Name": "<connection-name>",
        "Description": "<description>",
        "ConnectionType": "JDBC",
        "ConnectionProperties": {
            "JDBC_CONNECTION_URL": "<full-url>",
            "JDBC_ENFORCE_SSL": "false",
            "PASSWORD": "<password>",
            "USERNAME": "<username>"
        },
        "PhysicalConnectionRequirements": {
            "SubnetId": "<subnet>",
            "SecurityGroupIdList": [
                "<sec-group>",
                "<sec-group>"
            ],
            "AvailabilityZone": "us-west-2a"
        },
        "CreationTime": "<timestamp-w-tz>",
        "LastUpdatedTime": "<timestamp-w-tz>"
    }
}

我发现我缺少 ConnectionPropertiesJDBC_ENFORNCE_SSLPhysicalConnectionRequirementsAvailabilityZone

一旦我在 CDK 中设置它们,创建的连接就会按预期工作。