0

The following code works from a Console application, but does not work when running this same code from a Windows Service. We've made sure the User Account that is running the Serice is permissioned, but unfortunately we still get the error message below.

Are there any options can try for troubleshooting this, or why we might be getting this error from a Service.

    var awsOptions = new AWSOptions() {
         Region = Amazon.RegionEndpoint.USEast1,
         ProfilesLocation = "E:\\AWS\\credentials"
    };
    var buckets = await awsOptions.CreateServiceClient<Amazon.S3.IAmazonS3> ().ListBucketsAsync(default);
    Console.WriteLine(string.Join(Environment.NewLine, buckets.Buckets.Select(x => x.BucketName)));

Error Message...

Amazon.Runtime.AmazonServiceException Unable to get IAM security credentials from EC2 Instance Metadata Service.

Amazon.Runtime.AmazonServiceException: Unable to get IAM security credentials from EC2 Instance Metadata Service. at Amazon.Runtime.DefaultInstanceProfileAWSCredentials.FetchCredentials() at Amazon.Runtime.DefaultInstanceProfileAWSCredentials.GetCredentials() at Amazon.Runtime.DefaultInstanceProfileAWSCredentials.GetCredentialsAsync() at Amazon.Runtime.Internal.CredentialsRetriever.InvokeAsync[T](IExecutionContext executionContext) at Amazon.Runtime.Internal.RetryHandler.InvokeAsync[T](IExecutionContext executionContext) at Amazon.Runtime.Internal.RetryHandler.InvokeAsync[T](IExecutionContext executionContext) at Amazon.Runtime.Internal.CallbackHandler.InvokeAsync[T](IExecutionContext executionContext) at Amazon.Runtime.Internal.CallbackHandler.InvokeAsync[T](IExecutionContext executionContext) at Amazon.S3.Internal.AmazonS3ExceptionHandler.InvokeAsync[T](IExecutionContext executionContext) at Amazon.Runtime.Internal.ErrorCallbackHandler.InvokeAsync[T](IExecutionContext executionContext) at Amazon.Runtime.Internal.MetricsHandler.InvokeAsync[T](IExecutionContext executionContext) at Gaige.Job.Testing.ConfigurationTestJob.TestJob() in C:\Users\gmarx\source\repos\institutional-claims\Gaige.Job\Testing\ConfigurationTestJob.cs:line 53 at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor) at System.Reflection.MethodInvoker.Invoke(Object obj, IntPtr* args, BindingFlags invokeAttr)

Glenn
  • 166
  • 5
  • hello, looks like this https://stackoverflow.com/questions/60815037/aws-dotnet-sdk-error-unable-to-get-iam-security-credentials-from-ec2-instance-m – clay Jul 20 '23 at 18:29

1 Answers1

0

This is in conjunction with a Hangfire server for the Service. It failed when trying to inject the credential, but it succeeds when instantiating from inside the Service. This is the workaround we were able to find for it for now.

var credentials = new Amazon.Runtime.ProcessAWSCredentials("e:\\aws_signing_helper.exe credential-process --certificate ...");
Amazon.S3.IAmazonS3 s3Client = new Amazon.S3.AmazonS3Client(credentials, Amazon.RegionEndpoint.USEast1);
Glenn
  • 166
  • 5