2

Application is not able to talk to AWS Parameter Store in .NET 6. It is always talking to appsettings.json.

I tried debugging locally, still same behavior. Not able to find the SystemManagerConfiguration under list of configuration .

enter image description here

var builder = WebApplication.CreateBuilder();
var connectionString = builder.Configuration.GetConnectionString("OrderTrackerDatabase");

enter image description here

Packages Used

enter image description here

Library Source Code : https://github.com/aws/aws-dotnet-extensions-configuration

image

2
  • You need to .Build() after you finish configuring Commented Mar 3, 2022 at 5:19
  • you mean do .Build() after adding system manager? builder.AddSystemsManager("/OrderTracking/", TimeSpan.FromSeconds(30)); builder.Build() ; Commented Mar 3, 2022 at 5:23

5 Answers 5

1

I got the same issue and finally resolved it. The samples code in https://github.com/aws/aws-dotnet-extensions-configuration missed one line as below after called "AddSystemsManager" method in .Net 6.

builder.Services.Configure<Settings>(builder.Configuration.GetSection($"common:settings"));

After added above line, then I'm able to get the correct values from AWS Parameter Store when using the settings.

I've also created an issue of this in GitHub as below - https://github.com/aws/aws-dotnet-extensions-configuration/issues/114

Sign up to request clarification or add additional context in comments.

2 Comments

have u checked this solution? stackoverflow.com/a/71332859/4520493
Thanks @VireshMathad, my project and the sample project don't use database connection, so this solution is not relevant for our issue. I've created a PR as below in the source code repo for resolving the issue I encountered, it's very similar with this one but slightly different, might be useful for other developers who got the same issue. github.com/aws/aws-dotnet-extensions-configuration/pull/115
0

I believe the problem might be the trailing slash after "/OrderTracking/", try "/OrderTracking" instead.

5 Comments

not really, tried both. Slash doesn't matter. While debugging, Configuration Manager should show SystemManagerConfiguration but it isn't. It is not getting added.
I'm talking about image 2 in the post btw
Got ya. Didn't know the behavior of it if it "doesn't exist". Where are you adding the json files? How come it's not in the same place? Is it possible you don't have the same IConfigurationRoot @ that point in time? Maybe post a bit more of the code?
I'm sorry, I do not understand. I'm not adding any new json file, the config is present in the appsettings.json. This is the C# library package which I'm using - github.com/aws/aws-dotnet-extensions-configuration
Thanks Tim for taking a look. I figured the root cause - stackoverflow.com/a/71332859/4520493
0

WebApplication.CreateBuilder() will create new instance and doesn't carry over the SystemManager configuration.

Instead, use IConfiguration instance through constructor DI.

 var connectionString = _configuration.GetConnectionString("OrderTrackerDatabase");

Comments

0

In my case this extensions method was returning null at my lambda:

private static IConfiguration InitializeConfiguration() => new ConfigurationBuilder()
        .AddSystemsManager($"/my-data", true, TimeSpan.FromMinutes(5))
        .Build();

Because the role of lambda didn't have permission for read SSM for that resource.

User: is not authorized to perform: ssm:GetParametersByPath on resource

So, just add necessary permission (ssm:GetParametersByPath) for the role of lambda to your resource at System Manager.

Comments

0

In my case, I am using lambda serverless, so the IConfig is always null when it is passed to the controller.

I resolved it by changing the IOptions<Settings> settings in the Controller constructor to IConfiguration settings and then access the parameters by name like _settings.GetValue<string>("ParameterName")

A little less "Object Oriented", but it seemed much easier than this complex solution

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.