Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/amazon-s3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Amazon web services ec2 can';t访问同一存储桶中的另一个s3文件_Amazon Web Services_Amazon S3 - Fatal编程技术网

Amazon web services ec2 can';t访问同一存储桶中的另一个s3文件

Amazon web services ec2 can';t访问同一存储桶中的另一个s3文件,amazon-web-services,amazon-s3,Amazon Web Services,Amazon S3,我有一个S3存储桶和一个EC2,角色可以访问该存储桶。ec2可以访问s3://mybucket/folderA/file1,但不能访问s3://mybucket/folderB/file2。我似乎不明白为什么我可以从ec2实例访问file1而不能访问file2。当我尝试像这样下载file2时: aws s3 cp s3://mybucket/folderB/file2/home/ec2 user/file2 我得到这个错误: 致命错误:调用HeadObject操作时发生错误(403):禁止 但我

我有一个S3存储桶和一个EC2,角色可以访问该存储桶。ec2可以访问
s3://mybucket/folderA/file1
,但不能访问
s3://mybucket/folderB/file2
。我似乎不明白为什么我可以从ec2实例访问file1而不能访问file2。当我尝试像这样下载file2时:

aws s3 cp s3://mybucket/folderB/file2/home/ec2 user/file2

我得到这个错误:

致命错误:调用HeadObject操作时发生错误(403):禁止

但我在下载文件1时没有收到该错误:

aws s3 cp s3://mybucket/folderA/file1/home/ec2 user/file1

----编辑------

我错过了403错误…所以我想问题是为什么它没有看到文件

----编辑-----

这是我的政策

{
    "Version": "1-1-1",
    "Id": "Policy111111111",
    "Statement": [
        {
            "Sid": "Sxxxxxxx1234",
            "Effect": "Deny",
            "Principal": "*",
            "Action": "s3:GetObject",
            "Resource": [
                "arn:aws:s3:::mybucket",
                "arn:aws:s3:::mybucket/*"
            ],
            "Condition": {
                "StringNotEquals": {
                    "aws:sourceVpc": "vpc-a8xxxxx"
                }
            }
        },
        {
            "Sid": "RequiredEncryptedPutObject",
            "Effect": "Deny",
            "Principal": "*",
            "Action": "s3:PutObject",
            "Resource": "arn:aws:s3:::mybucket/*",
            "Condition": {
                "StringNotEquals": {
                    "s3:x-amz-server-side-encryption": [
                        "AES256",
                        "aws:kms"
                    ]
                }
            }
        }
    ]
}

可能完全不相关,但是你知道s3在没有这样的文件时返回403吗(而不是404)?不…我完全错过了…虽然文件在那里…所以我想问题是为什么它没有看到文件?@user3707125不太清楚。如果对象不存在且您没有列表权限,则返回403。如果对象不存在,但您有列表权限,则返回404。因此,它没有看到对象,并且我没有
folderB
的权限,那么?要么对象存在,而您没有获取该对象的权限。或者该对象不存在,并且您没有列出该对象的权限。