Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in AWS by (1.4k points)
edited by

I have created a policy that will grant upload permissions to a certain S3 bucket for a list of users. I started at http://awspolicygen.s3.amazonaws.com/policygen.html.

How can I define the users? I referred to docs it states ‘ a person or persons’ but unclear about how to refer to a person(s). Another assumes ‘email address’ where the policy generator will accept that and then I have pasted the generated statement to the bucket policy editor but I’m getting " Invalid principal in policy - "AWS": "[email protected]" ".

Here is the full statement:

{

  "Id": "myPol",

  "Statement": [

    {

      "Sid": "Stmt130",

      "Action": "s3:*",

      "Effect": "Allow",

      "Resource": "arn:aws:s3:::myBucketName",

      "Principal": {

        "AWS": [

          "[email protected]"

        ]

      }

    } ]

}

Please suggest me any solution. 

1 Answer

0 votes
by (2.6k points)
edited by

Kindly once again refer the AWS s3 Policy Document and try the following code:

[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();

}

Hope this helps. 

If you need help mastering the AWS Cloud platform from the basics to the most advanced level, consider enrolling in AWS Certification Course to help you achieve your goal.

Related questions

Want to get 50% Hike on your Salary?

Learn how we helped 50,000+ professionals like you !

0 votes
1 answer
0 votes
1 answer

Browse Categories

...