I'm developing a web api using .NET Core 2 on a Windows laptop. I'm trying to access my S3 bucket and am getting an Access Denied error.
Interesting thing is that it works with the AWS CLI.
My appSettings.Development.json file:
"AWS": {
"Profile": "my-profile",
"Region": "us-east-1"
}
Startup.cs file:
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
var options = Configuration.GetAWSOptions();
services.AddDefaultAWSOptions(Configuration.GetAWSOptions());
services.AddAWSService<IAmazonS3>();
}
BucketController.cs file:
public async Task<IEnumerable<string>> Get()
{
// List all objects
ListObjectsRequest listRequest = new ListObjectsRequest
{
BucketName = "shel-bucket"
};
ListObjectsResponse listResponse;
do
{
// Get a list of objects
listResponse = await _client.ListObjectsAsync(listRequest);
foreach (S3Object obj in listResponse.S3Objects)
{
Console.WriteLine("Object - " + obj.Key);
Console.WriteLine(" Size - " + obj.Size);
Console.WriteLine(" LastModified - " + obj.LastModified);
Console.WriteLine(" Storage class - " + obj.StorageClass);
}
// Set the marker property
listRequest.Marker = listResponse.NextMarker;
} while (listResponse.IsTruncated);
return null;
}
The error I get is AmazonS3Exception: Access Denied.
When I do it from the AWS CLI it works.
aws --profile my-profile s3 ls shel-bucket
PRE test1/
PRE images/
PRE projects/
PRE test4/
My credentials and confil files are in the default location in .aws.