aws / aws-dotnet-extensions-configuration

This repository hosts various libraries that help developers configure .NET applications using AWS services.

Home Page:https://aws.amazon.com/developer/language/net/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Amazon.Extensions.Configuration.SystemsManager Doesnt Fetch Parameter

nataizya-s opened this issue · comments

When using Amazon.Extensions.Configuration.SystemsManager, parameters are unable to be fetched from SSM. However, using Amazon.SimpleSystemsManagement works perfectly.

Code Snippets:

Amazon.Extensions.Configuration.SystemsManager

using Amazon.Extensions.Configuration.SystemsManager;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using System;

namespace TestParameterStore
{
	class Program
	{
		public static Action<SystemsManagerExceptionContext> OnLoadException { get; set; }
		static void Main(string[] args) => CreateHostBuilder(args).Build().Run();

		public static IWebHostBuilder CreateHostBuilder(string[] args)
		{
			return WebHost.CreateDefaultBuilder(args).ConfigureAppConfiguration(builder =>
			{
				builder.AddSystemsManager(configureSource =>
				{
					configureSource.Path = "/xyz/abc/";
					configureSource.Optional = true;
					configureSource.OnLoadException += OnLoadException;

				});
			})
			.UseStartup<Startup>();
		}
	}
}

Amazon.SimpleSystemsManagement

using System;
using System.Threading.Tasks;
using Amazon.SimpleSystemsManagement;
using Amazon.SimpleSystemsManagement.Model;

namespace TestParameterStore
{
    class Program1
    {
        //static void Main(string[] args) => GetConfiguration().Wait();

        static async Task GetConfiguration()
        {
            // NOTE: set the region here to match the region used when you created
            // the parameter
            var region = Amazon.RegionEndpoint.APSoutheast2;
            var request = new GetParameterRequest()
            {
                Name = "/app/abc/shared/rabbitmq/host"
            };

            using (var client = new AmazonSimpleSystemsManagementClient(region))
            {
                try
                {
                    var response = await client.GetParameterAsync(request);
                    Console.WriteLine($"Parameter {request.Name} value is: {response.Parameter.Value}");
                }
                catch (Exception ex)
                {
                    Console.Error.WriteLine($"Error occurred: {ex.Message}");
                }
            }
        }
    }
}

In addition, the Amazon.Extensions.Configuration.SystemsManager works fine in one environment and fails in another. There is no obvious reason as to why it would fail. On the other hand, Amazon.SimpleSystemsManagement works in both environments perfectly.

Hi,

Got the issue it is due to the fact that library Amazon.Extensions.Configuration.SystemsManager; and its case insensitive, where as Amazon.SimpleSystemsManagement; is case sensitive
In parameter store we had UserName and username. The 2nd library was fetching both of them and the first one was failing after fetching 1 username as it said it already has a username populated.

@mdhapre thanks so much for responding to this! I updated your comment with formatting to make it a little more readable as I think this is the proper answer/solution.

@nataizya-s Did the above fix your problem? Let me know so I can determine if we need to investigate further!

😸 😷

Thanks.Its all fixed. :)