SageMaker notebook instance in VPC failed to connect to local database

0

hi there,

I am setting up a jupyter notebook in SageMaker within the VPC and using the jdbc jars to connect to the local database. But it shows the following error messages.
": com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the host xxx.xxx.xxx.xxx, port 21000 has failed. Error: "connect timed out. Verify the connection properties. Make sure that an instance of SQL Server is running on the host and accepting TCP/IP connections at the port. Make sure that TCP connections to the port are not blocked by a firewall."."

I used the exactly the same VPC, subnet, security group as what i used in a glue job to extract the data from the local db. While the glue job works but the SageMaker notebook failed. I am sure the firewalls are opened.
Could anyone tell me how to solve it?
I also came across the following articles, but i am not sure if it is the root cause.
https://aws.amazon.com/blogs/machine-learning/understanding-amazon-sagemaker-notebook-instance-networking-configurations-and-advanced-routing-options/

axchoi
已提問 5 年前檢視次數 1075 次
1 個回答
0
已接受的答案

Hi,
The principle here is that there much be network connectivity between the Notebook Instance and the DB Instance, and the security groups on the DB Instance should allow in-bound traffic from the Notebook Instance

One example of such as setup is

  1. RDS DB Instance is VPC vpc-a and Subnet subnet-b.

  2. SageMaker Notebook is launched in VPC vpc-a, Subnet subnet-b, with Security Group sg-c with DirectIntenetAccess "Disabled"

  3. In the RDS DB Instance's Security Group rules, you can add an Inbound Rule to allow inbound traffic from the SageMaker Notebook security group "sg-c"
    -- Type - Protocol - Port Range - Source
    -- MYSQL/Aurora - TCP - 3306 - sg-c


Sample Code:

! pip install mysql-connector

import mysql.connector
mydb = mysql.connector.connect(
host="$RDS_ENDPOINT",
user="$RDS_USERNAME",
passwd="$RDS_PASSWORD"
)
cursor = mydb.cursor()
cursor.execute("SHOW DATABASES") 

Thanks for using Amazon SageMaker and let us know if there's anything else we can help with!

Edited by: JaipreetS-AWS on May 6, 2019 3:04 PM

已回答 5 年前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南