Aws-sdk-net: `GetAWSOptions` support AWS credentials?

Created on 21 Jul 2020  路  8Comments  路  Source: aws/aws-sdk-net

Can I load credentials from the GetAWSOptions() file?

Hi,
I want to set all AWS configuration variables in my appsettings.json file, since we can insert env. variables from our release definitions into that, which is the ultimate goal.
I saw this blog post today and it kinda works. Meaning I can load profile and region just fine. However, the Credentials of my options are always null. Is that intended?

Again, my appsettings.json looks something like:

{
  "AWS": {
    "Profile": "default",
    "Region": "us-east-1",
    "AccessKey": "__REPLACE_WITH_KEY__",
    "SecretKey": "__REPLACE_WITH_SECRET__",
    "SessionToken":"__REPLACE_WITH_TOKEN__"
  }
}

Is it possible to load these with the Configuration.GetAWSOptions function?

Related: #499 #680

closed-for-staleness guidance modulsdk-core

All 8 comments

We have not implemented that feature because we want to encourage the use of profiles instead of embedding credentials directly into appsettings.X.json file where they would accidentally get checked into source control.

Understood. Thanks for clarification..

Are there any good/best practices on how to get a profile/aws-config file into a release? Because as you mentioned, just checking it in wouldn't really be an option...

By release do you mean being deployed to AWS or deployed on premise in an environment that doesn't have access to user profiles?

Yes, exactly. On-prem deployments (in our case with IIS)

What I would recommend is write a credentials file that is accessible to the IIS process and then use the ProfilesLocation property to point to that credentials file during your release builds.

{
  "AWS": {
    "Profile": "prod",
    "ProfilesLocation": "C:\\OnPremiseProfiles\\credential",
    "Region": "us-east-1"
  }
}
 "AWS": {
    "Profile": "prod",
    "ProfilesLocation": "C:\\OnPremiseProfiles\\credential",
    "Region": "us-east-1"
  }

Hi, does someone can help me? I have created my json file config (development) as follow:

{
  "AWS": {
    "Profile": "default",
    "ProfilesLocation": "C:\\Users\\myuser\\.aws\\credential",
    "Region": "sa-east-1"
  }
}

and then I tried this: var awsConfig = Configuration.GetAWSOptions(); but my awsConfig variable is always null.

@Jass91 Are you sure that you can get the values from your appsettings.Jason confit file? E.g. like:

c# configuration.GetValue<string>("AWS:Region")

From what I know, GetAWSOptions only works for region and profile. I solved the problem by overriding the environment vars directly from the source code.

@Jass91 Are you sure that you can get the values from your appsettings.Jason confit file? E.g. like:

configuration.GetValue<string>("AWS:Region")

From what I know, GetAWSOptions only works for region and profile. I solved the problem by overriding the environment vars directly from the source code.

Thanks for your help and sorry, i wrote wrong, I mean, when a call GetAWSOptions, I have Region and Profile, but credencials object is always null.

Was this page helpful?
0 / 5 - 0 ratings