amazon-redshift-python-driver icon indicating copy to clipboard operation
amazon-redshift-python-driver copied to clipboard

IAMR not supported

Open raphaelauv opened this issue 1 year ago • 0 comments

I can't connect to an IAMR redshift user with this lib

CREATE USER "IAMR:test_to_delete_redshift_ci" PASSWORD DISABLE;

but It work when I manually use boto3+psycopg2


import os

import boto3
import psycopg2
import redshift_connector

os.environ["AWS_PROFILE"] = "redshift_test_role_2"

def with_lib():
    conn = redshift_connector.connect(
        iam=True,
        cluster_identifier="YYYYYY",
        database="AAAAA",
        db_user="test_to_delete_redshift_ci",
        password="",
        region="eu-west-1",
    )
    cursor = conn.cursor()
    cursor.execute("SELECT 10,20")
    print(cursor.fetchall())

def manually():

    RS_PORT = 5439
    DATABASE = 'AAAAAA'
    CLUSTER_ID = 'YYYYYYY'
    RS_HOST = 'XXXXXXXXXXX'

    client = boto3.client('redshift')

    cluster_creds = client.get_cluster_credentials_with_iam(ClusterIdentifier=CLUSTER_ID)

    print(cluster_creds)
    conn = psycopg2.connect(
        host=RS_HOST,
        port=RS_PORT,
        user=cluster_creds['DbUser'],
        password=cluster_creds['DbPassword'],
        database=DATABASE
    )
    cur = conn.cursor()
    cur.execute("SELECT 10,20")

    print(cur.fetchall())

if __name__ == '__main__':

    with_lib()
    manually()

with_lib fail with

redshift_connector.error.ProgrammingError: {'S': 'FATAL', 'C': '42704', 'M': 'user "IAM:test_to_delete_redshift_ci" does not exist', 'F': '/opt/brazil-pkg-cache/packages/RedshiftPADB/RedshiftPADB-1.0.7910.0/AL2_x86_64/generic-flavor/src/src/pg/src/backend/utils/init/miscinit.c', 'L': '976', 'R': 'InitializeSessionUserId'}

raphaelauv avatar Feb 26 '25 13:02 raphaelauv