I am getting s3 error: An error occurred (AccessDenied) when calling the ListBuckets operation: Access Denied

I am getting s3 error: An error occurred (AccessDenied) when calling the ListBuckets operation: Access Denied

enter code here获取:调用ListBuckets操作时发生错误(AccessDenied):Access Denied

但我设置了 IAM 策略,并使用带有附加策略的 --profile 的 aws CLI。 IAM 政策:

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "VisualEditor0",
            "Effect": "Allow",
            "Action": "s3:ListBucket",
            "Resource": "arn:aws:s3:::my-repository"
        },
        {
            "Sid": "VisualEditor1",
            "Effect": "Allow",
            "Action": [
                "s3:GetObjectAcl",
                "s3:GetObject",
                "s3:GetObjectTagging",
                "s3:DeleteObject"
            ],
            "Resource": "arn:aws:s3:::my-repository/data/*"
        }
    ]
}

aws --profile my-repository s3 ls

An error occurred (AccessDenied) when calling the ListBuckets operation: Access Denied

您需要以下 IAM 权限才能执行 aws s3 ls:

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": "s3:ListAllMyBuckets",
            "Resource": "*"
        }
    ]
}
{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "VisualEditor0",
            "Effect": "Allow",
            "Action": "s3:ListBucket",
            "Resource": "arn:aws:s3:::my-repository"
        },
        {
            "Sid": "VisualEditor1",
            "Effect": "Allow",
            "Action": "s3:ListAllMyBuckets",
            "Resource": "*"
        },
        {
            "Sid": "VisualEditor2",
            "Effect": "Allow",
            "Action": [
                "s3:GetObjectAcl",
                "s3:GetObject",
                "s3:GetObjectTagging",
                "s3:DeleteObject"
            ],
            "Resource": "arn:aws:s3:::my-repository/data/*"
        }
    ]
}