JED
JED

Reputation: 1694

.NET 6 web app on IIS - How to store AWS credentials

I am creating a new app that I want to run on my local IIS. I would expect it to pull my default credentials from %USER_PROFILE%/.aws/credentials but whenever I try to access an AWS resource, it says that my credentials are empty.

I'm guessing the credentials in my AWS Toolkit are unavailable because the app is running outside of IIS Express. I also tried adding appsettings to my web.config (see below) but that didn't work.

<appSettings>
  <add key="AWSProfileName" value="default" />
  <add key="AWSProfileLocation" value="%USERPROFILE%/.aws/credentials" />
</appSettings>

I also tried adding the AWS_SHARED_CREDENTIALS_FILE, AWS_PROFILE, and AWS_DEFAULT_REGION environment variables to my site via the IIS via the Configuration Editor, but no dice.

I was able to get it to work by adding the environment variables AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, and AWS_DEFAULT_REGION to my web.config, but I don't really want to do that (for risk of a developers credentials being put into our git repo.)

Is there something that I'm missing?

My site in IIS:

enter image description here

My app pool in IIS:

enter image description here

The permissions on the directory that contains the app:

enter image description here

Upvotes: 1

Views: 900

Answers (1)

Rippo
Rippo

Reputation: 22424

Lots options, one which worked for me in past

in web.config

<add key="AWSProfileName" value="dev" />
<add key="AWSProfilesLocation" value="D:\projects\keys\aws-api-keys.txt" />

or

<add key="AWSProfileName" value="live" />

and in keys file

[live]
aws_access_key_id=123456
aws_secret_access_key=ABCD1234
[dev]
aws_access_key_id=7654321
aws_secret_access_key=ABCFR434

and in code you just need to create a connection like this

var sqs = new AmazonSQSClient(regionEndpoint);

and AWS sniffs out the keys for you

see https://aws.amazon.com/blogs/developer/referencing-credentials-using-profiles/ for more info Alternative Credentials File at bottom of webpage

Upvotes: 1

Related Questions