You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过AWS CLI/boto3更新Glue数据库JDBC连接用户名

AWS Glue JDBC连接更新用户名的正确实现方式

错误原因说明

你遇到的报错有两个核心诱因:

  • Glue JDBC连接的ConnectionProperties有固定的键名规则,用户名对应的键为JDBC_USER,而非你使用的Username,密码、连接URL对应的键分别为JDBC_PASSWORD、JDBC_CONNECTION_URL,使用自定义键名会被识别为无效参数。
  • update_connection接口的ConnectionInput是全量覆盖逻辑,不是增量更新,仅传用户名参数会缺失JDBC连接必填的URL、密码等配置,直接触发参数校验失败。

boto3 正确实现代码

建议先拉取现有连接的完整配置,仅修改用户名字段后再提交更新,避免手动补齐配置出错:

# 先获取现有连接配置
existing_conn = client.get_connection(
    Name='test-db'
)['Connection']

# 仅更新用户名字段
existing_conn['ConnectionProperties']['JDBC_USER'] = username

# 提交更新
response = client.update_connection(
    Name='test-db',
    ConnectionInput={
        'Name': existing_conn['Name'],
        'ConnectionType': existing_conn['ConnectionType'],
        'ConnectionProperties': existing_conn['ConnectionProperties'],
        # 可选:保留原有的Description、PhysicalConnectionRequirements等配置
        'Description': existing_conn.get('Description', ''),
        'PhysicalConnectionRequirements': existing_conn.get('PhysicalConnectionRequirements', {})
    }
)

CLI 正确实现方式

方式1:基于现有配置更新(推荐)

  1. 导出现有连接配置到本地文件
aws glue get-connection --name test-db --query 'Connection' > conn_config.json
  1. 编辑conn_config.json,修改ConnectionProperties下的JDBC_USER值为新用户名,删除返回结果中的CreationTime、LastUpdatedTime等只读字段
  2. 提交更新
aws glue update-connection --name test-db --connection-input file://conn_config.json

方式2:直接传参更新

aws glue update-connection \
  --name test-db \
  --connection-input '{
    "Name": "test-db",
    "ConnectionType": "JDBC",
    "ConnectionProperties": {
      "JDBC_CONNECTION_URL": "jdbc:mysql://你的数据库地址:端口/库名",
      "JDBC_USER": "新用户名",
      "JDBC_PASSWORD": "你的数据库密码"
    }
  }'

内容的提问来源于stack exchange,提问作者Adi334

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.29 00:45:02