简体   繁体   中英

create glue connection to mysql using boto3

I'm trying to create a new aws glue connection. I'm using the boto3 script below. I'm able to connect with similar scripts and retrieve the structure of tables in data catalog databases. So I know the client is working. I know the availability zone is us-west-2 also. I copied the rest of the info from a glue connection I'd already created. I was just trying to test the boto3 script to see if I could create a connection through the script. Does anyone see what the issue might be? I'm trying to connect to a mysql database on an ec2 instance.

code:

# 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'
        }
    }
)

error:

---------------------------------------------------------------------------
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

The create_connection Glue API defined by Boto3 does not mention what parameters are to be passed for the 'ConnectionProperties' field. It only mentions key-value pairs are to be supplied.The values to be passed are as below.


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>']
    }
    }
)

I had the ConnectionProperties wrong. replace 'string' with 'JDBC_CONNECTION_URL'. The correction is below.

 'ConnectionProperties': {
                'JDBC_CONNECTION_URL': 'jdbc:mysql://dataxxx:3306/disxxx',
                'username':'root',
                'password':'ip1k5PNCxxxxx'
            }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM