I understand there are a few questions related to these issues. I have seen them but could not find the correct solution.
I am using AWS Secret Manager to store the credentials and right now trying to connect with AWS Redshift using AWS Lambda Function.
Here is my lambda.py
import json
import boto3
import base64
import psycopg2
from botocore.exceptions import ClientError
def get_secret(secret_name):
try:
session = boto3.session.Session()
client = session.client(service_name='secretsmanager', region_name='xx')
get_secret_value_response = client.get_secret_value( SecretId=secret_name )
secret = get_secret_value_response['SecretString']
secret = json.loads(secret)
return secret
def lambda_handler(event, context):
s = get_secret('secretname')
conn = psycopg2.connect(database = s['xx'],
user = s['username'],
password = secret['password'],
host = secret['host'],
port = secret['port']
)
print('connected')
cur = conn.cursor()
cur.execute("""Select * from table1;""")
rows = cur.fetchall()
for row in rows:
print(row[0])
ERROR: FATAL: no pg_hba.conf entry for host "::ffff:xx.xxx.xxx.xxx", user "xxxx", database "xxx", SSL off
I am using psycopg2.
I have tried inserting, " sslmode = 'require'", not working.
Any help will be appreciated