Connect to Redshift (in private Subnet) using Lambda

0

I have a Redshift cluster in private subnet and i am using Pyscopg2 library to connect to it from Lambda . I have deployed the Lambda inside the VPC and subnets and security group appropriately.

When I use the following code to connect ,

try:
    client = boto3.client('redshift')
    creds = client.get_cluster_credentials(
      DbUser=REDSHIFT_USER,
      DbName=REDSHIFT_DATABASE,
      ClusterIdentifier=REDSHIFT_CLUSTER,
      DurationSeconds=3600)
  except Exception as ERROR:
    print("Credentials Issue: " + ERROR)
  try:

    conn = psycopg2.connect(
      dbname=REDSHIFT_DATABASE,
      user=creds['DbUser'],
      password=creds['DbPassword'],
      port=REDSHIFT_PORT,
      host=REDSHIFT_ENDPOINT)
  except Exception as ERROR:
    print("Connection Issue: ")
    raise

I get the folliowing error

{
  "errorMessage": "FATAL:  no pg_hba.conf entry for host \"::ffff:10.209.4.117\", user \"IAM:awsuser\", database \"dev\", SSL off\n",
  "errorType": "OperationalError",

I have solved this error in SQL clients by adding the following properties AuthMech=REQUIRE&ssl=TRUE

However , i am not sure how can i make the lambda code connect to Redshift.

AWS
전문가
질문됨 4년 전1650회 조회
1개 답변
0
수락된 답변

Check to see if the Lambda is running in the default VPC. It should be running in the same VPC as the Redshift. Please read more here, you will find a tutorial with RDS use pg instead of pymysql to connect to Redshift, pycopg2 is also fine.

AWS
Kunal_G
답변함 4년 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