[英]create glue connection to mysql using boto3
我正在嘗試創建一個新的 aws 膠水連接。 我正在使用下面的 boto3 腳本。 我能夠連接類似的腳本並檢索數據目錄數據庫中的表結構。 所以我知道客戶正在工作。 我知道可用區也是 us-west-2。 我從我已經創建的膠水連接中復制了信息的 rest。 我只是想測試 boto3 腳本,看看是否可以通過腳本創建連接。 有誰看到問題可能是什么? 我正在嘗試連接到 ec2 實例上的 mysql 數據庫。
代碼:
# create new connection
response = client.create_connection(
ConnectionInput={
'Name': 'tst_scrpt',
'ConnectionType': 'JDBC',
'MatchCriteria': [
'string',
],
'ConnectionProperties': {
'string': 'jdbc:mysql://xxxxx:3306/disxxx',
'username':'root',
'password':'ipxxxxx'
},
'PhysicalConnectionRequirements': {
'SubnetId': 'subnet-04xxxxx',
'SecurityGroupIdList': [
'sg-xxxxx'
],
'AvailabilityZone': 'us-west-2'
}
}
)
錯誤:
---------------------------------------------------------------------------
InvalidInputException Traceback (most recent call last)
<ipython-input-20-c3f33f9c9933> in <module>
18 'sg-xxxxx'
19 ],
---> 20 'AvailabilityZone': 'us-west-2'
21 }
22 }
/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
Boto3 定義的 create_connection Glue API 沒有提到要為“ConnectionProperties”字段傳遞哪些參數。 它只提到要提供鍵值對。要傳遞的值如下。
client = boto3.client('glue', region_name='<region-to-use>')
response = client.create_connection(
CatalogId='<account-id>',
ConnectionInput={
'Name': '<name-of-the-connection>',
'Description': 'Test connection',
'ConnectionType':'JDBC',
'ConnectionProperties': {
'USERNAME': '<db-username>',
'JDBC_ENFORCE_SSL': 'false',
'PASSWORD': '<db-password>',
'JDBC_CONNECTION_URL': 'jdbc:protocol://host:port/db_name'
},
'PhysicalConnectionRequirements': {
'SubnetId': '<subnet-to-use>',
'AvailabilityZone': '<availability-zone-to-use>',
'SecurityGroupIdList': ['<security-group(s)-to-use>']
}
}
)
我的 ConnectionProperties 錯誤。 將“字符串”替換為“JDBC_CONNECTION_URL”。 更正如下。
'ConnectionProperties': {
'JDBC_CONNECTION_URL': 'jdbc:mysql://dataxxx:3306/disxxx',
'username':'root',
'password':'ip1k5PNCxxxxx'
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.