通过AWS PHP SDK向AWS S3文件授予IAM用户权限

时间:2014-04-18 13:54:46

标签: php amazon-web-services amazon-s3 amazon-iam

有没有办法通过AWS PHP SDK在AWS S3文件上授予特定的IAM用户或组完全权限?

我尝试过以下命令:

// Grant permissions via user id
$s3->putObjectAcl(array(
    'Bucket'       => '[Bucket name]',
    'Key'          => '[File location in bucket]',
    'Grants' => array(
        array(
            'Grantee' => array(
                'ID' => '[User ID from IAM API]',
                'Type' => 'CanonicalUser'
            ),
            'Permission' => 'FULL_CONTROL'
        )
    )
));

// Grant permissions via group id
$s3->putObjectAcl(array(
    'Bucket'       => '[Bucket name]',
    'Key'          => '[File location in bucket]',
    'Grants' => array(
        array(
            'Grantee' => array(
                'ID' => '[Group ID from IAM API]',
                'Type' => 'Group'
            ),
            'Permission' => 'FULL_CONTROL'
        )
    )
));

但他们总是抛出以下错误:

 Argument format not recognized

有人能告诉我我做错了吗?

非常感谢任何帮助。

1 个答案:

答案 0 :(得分:1)

在上面的代码中,你没有指定SourceFile,所以抛出错误。这是更新的代码,可以帮助您解决此问题。

// Grant permissions via user id
 $s3->putObjectAcl(array(
      'Bucket'       => '[Bucket name]',
      'Key'          => '[File location in bucket]',
      'SourceFile'   => '[File to be uploaded location]',   // add this line
      'Grants' => array(
         array(
             'Grantee' => array(
             'ID' => '[User ID from IAM API]',
             'Type' => 'CanonicalUser'
         ),
             'Permission' => 'FULL_CONTROL'
      )
    )
 ));