amazon-web-services - 尽管权限 = 允许所有,但拒绝从 Athena 访问 S3 存储桶

标签 amazon-web-services amazon-s3 amazon-athena

我跟着教程http://docs.aws.amazon.com/athena/latest/ug/connect-with-jdbc.html .我设置了一个 IAM 用户(具有奇怪的权限)和一个 S3 存储桶,并且可以查询示例 Athena 表并将输出写入我的 S3 存储桶。
现在我有来自客户的凭据来访问他的 Athena 表。这不起作用,我收到以下错误:

Access denied when writing output to url: s3://my-test-bucket/b36-f3c0-482-a225-34d63d355.txt . Please ensure you are allowed to access the S3 bucket. If you are encrypting query results with KMS key, please ensure you are allowed to access your KMS key



我的 S3-bucket 是公开的。
“任何经过身份验证的 AWS 用户”的权限:读取、写入。
“每个人”的权限:读、写。
“日志传送”的权限:读、写。
一切的“权限访问”:读、写

桶策略允许每个人做任何事情。

{
 "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.jsonliness3://c<s3 bucket name>/path/to/file/data_copy.jsonlines
  • 移动:s3://<s3 bucket name>/path/to/file/data_copy.jsonliness3://cfa-opengazettes-ke/path/to/file/data.jsonlines

  • 基本上,它会创建文件的副本,然后在移动过程中删除它,同时更改文件的权限。

    请注意 --acl选项和参数 public-read .也许以下权限之一对您有用。您可以更换 public-read得到另一个许可。来自 documentation :

    --acl (string) Sets the ACL for the object when the command is performed. If you use this parameter you must have the "s3:PutObjectAcl" permission included in the list of actions for your IAM policy. Only accepts values of private, public-read, public-read-write, authenticated-read, aws-exec-read, bucket-owner-read, bucket-owner-full-control and log-delivery-write.



    一些更有用的信息在此 AWS page

    关于amazon-web-services - 尽管权限 = 允许所有,但拒绝从 Athena 访问 S3 存储桶,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44759904/

    相关文章:

    hadoop - Hadoop和Amazon EMR/S3中每个文件的单独输出

    amazon-web-services - AWS Athena 扁平化嵌套 JSON 源中的数据

    amazon-web-services - AWS Glue 下推谓词无法正常工作

    amazon-web-services - 如何真正快速地从 Amazon SQS(简单队列服务)队列中删除事件?

    Laravel 如何下载目录中的所有文件

    python - 客户端错误 : An error occurred (AccessDenied) when calling the ListObjects operation: Access Denied

    sql - 如何有效地将新数据附加到 AWS Athena 中的表中?

    amazon-web-services - AWS 雅典娜错误 : INTERNAL_ERROR_QUERY_ENGINE on CREATE TABLE

    networking - aws 实例不允许端口 80 进入我的机器

    python - BOTO3 - `put_object` 的generate_presigned_url 返回 `The request signature we calculated does not match the signature you provided`