안녕하세요 S3합니다 :언로드 여러 파일 내가 오류가 아래 점점 특정 S3 버킷에 Redshift에 여러 테이블을 언로드하려고
psycopg2.InternalError: Specified unload destination on S3 is not empty. Consider using a different bucket/prefix, manually removing the target files in S3, or using the ALLOWOVERWRITE option.
내가 'allowoverwrite'추가 할 경우 unload_function에 대한 옵션은 그 전에 overwritting한다 S3에서 마지막 테이블을 언로드하고 테이블을로드합니다. 당신이 동일한 대상에 데이터를 저장하는 것을 불평
import psycopg2
def unload_data(r_conn, aws_iam_role, datastoring_path, region, table_name):
unload = '''unload ('select * from {}')
to '{}'
credentials 'aws_iam_role={}'
manifest
gzip
delimiter ',' addquotes escape parallel off '''.format(table_name, datastoring_path, aws_iam_role)
print ("Exporting table to datastoring_path")
cur = r_conn.cursor()
cur.execute(unload)
r_conn.commit()
def main():
host_rs = 'dataingestion.*********.us******2.redshift.amazonaws.com'
port_rs = '5439'
database_rs = '******'
user_rs = '******'
password_rs = '********'
rs_tables = [ 'Employee', 'Employe_details' ]
iam_role = 'arn:aws:iam::************:role/RedshiftCopyUnload'
s3_datastoring_path = 's3://mysamplebuck/'
s3_region = 'us_*****_2'
print ("Exporting from source")
src_conn = psycopg2.connect(host = host_rs,
port = port_rs,
database = database_rs,
user = user_rs,
password = password_rs)
print ("Connected to RS")
for i, tabe in enumerate(rs_tables):
if tabe[0] == tabe[-1]:
print("No files to read!")
unload_data(src_conn, aws_iam_role = iam_role, datastoring_path = s3_datastoring_path, region = s3_region, table_name = rs_tables[i])
print (rs_tables[i])
if __name__=="__main__":
main()
당신은 'allowoverwrite'옵션을 사용하여 문제가 있다고 말했지만 난 정말 당신이 무엇을 의미하는지에 따라 didnt한다 -하십시오 그걸 더 잘 설명 할 수 있습니까? –
답변 해 주셔서 감사합니다. 내가 아래로 언로드 변수에 'allowoverwrite'추가 할 경우 '언로드 =' ' 언로드' 에 {} ' 자격 증명'aws_iam_role = {} ' gzip을 구분 매니페스트'('*에서 {}를 선택)', 'addquotes escape allowoverwrite' '.format (table_name, datastoring_path, aws_iam_role) 모든 테이블은 동시에 다음 테이블로 덮어 쓰면서 s3 버킷에 쓸 수 있습니다. 마지막으로 s3 버켓의 마지막 테이블을 볼 수 있습니다. –