我有一个flask应用程序,它调用boto3上传文件来将文件上传到S3存储桶。我以IAM用户的身份打这个电话,因为只有经过身份验证的用户才能进行多部分上传。
下面是将文件上传到S3 bucket的python代码部分:
s3_client = boto3.client('s3', aws_access_key_id=ACCESS_KEY, aws_secret_access_key=SECRET_KEY)
response = s3_client.upload_file(file_name, bucket, object_name)
S3存储桶策略:
{
"Version": "2012-10-17",
"Id": "Policy*********",
"Statement": [
{
"Sid": "Stmt*********",
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::12******756:user/<iam-user>"
},
"Action": [
"s3:*",
"s3:PutObject",
"s3:GetObject",
"s3:DeleteObject",
"s3:*Object"
],
"Resource": [
"arn:aws:s3:::<bucketname>",
"arn:aws:s3:::<bucketname>/*"
]
}
]
}
IAM用户策略:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "VisualEditor0",
"Effect": "Allow",
"Action": [
"s3:GetAccessPoint",
"s3:PutAccountPublicAccessBlock",
"s3:GetAccountPublicAccessBlock",
"s3:ListAllMyBuckets",
"s3:ListAccessPoints",
"s3:ListJobs",
"s3:CreateJob",
"s3:PutObject"
],
"Resource": "*"
},
{
"Sid": "VisualEditor1",
"Effect": "Allow",
"Action": "s3:*",
"Resource": "arn:aws:s3:::*"
},
{
"Sid": "VisualEditor2",
"Effect": "Allow",
"Action": "s3:*",
"Resource": "arn:aws:s3:::*/*"
}
]
}
然而,我仍然看到错误-“调用PutObject操作时发生错误(AccessDenied):拒绝访问”。
任何关于如何解决这个问题的建议都会很有帮助
编辑:在此处添加错误和堆栈跟踪:
Traceback (most recent call last):
File "/Users/se/lib/python3.7/site-packages/boto3/s3/transfer.py", line 279, in upload_file
future.result()
File "/Users/se/lib/python3.7/site-packages/s3transfer/futures.py", line 106, in result
return self._coordinator.result()
File "/Users/se/lib/python3.7/site-packages/s3transfer/futures.py", line 265, in result
raise self._exception
File "/Users/se/lib/python3.7/site-packages/s3transfer/tasks.py", line 126, in __call__
return self._execute_main(kwargs)
File "/Users/se/lib/python3.7/site-packages/s3transfer/tasks.py", line 150, in _execute_main
return_value = self._main(**kwargs)
File "/Users/se/lib/python3.7/site-packages/s3transfer/upload.py", line 692, in _main
client.put_object(Bucket=bucket, Key=key, Body=body, **extra_args)
File "/Users/se/lib/python3.7/site-packages/botocore/client.py", line 276, in _api_call
return self._make_api_call(operation_name, kwargs)
File "/Users/se/lib/python3.7/site-packages/botocore/client.py", line 586, in _make_api_call
raise error_class(parsed_response, operation_name)
botocore.exceptions.ClientError: An error occurred (AccessDenied) when calling the PutObject operation: Access Denied
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "moveToS3.py", line 76, in <module>
main()
File "moveToS3.py", line 65, in main
response = upload_file(file_name, bucket_name, object_name)
File "moveToS3.py", line 39, in upload_file
response = s3_client.upload_file(file_name, bucket, object_name)
File "/Users/se/lib/python3.7/site-packages/boto3/s3/inject.py", line 131, in upload_file
extra_args=ExtraArgs, callback=Callback)
File "/Users/se/lib/python3.7/site-packages/boto3/s3/transfer.py", line 287, in upload_file
filename, '/'.join([bucket, key]), e))
boto3.exceptions.S3UploadFailedError: Failed to upload output1.txt to <bucketname>/01-12-2020 06:54:36 output.txt: An error occurred (AccessDenied) when calling the PutObject operation: Access Denied
我看到,您正在使用upload_file
函数并将file_name、桶和object_key作为该函数的参数。
根据错误日志,bucket的值为
突出问题的错误日志:
boto3.exceptions.上传output1.txt失败
我想让IAM用户可以从S3存储桶下载文件,但在执行
我正在一个项目中工作,目标是从amazon S3获取报告。目前,我正在尝试访问S3位置,以检查我的可用桶列表。 我在python中工作,我已经在提示符下设置了所有凭据:aws configure。 在我的python文件中,当我尝试列出我所有的bucket时: 我得到了这个错误: 回溯(最后一次调用):文件“C:\Users\bakpovo\testAmazon.py”,第3行,在s3中的buck
在此处输入代码:调用ListBucket操作时出错(AccessDenied):拒绝访问 但我有一个IAM策略集,并使用aws CLI和--profile,该配置文件附带了该策略。IAM政策:
我试图在s3中使用boto3创建一个bucket,但收到了ClientError:调用CreateBucket操作时出错(AccessDenied):拒绝访问。 我已经通过aws配置设置了我的aws cli凭据。这是我的权限摘要: 这是我的代码: 我希望能够在不被拒绝访问的情况下创建一个bucket
为什么我不能上传到我的桶里?
问题内容: $ ./mysqladmin -u root -p ‘ 编辑 ‘ 输入密码: mysqladmin:在“ localhost”处连接到服务器失败错误: “对用户“ root” @“ localhost”的访问被拒绝(使用密码:是) 我怎样才能解决这个问题? 问题答案: 打开并编辑或,具体取决于您的发行版。 添加下 重启MySQL 您现在应该可以使用以下命令登录mysql 跑 设置新密码