亚马逊s3推出了存储桶策略

时间:2012-04-04 13:06:28

标签: php curl amazon-s3 amazon policy

我正在尝试添加一个桶policys我正在阅读亚马逊s3文档。 http://docs.amazonwebservices.com/AmazonS3/latest/dev/setpolicyonbucket.html

在文档中说它运行此代码。

PUT /?policy HTTP/1.1
Host: bucket.s3.amazonaws.com  
Date: Tue, 04 Apr 2010 20:34:56 GMT  
Authorization: AWS AKIAIOSFODNN7EXAMPLE:VGhpcyBSAMPLEBieSBlbHZpbmc= 

{
"Version":"2008-10-17",
"Id":"aaaa-bbbb-cccc-dddd",
"Statement" : [
    {
        "Effect":"Allow",
        "Sid":"1", 
        "Principal" : {
            "AWS":["1111-2222-3333","4444-5555-6666"]
        },
        "Action":["s3:GetObject*"],
        "Resource":"arn:aws:s3:::mybucket/*"
    }
 ] 
}

这正是我需要做的,我正在努力的是我如何运行php curl请求来执行此操作我从哪里开始?这是新的,因为直到现在我一直在使用亚马逊s3类。

由于

1 个答案:

答案 0 :(得分:0)

是您要找的方法setAccessControlPolicy?它允许您像上面的示例一样设置访问控制。来自文档:

  

setAccessControlPolicy(string $ bucket,[string $ uri =''],[array   $ acp = array()])返回页首

     

在$ uri =''

时设置对象或存储桶的访问控制策略      

示例:

<?php

    if (($acp = S3::getAccessControlPolicy($bucket, $uri)) !== false) {
        // Here you would modify the $acp array...
        // For example, grant access to the S3 LogDelivery system:
        $acp["acl"][] = array(
            "type" => "Group", "uri" => "http://acs.amazonaws.com/groups/s3/LogDelivery", "permission" => "WRITE"
        );
        $acp["acl"][] = array(
            "type" => "Group", "uri" => "http://acs.amazonaws.com/groups/s3/LogDelivery", "permission" => "READ_ACP"
        );
        // Then update the policy using the modified $acp array:
        if (S3::setAccessControlPolicy($bucket, $uri, $acp)) {
            echo "Policy updated";
        }
    }
?>