forked from awsdocs/aws-doc-sdk-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paths3BucketAcl.php
More file actions
78 lines (69 loc) · 2.08 KB
/
s3BucketAcl.php
File metadata and controls
78 lines (69 loc) · 2.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?php
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
/*
* ABOUT THIS PHP SAMPLE: This sample is part of the SDK for PHP Developer Guide topic at
* https://docs.aws.amazon.com/sdk-for-php/v3/developer-guide/s3-examples-access-permissions.html
*
*/
// snippet-start:[s3.php.put_bucket_acl.complete]
// snippet-start:[s3.php.put_bucket_acl.import]
require 'vendor/autoload.php';
use Aws\Exception\AwsException;
use Aws\S3\S3Client;
// snippet-end:[s3.php.put_bucket_acl.import]
// Create a S3Client
// snippet-start:[s3.php.put_bucket_acl.main]
$s3Client = new S3Client([
'profile' => 'default',
'region' => 'us-west-2',
'version' => '2006-03-01'
]);
// Gets the access control policy for a bucket
$bucket = 'amzn-s3-demo-bucket';
try {
$resp = $s3Client->getBucketAcl([
'Bucket' => $bucket
]);
echo "Succeed in retrieving bucket ACL as follows: \n";
var_dump($resp);
} catch (AwsException $e) {
// output error message if fails
echo $e->getMessage();
echo "\n";
}
// Sets the permissions on a bucket using access control lists (ACL).
$params = [
'ACL' => 'public-read',
'AccessControlPolicy' => [
// Information can be retrieved from `getBucketAcl` response
'Grants' => [
[
'Grantee' => [
'DisplayName' => '<string>',
'EmailAddress' => '<string>',
'ID' => '<string>',
'Type' => 'CanonicalUser',
'URI' => '<string>',
],
'Permission' => 'FULL_CONTROL',
],
// ...
],
'Owner' => [
'DisplayName' => '<string>',
'ID' => '<string>',
],
],
'Bucket' => $bucket,
];
try {
$resp = $s3Client->putBucketAcl($params);
echo "Succeed in setting bucket ACL.\n";
} catch (AwsException $e) {
// Display error message
echo $e->getMessage();
echo "\n";
}
// snippet-end:[s3.php.put_bucket_acl.main]
// snippet-end:[s3.php.put_bucket_acl.complete]