Question

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.

Était-ce utile?

La solution

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'
      )
    )
 ));
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top