Tuesday, November 17, 2020

AWS Libraries in C# - Hard to Spot Typo in AWS Credentials File

I encountered an error when trying to run a C# command-line utility with `dotnet run`.  The AWS package kept throwing an error, and nothing I did to try to fix it made it work.  Here's the error: 

Unhandled exception. System.TypeInitializationException: The type initializer for 'Amazon.Runtime.Internal.FallbackInternalConfigurationFactory' threw an exception.

 ---> System.IO.InvalidDataException: Line 14:<arn:aws:iam::{{AWS Acct ID}}:role/{{Role Name}}

> in file C:\Users\{{User Name}}\.aws\credentials does not contain a section, property or comment.

After digging into the environment vars on my Windows box, trying to set things in PowerShell, and unsetting whatever I could, a co-worker helped me take a second look at the error.  My credentials file itself had a typo on line 14.  I had chopped off the 'role_arn=' from in front of my developer creds at some time in the past, and this util was the first to try to load it.  Once I fixed up the creds, it ran like a champ.

Preserving this here because googling that exact error didn't help me.