I've been trying to figure this out for some time now and just cannot get it to work. I'm working on a web application where I'll have a user that needs to upload files to an S3 bucket and then other users will be able to view that content from the bucket. I've been trying to get the bucket upload to work with no avail. Here's the policies that I've set in IAM and S3 for my app/bucket:

Bucket:

{ "Version": "2012-10-17", "Id": "Policy1488494182833", "Statement": [ { "Sid": "Stmt1488493308547", "Effect": "Allow", "Principal": { "AWS": "arn:aws:iam::614222560511:user/NuRenAppUser" }, "Action": "s3:*", "Resource": [ "arn:aws:s3:::nu-ren-bucket", "arn:aws:s3:::nu-ren-bucket/*" ] } ] }

IAM User:

{ "Version": "2012-10-17", "Statement": [ { "Sid": "FullAccessS3", "Effect": "Allow", "Action": "s3:*", "Resource": [ "arn:aws:s3:::nu-ren-bucket" ] } ] }

I have my credentials in the .aws folder and the S3 client is picking them up just fine. The only issue with the credentials I'm not sure about is that there's a field when debugging that says "token" that's not being populated, but most of the documentation that I've seen just instructs to put in the two keys and the region, which I have set correctly. Here is my code:

ASP.Net Core 2.1 Web Api:

