Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reading AWS AppConfig from .NET 6 Lambda Function

I've googled around but with no luck... I need to read some configuration values stored inside a AWS Systems Manager -> AppConfig configuration (stored as text, not flag) but I've not found a C# example... I've also tried on the AWS Console to add the layer as specified here but with no success.

For now I've used a SecretManager but it's not the correct place to store the config information... can someone help me? Thanks

like image 228
advapi Avatar asked Sep 11 '26 07:09

advapi


2 Answers

Since your question is about C# example for AppConfig, you can take a look on https://github.com/ScottHand/AppConfigNETCoreSample/tree/5f5db8d375e4df92dd7dc1b8a16f42bfb042e645. There is interesting issue with .NET client though that https://docs.aws.amazon.com/appconfig/2019-10-09/APIReference/API_GetConfiguration.html is deprecated in favor of StartConfigurationSession and GetLatestConfiguration, however .NET client do not have yet support for these methods https://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/services/appconfig/AmazonAppConfigAsyncClient.html

Recommended approach is though to go with lambda extension, so you can try to open another question with your problem of setting up the extension.

Alternatively you can use SSM Parameter Store which also might be suitable for your Lambda use case.

like image 69
Milan Gatyas Avatar answered Sep 15 '26 06:09

Milan Gatyas


The Amazon.Extensions.Configuration.SystemsManager package might be helpful with what you are trying to achieve. You need to store your configuration as JSON.

This is how it can be implemented using the .NET Core Configuration mechanism.

builder.Configuration.SetBasePath(Environment.CurrentDirectory)
                     .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
                     .AddSystemsManager($"/{builder.Configuration["AwsAppConfig:ApplicationId"]}/", TimeSpan.FromMinutes(5))
                     .AddAppConfigUsingLambdaExtension(builder.Configuration["AwsAppConfig:ApplicationId"], builder.Configuration["AwsAppConfig:EnvironmentId"], builder.Configuration["AwsAppConfig:ConfigurationProfileId"])
                     .Build();

For more information, you can check out the documentation here.

like image 36
Leo Avatar answered Sep 15 '26 06:09

Leo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!