문제

Is there a way to grant a specific IAM user or group full permissions on an AWS S3 file through the AWS PHP SDK?

I've tried the following commands:

// 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'
        )
    )
));

But they always throw the following error:

 Argument format not recognized

Can someone tell me what I'm doing wrong?

Any help would be greatly appreciated.

도움이 되었습니까?

해결책

In the above code you didn't specify the SourceFile, so its throwing the error. Here's the updated code, that will help you solve this problem.

// 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'
      )
    )
 ));
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top