using Amazon.Runtime; using Amazon.S3; using Amazon.S3.Transfer; using Amazon.S3.Model; using Microsoft.AspNetCore.Http; using NuRen.Services.Abstractions; using NuRen.Services.Models; using System; using System.Collections.Generic; using System.IO; using System.Text; using System.Threading.Tasks; namespace NuRen.Services.Repositories { public class VideoRepository : IVideoRepository { private IAmazonS3 _s3Client; public VideoRepository(IAmazonS3 s3Client) { _s3Client = s3Client; } public async Task<Guid> SaveVideo(IFormFile file, Video newVideo) { Stream fileStream = file.OpenReadStream(); var request = new PutObjectRequest(); request.BucketName = "nu-ren-bucket"; request.Key = newVideo.ID.ToString(); request.InputStream = fileStream; request.ContentType = file.ContentType; request.CannedACL = S3CannedACL.PublicRead; var response = await _s3Client.PutObjectAsync(request); //var uploadrequest = new TransferUtilityUploadRequest() //{ // InputStream = fileStream, // Key = newVideo.ID.ToString(), // BucketName = "nu-ren-bucket", // CannedACL = S3CannedACL.PublicRead //}; return newVideo.ID; } } }

I know my model says video but I've just been testing with small files just to get it to work, so I know the size is not the issue. The code you see commented out is what I have tried before everything else and I keep getting the same issue:

Error:

An unhandled exception occurred while processing the request. HttpErrorResponseException: Exception of type 'Amazon.Runtime.Internal.HttpErrorResponseException' was thrown. Amazon.Runtime.HttpWebRequestMessage.GetResponseAsync(CancellationToken cancellationToken) in HttpRequestMessageFactory.cs, line 539 AmazonS3Exception: Access Denied Amazon.Runtime.Internal.HttpErrorResponseExceptionHandler.HandleException(IExecutionContext executionContext, HttpErrorResponseException exception) in HttpErrorResponseExceptionHandler.cs, line 60 Stack Query Cookies Headers HttpErrorResponseException: Exception of type 'Amazon.Runtime.Internal.HttpErrorResponseException' was thrown. Amazon.Runtime.HttpWebRequestMessage.GetResponseAsync(CancellationToken cancellationToken) in HttpRequestMessageFactory.cs Amazon.Runtime.Internal.HttpHandler<TRequestContent>.InvokeAsync<T>(IExecutionContext executionContext) in HttpHandler.cs Amazon.Runtime.Internal.RedirectHandler.InvokeAsync<T>(IExecutionContext executionContext) Amazon.Runtime.Internal.Unmarshaller.InvokeAsync<T>(IExecutionContext executionContext) Amazon.S3.Internal.AmazonS3ResponseHandler.InvokeAsync<T>(IExecutionContext executionContext) Amazon.Runtime.Internal.ErrorHandler.InvokeAsync<T>(IExecutionContext executionContext) Show raw exception details AmazonS3Exception: Access Denied Amazon.Runtime.Internal.HttpErrorResponseExceptionHandler.HandleException(IExecutionContext executionContext, HttpErrorResponseException exception) in HttpErrorResponseExceptionHandler.cs Amazon.Runtime.Internal.ErrorHandler.ProcessException(IExecutionContext executionContext, Exception exception) in ErrorHandler.cs Amazon.Runtime.Internal.ErrorHandler.InvokeAsync<T>(IExecutionContext executionContext) in ErrorHandler.cs Amazon.Runtime.Internal.CallbackHandler.InvokeAsync<T>(IExecutionContext executionContext) Amazon.Runtime.Internal.EndpointDiscoveryHandler.InvokeAsync<T>(IExecutionContext executionContext) Amazon.Runtime.Internal.EndpointDiscoveryHandler.InvokeAsync<T>(IExecutionContext executionContext) in EndpointDiscoveryHandler.cs Amazon.Runtime.Internal.CredentialsRetriever.InvokeAsync<T>(IExecutionContext executionContext) in CredentialsRetriever.cs Amazon.Runtime.Internal.RetryHandler.InvokeAsync<T>(IExecutionContext executionContext) Amazon.Runtime.Internal.RetryHandler.InvokeAsync<T>(IExecutionContext executionContext) in RetryHandler.cs Amazon.Runtime.Internal.CallbackHandler.InvokeAsync<T>(IExecutionContext executionContext) Amazon.Runtime.Internal.CallbackHandler.InvokeAsync<T>(IExecutionContext executionContext) Amazon.S3.Internal.AmazonS3ExceptionHandler.InvokeAsync<T>(IExecutionContext executionContext) Amazon.Runtime.Internal.ErrorCallbackHandler.InvokeAsync<T>(IExecutionContext executionContext) Amazon.Runtime.Internal.MetricsHandler.InvokeAsync<T>(IExecutionContext executionContext) NuRen.Services.Repositories.VideoRepository.SaveVideo(IFormFile file, Video newVideo) in VideoRepository.cs + var response = await _s3Client.PutObjectAsync(request); NuRen.Services.Services.VideoService.UploadVideo(IFormFile file) in VideoService.cs + return await _vr.SaveVideo(file, newVideo); NuRenApp.Controllers.VideoController.UploadVideo(IFormFile file) in VideoController.cs + return await _vs.UploadVideo(file); lambda_method(Closure , object ) Microsoft.Extensions.Internal.ObjectMethodExecutorAwaitable+Awaiter.GetResult() Microsoft.AspNetCore.Mvc.Internal.ActionMethodExecutor+AwaitableObjectResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, object controller, object[] arguments) System.Threading.Tasks.ValueTask<TResult>.get_Result() Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeActionMethodAsync() Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeNextActionFilterAsync() Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Rethrow(ActionExecutedContext context) Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(ref State next, ref Scope scope, ref object state, ref bool isCompleted) Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeInnerFilterAsync() Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeNextResourceFilter() Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow(ResourceExecutedContext context) Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Next(ref State next, ref Scope scope, ref object state, ref bool isCompleted) Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeFilterPipelineAsync() Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeAsync() Microsoft.AspNetCore.Builder.RouterMiddleware.Invoke(HttpContext httpContext) Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context) Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Invoke(HttpContext context) Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore.MigrationsEndPointMiddleware.Invoke(HttpContext context) Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore.DatabaseErrorPageMiddleware.Invoke(HttpContext httpContext) Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore.DatabaseErrorPageMiddleware.Invoke(HttpContext httpContext) Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)

I've tried different combinations of code, policies and keys and nothing has worked. Completely stuck at this point.