python-3.x - 在 Boto3 中创建新连接时指定 ConnectionProperties
问题描述
我正在尝试使用 boto3 python 脚本创建连接。它是与 ec2 实例上的 mysql 数据库的连接。我正在使用下面的脚本。我收到以下错误消息。我不确定我错过了什么。我已经使用类似的脚本毫无问题地创建了胶水爬虫。除了我在 ConnectionProperties 中添加了用户名和密码外,我几乎都遵循 boto3 文档。我不确定这是否正确。如果我做对了,或者我需要在我的代码中修复什么,有人可以告诉我吗?
代码:
# create new connection
response = client.create_connection(
ConnectionInput={
'Name': 'tst_scrpt',
'ConnectionType': 'JDBC',
'ConnectionProperties': {
'string': 'jdbc:mysql://dataxxx:3306/disxxx',
'username':'root',
'password':'ip1k5PNCxxxxx'
}
,
'PhysicalConnectionRequirements': {
'SubnetId': 'subnet-0436167b7cbxxxx',
'SecurityGroupIdList': [
'sg-02c3f45ce51exxxxx'
]
}
}
)
错误:
---------------------------------------------------------------------------
InvalidInputException Traceback (most recent call last)
<ipython-input-18-6ac0bdcfa816> in <module>
16 'SubnetId': 'subnet-0436167b7cbxxxx',
17 'SecurityGroupIdList': [
---> 18 'sg-02c3f45ce51exxxxx'
19 ]
20 # ,
/anaconda3/envs/py36/lib/python3.6/site-packages/botocore/client.py in _api_call(self, *args, **kwargs)
355 "%s() only accepts keyword arguments." % py_operation_name)
356 # The "self" in this scope is referring to the BaseClient.
--> 357 return self._make_api_call(operation_name, kwargs)
358
359 _api_call.__name__ = str(py_operation_name)
/anaconda3/envs/py36/lib/python3.6/site-packages/botocore/client.py in _make_api_call(self, operation_name, api_params)
659 error_code = parsed_response.get("Error", {}).get("Code")
660 error_class = self.exceptions.from_code(error_code)
--> 661 raise error_class(parsed_response, operation_name)
662 else:
663 return parsed_response
InvalidInputException: An error occurred (InvalidInputException) when calling the CreateConnection operation: Validation for connection properties failed
解决方案
我的 ConnectionProperties 错误。将“字符串”替换为“JDBC_CONNECTION_URL”。更正如下。
'ConnectionProperties': {
'JDBC_CONNECTION_URL': 'jdbc:mysql://dataxxx:3306/disxxx',
'username':'root',
'password':'ip1k5PNCxxxxx'
}
推荐阅读
- c - C 如何正确存储 sqlite3 行数据?
- ubuntu-16.04 - Ejabberd 19 在安装时抛出“deps/.got”异常
- javascript - 如何提交从php生成的多个表单
- automated-tests - 如何在 Visual Studio 2019 中单独运行选定的测试
- yammer - 通过 Yammer 上的 API 发布富文本消息
- wordpress - plesk 子文件夹/blog wordpress nginx 404 未找到
- sql-server - 在同一台计算机上从 SQL Server Express 切换到 SQL Server Developer 版本
- matlab - 如何将 .mat 文件转换为 netCDF 文件?
- python - 值计数不适用于对象列
- java - 如果不从 TestNG 运行 @before 方法,我应该如何运行相同的测试用例?