gpt4 book ai didi

python-3.x - AWS UNLOAD 无效凭证子句

转载 作者:行者123 更新时间:2023-12-03 23:55:44 26 4
gpt4 key购买 nike

我正在尝试将数据从 AWS Redshift 卸载到 s3 存储桶。 Redshift 集群还受密码保护。我设置了 aws cli 以使用适当的 key 对并成功测试。我可以使用我的凭据通过 DataGrip 访问 Redshift 集群,但是现在当我尝试在 python3 中使用以下脚本卸载时

import json
import os
import psycopg2


def run(config_json, sql_query):

conn = psycopg2.connect(**config_json['db'])
cursor = conn.cursor()

query = """
UNLOAD ($${}$$)
to \'{}\'
parallel off
delimiter ','
allowoverwrite;
""".format(sql_query, config_json['s3bucket_path_to_file'])
print("The following UNLOAD query is being run: \n" + query)
cursor.execute(query)
print('Completed write to {}'.format(config_json['s3bucket_path_to_file']))


if __name__ == '__main__':
config_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'config.json')
with open(config_path, 'r') as f:
config = json.loads(f.read())

query_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'query.sql')
with open(query_path, 'r') as f:
query_sql = f.read()

run(config, query_sql)

我收到以下错误
psycopg2.InternalError: invalid CREDENTIALS clause
DETAIL:
-----------------------------------------------
error: invalid CREDENTIALS clause
code: 8001
context:
query: 2820791
location: aws_credentials_parser.cpp:62
process: padbmaster [pid=25330]
-----------------------------------------------
config.json文件具有以下格式:
{
"db": {
"dbname": "dbname",
"user": "user1",
"host": "someip",
"password": "very secret psw",
"port": "1111"
},
"s3bucket_path_to_file": "s3://bucket-name/path/to/file.csv"
}

最佳答案

您尚未在查询语句中指定 CREDENTIALS 部分。为了让 Redshift 写入您的 S3 存储桶,您需要提供 Redshift 将使用的有效凭证。

您可以指定 iam_roleaccess_key_idsecret_access_key (如果使用临时凭据,则使用 session_token)。

关于python-3.x - AWS UNLOAD 无效凭证子句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48532619/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com