【发布时间】:2018-01-16 16:51:07
【问题描述】:
以下已解决的问题允许我在 Redshift 中卸载、复制、运行查询、创建表等:Redshift create table not working via Python 和 Unload to S3 with Python using IAM Role credentials。请注意,即使我通过 Redshift 成功地从 S3 写入和复制,也没有对 Boto3 的依赖。
我希望能够在 Python 中(来自 cwd)动态地将文件上传到 S3 - 但是我似乎没有找到有关如何使用 iam_role 'arn:aws:iam:<aws-account-id>:role/<role_name> 而不是访问和根据http://boto3.readthedocs.io/en/latest/guide/quickstart.html 的密钥。
非常感谢任何帮助。这就是我现在所拥有的,它会引发Unable to locate credentials 的错误:
import boto3
#Input parameters for s3 buckets and s3 credentials
bucket_name = ''
bucket_key = ''
filename_for_csv = 'output.csv'
#Moving file to S3
s3 = boto3.resource('s3')
data = open(filename_for_csv, 'rb')
s3.Bucket(bucket_name).put_object(Key=bucket_key, Body=data, ServerSideEncryption='AES256')
【问题讨论】:
标签: python amazon-web-services amazon-s3