我遵循了教程 http://docs.aws.amazon.com/athena/latest/ug/connect-with-jdbc.html。我设置了一个 IAM 用户(具有奇怪的权限)和一个 S3 存储桶,可以查询示例 Athena 表,并将输出写入我的 S3 存储桶。 现在我有了客户的凭据来访问他的 Athena 表。这不起作用,我收到以下错误:
将输出写入 url 时访问被拒绝: s3://my-test-bucket/b36-f3c0-482-a225-34d63d355.txt 。请确保 您可以访问 S3 存储桶。如果您正在加密查询 结果与 KMS 密钥,请确保您有权访问您的 KMS 钥匙
我的 S3 存储桶是公开的。 “任何经过身份验证的 AWS 用户”的权限:读取、写入。 “每个人”的权限:读、写。 “日志传送”的权限:读、写。 一切的“权限访问”:读、写
Bucket 策略允许每个人做所有事情。
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": "*",
"Action": "s3:ListBucket",
"Resource": "arn:aws:s3:::my-test-bucket"
},
{
"Effect": "Allow",
"Principal": "*",
"Action": [
"s3:PutObject",
"s3:GetObject",
"s3:DeleteObject"
],
"Resource": "arn:aws:s3:::my-test-bucket/*"
},
{
"Sid": "AddPerm",
"Effect": "Allow",
"Principal": "*",
"Action": [
"s3:GetObject",
"s3:PutObject"
],
"Resource": "arn:aws:s3:::my-test-bucket/*"
}
] }
CORS配置:
<?xml version="1.0" encoding="UTF-8"?> <CORSConfiguration
xmlns="http://s3.amazonaws.com/doc/2006-03-01/"> <CORSRule>
<AllowedOrigin>*</AllowedOrigin>
<AllowedMethod>PUT</AllowedMethod>
<AllowedMethod>POST</AllowedMethod>
<AllowedMethod>DELETE</AllowedMethod>
<AllowedHeader>*</AllowedHeader> </CORSRule> </CORSConfiguration>
仍然出现错误:将输出写入 url 时访问被拒绝...
编辑:有时我会收到另一个错误:“无法验证/创建输出存储桶 my-test-bucket”。不知道为什么我会收到不同的错误。
我能做什么?
s3 上的特定文件也有几乎类似的问题。我无法读取该文件。通过使用 mv 命令和
--acl
参数更改文件的访问权限解决了该问题。尝试访问名为 data.jsonlines
的文件时出现 ACCESS DENIED
错误。通过运行以下命令解决了这个问题:
注意:您需要安装 AWS CLI:
$ pip install --upgrade --user awscli
aws s3 cp s3://<s3 bucket name>/path/to/file/data.jsonlines s3://cfa-opengazettes-ke/gazettes/data_copy.jsonlines
aws s3 mv --acl public-read s3://<s3 bucket name>/path/to/file/data_copy.jsonlines s3://cfa-opengazettes-ke/gazettes/data.jsonlines
或者您可以通过运行来组合它们:
aws s3 cp s3://<s3 bucket name>/path/to/file/data_out.jsonlines s3://cfa-opengazettes-ke/gazettes/data_out2.jsonlines && aws s3 mv --acl public-read s3://cfa-opengazettes-ke/gazettes/data_out2.jsonlines s3://<s3 bucket name>/path/to/file/data_out.jsonlines
这些命令执行以下步骤:
复制:
s3://<s3 bucket name>/path/to/file/data.jsonlines
到
s3://c<s3 bucket name>/path/to/file/data_copy.jsonlines
移动:
s3://<s3 bucket name>/path/to/file/data_copy.jsonlines
到
s3://cfa-opengazettes-ke/path/to/file/data.jsonlines
基本上,它会创建文件的副本,然后在移动过程中删除它,同时更改文件的权限。
注意
--acl
选项和参数 public-read
。也许以下权限之一适合您。您可以将 public-read
替换为其他权限。来自文档:
--acl(字符串)执行命令时设置对象的 ACL。如果您使用此参数,您必须具有 “s3:PutObjectAcl”权限包含在您的操作列表中 IAM 政策。仅接受 private、public-read 的值, 公共读-写、经过身份验证的读、aws-exec-读、 bucket-owner-read、bucket-owner-full-control 和 log-delivery-write。
此 AWS 页面
有一些更有用的信息