title: C# with AWS S3 access denied with transfer utility
body: <p>I've been trying for several hours to get this to work and not sure what I'm doing wrong. I have a bucket in US-West Oregon (us-west-2). I have an IAM user with full S3 access. I am attempting to store the contents of a string into a file on S3. Here is the code below:</p>
  
  <pre><code>using System.IO;
  using Amazon;
  
  namespace XXX.Util
  {
  
      public static class S3
      {
  
          private static Amazon.S3.Transfer.TransferUtility transferUtility;
  
          public static void UploadFile(string bucket, string key, string contents)
          {    
              // user "publisher" credentials
              transferUtility = new Amazon.S3.Transfer.TransferUtility("{AccessID}", "{Secret}",RegionEndpoint.USWest2);
  
              using (Stream s = GenerateStreamFromString(contents))
              {
                  using (transferUtility)
                  {
                      transferUtility.Upload(s, bucket, key);
                  }
              }
  
  
          }
          public static Stream GenerateStreamFromString(string s)
          {
              MemoryStream stream = new MemoryStream();
              StreamWriter writer = new StreamWriter(stream);
              writer.Write(s);
              writer.Flush();
              stream.Position = 0;
              return stream;
          }
      }
  }
  </code></pre>
  
  <p>I invoke the method with:</p>
  
  <pre><code>S3.UploadFile("s3-us-west-2.amazonaws.com/{bucket-name}", guid.ToString(),contents);
  </code></pre>
  
  <p>The error message I get is:</p>
  
  <blockquote>
    <p>AmazonS3Exception: Access Denied
    Amazon.Runtime.Internal.HttpErrorResponseExceptionHandler.HandleException(IExecutionContext
    executionContext, HttpErrorResponseException exception) in
    HttpErrorResponseExceptionHandler.cs, line 60</p>
  </blockquote>
  
  <p>My S3 policy:</p>
  
  <blockquote>
    <p>{
        "Version": "2012-10-17",
        "Id": "Policy1516569218147",
        "Statement": [
            {
                "Sid": "Stmt1516569211561",
                "Effect": "Allow",
                "Principal": {
                    "AWS": "arn:aws:iam::{iamID}:user/publisher"
                },
                "Action": "s3:*",
                "Resource": "arn:aws:s3:::{bucket-name}"
            }
        ] }</p>
  </blockquote>
  
  <p>Any ideas?</p>