开发者

How to define the principal for an AWS policy statement?

开发者 https://www.devze.com 2023-03-11 04:35 出处:网络
I\'m starting from http://awspolicygen.s3.amazonaws.com/policygen.html to create a policy that will grant upload rights to a specific S3 bucket for a list of users. I\'m not clear on how I define who

I'm starting from http://awspolicygen.s3.amazonaws.com/policygen.html to create a policy that will grant upload rights to a specific S3 bucket for a list of users. I'm not clear on how I define who those users should be.

The docs refer to a principal as "a person or persons" without an example of how to refer to said person(s). One assumes "email address" and the policy generator will accept it, but w开发者_如何学Gohen I paste the generated statement to the bucket policy editor, I get:

Invalid principal in policy - "AWS" : "steve@here.com"

Full statement:

{
  "Id": "myPol",
  "Statement": [
    {
      "Sid": "Stmt130",
      "Action": "s3:*",
      "Effect": "Allow",
      "Resource": "arn:aws:s3:::myBucketName",
      "Principal": {
        "AWS": [
          "steve@here.com"
        ]
      }
    } ]
}


A principal can be another AWS account or an IAM user. These docs are helpful Specifying Principals in Bucket Policies and Integrating IAM with S3


[HttpPost]
public ActionResult Uploaddemo(HttpPostedFileBase file) {
    try {
        IAmazonS3 client;
        using (client = Amazon.AWSClientFactory.CreateAmazonS3Client(_awsAccessKey, _awsSecretKey,RegionEndpoint.USWest2)) {
            var request = new PutObjectRequest() {
                BucketName = _bucketName,
                CannedACL = S3CannedACL.PublicRead, ACCESIBLE
                Key = string.Format("visumes/{0}", file.FileName),
                InputStream = file.InputStream,//SEND THE FILE STREAM
            };

            Amazon.S3.AmazonS3Config s3Config = new Amazon.S3.AmazonS3Config() { 
                ServiceURL = "http://s3.amazonaws.com"  
            };
            string HOST ="http://s3-website-us-west-2.amazonaws.com";
            client.PutObject(request);
        }
    } catch (Exception ex) {

    }
    return View();
}
0

精彩评论

暂无评论...
验证码 换一张
取 消