question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Duplicate SSM parameter with different Case cause the whole SSM parameter fail to load

See original GitHub issue

Describe the bug

If we have duplicate SSM parameters with different case like below, the whole SSM parameters not added to the config at all.

  • /dotnet-aws-samples/systems-manager-sample/OracleConnectionString
  • /dotnet-aws-samples/systems-manager-sample/ORACLECONNECTIONSTRING
  • /dotnet-aws-samples/systems-manager-sample/oracleconnectionstring

note: this is applicable, because AWS SSM parameter names are case sensitive.

this is because of the code in DefaultParameterProcessor, that doesn’t take into consideration is edge case.

Expected Behavior

Just ignore the duplicate SSM parameter and continue, or load the latest duplicate SSM parameters , or even throw error, that will be acceptable too (when configureSource.Optional = true).

Current Behavior

silently ignores ALL the SSM parameters and not add any of them to the config.

Reproduction Steps

to reproduce, setup the sample project, and add below parameters to the AWS SSM , and use configureSource.Optional = true

configurationBuilder.AddSystemsManager(configureSource =>
                        {
               configureSource.Path = "/your/path/here"; 
               configureSource.Optional = true;
})
  • /dotnet-aws-samples/systems-manager-sample/sampleone
  • /dotnet-aws-samples/systems-manager-sample/SAMPLEONE
  • /dotnet-aws-samples/systems-manager-sample/SampleOne

reload the project, you will not find any config value coming from AWS SSM at all.

Possible Solution

this pull request should have the fix #145 summary we just add 2 lines of code in DefaultParameterProcessor.cs file, to prevent duplicated keys and take first one only instead of throw error

                .GroupBy(parameter => parameter.Key, StringComparer.OrdinalIgnoreCase)
                .ToDictionary(group => group.Key, group => group.First().Value, StringComparer.OrdinalIgnoreCase);

So the final method will be like that

        public virtual IDictionary<string, string> ProcessParameters(IEnumerable<Parameter> parameters, string path)
        {
            return parameters
                .Where(parameter => IncludeParameter(parameter, path))
                .Select(parameter => new
                {
                    Key = GetKey(parameter, path),
                    Value = GetValue(parameter, path)
                })                
                .GroupBy(parameter => parameter.Key, StringComparer.OrdinalIgnoreCase)
                .ToDictionary(group => group.Key, group => group.First().Value, StringComparer.OrdinalIgnoreCase);
        }

Additional Information/Context

No response

AWS .NET SDK and/or Package version used

“AWSSDK.AppConfigData” Version=“3.7.0.23” “AWSSDK.Extensions.NETCore.Setup” Version=“3.7.1” “AWSSDK.SimpleSystemsManagement” Version=“3.7.12.9” “Microsoft.Extensions.Configuration” Version=“2.0.*”

Targeted .NET Platform

net6.0

Operating System and version

AmazonLinux, and MacOs 13.3.1

Issue Analytics

  • State:open
  • Created 5 months ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
normjcommented, May 12, 2023

@malah-code I debated the same thing about Optional but if you look at the docs for the AddJson method here it says the Optional property means “Whether the file is optional.”. I’m interpreting that as it is optional the file exists not that it should ignore errors with the file. Which seems to prove true because when I make my appsettings.Development.json file have unparseable JSON I get the error Failed to load configuration file <file>. So following that pattern I think it is safe for us to throw exceptions if the data coming back from SSM is invalid like duplicate keys.

0reactions
malah-codecommented, Jul 7, 2023

Just a proposed solution to provide Tolerant Implementation in case of duplicate parameters that may located in SSM with different CASE (like \Path1\Param1 and \path1\param1 , only first one will be taken). . this is like additional option for user to use instead of the DefaultParameterProcessor by using

        public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
            WebHost.CreateDefaultBuilder(args)
                .ConfigureAppConfiguration(builder =>
                {
                    builder.AddSystemsManager(config => {
                        config.Path = "/my-application/";
                        config.ParameterProcessor = new TolerantDefaultParameterProcessor();
                    });
                })
                .UseStartup<Startup>();
Read more comments on GitHub >

github_iconTop Results From Across the Web

Issues · aws/aws-dotnet-extensions-configuration
Duplicate SSM parameter with different Case cause the whole SSM parameter fail to load bug This issue is a bug. ; Support for...
Read more >
Why am I getting an error when querying SSM parameters ...
The parameter name must begin with a forward slash "/". It can't be prefixed with "aws" or "ssm" (case-insensitive). It must use only...
Read more >
Troubleshooting Parameter Store - AWS Systems Manager
Problem: You ran a command to create an aws:ec2:image parameter, but parameter creation failed. You receive a notification from Amazon EventBridge that ...
Read more >
Cloudformation ssm parameter. Wait until the Designer loads ...
Parameter Store is a capability from AWS Systems Manager used to store configuration data and secrets in a easy way. To workaround this,...
Read more >
Parameter Store UI is terrible : r/aws
One use case we have for SSM is the ability to change log levels for all services in one place. So we notice...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found