Open
Description
Describe the bug
I have an ASP.NET application deployed on ECS Fargate, and I want to use SSM for data protection. I also use XRay for tracing. When the application starts, it fails because it can't read SSM (even though I setup the correct IAM permissions in the task's role).
Expected Behavior
The application should start normally.
Current Behavior
The following exceptions are thrown:
An error occurred while reading the key ring.
Stack Trace:
Amazon.XRay.Recorder.Core.Exceptions.EntityNotAvailableException: Entity doesn't exist in AsyncLocal
File "/_/sdk/src/Core/Internal/Context/AsyncLocalContextContainer.netstandard.cs", line 45, col 17, in Entity AsyncLocalContextContainer.GetEntity()
File "/_/sdk/src/Core/AWSXRayRecorderImpl.cs", line 968, col 13, in Entity AWSXRayRecorderImpl.GetEntity()
File "/_/sdk/src/Handlers/AwsSdk/Internal/XRayPipelineHandler.cs", line 312, col 17, in void XRayPipelineHandler.ProcessBeginRequest(IExecutionContext executionContext)
File "/_/sdk/src/Core/Internal/Context/TraceContextImpl.cs", line 71, col 17, in void TraceContextImpl.HandleEntityMissing(IAWSXRayRecorder recorder, Exception e, string message)
File "/_/sdk/src/Handlers/AwsSdk/Internal/XRayPipelineHandler.cs", line 316, col 17, in void XRayPipelineHandler.ProcessBeginRequest(IExecutionContext executionContext)
File "/_/sdk/src/Handlers/AwsSdk/Internal/XRayPipelineHandler.cs", line 695, col 17, in async Task<T> XRayPipelineHandler.InvokeAsync<T>(IExecutionContext executionContext)
?, in async Task<T> CallbackHandler.InvokeAsync<T>(IExecutionContext executionContext)
?, in async Task<T> ErrorCallbackHandler.InvokeAsync<T>(IExecutionContext executionContext)
?, in async Task<T> MetricsHandler.InvokeAsync<T>(IExecutionContext executionContext)
?, in async Task<IReadOnlyCollection<XElement>> SSMXmlRepository.GetAllElementsAsync()
?, in IReadOnlyCollection<XElement> SSMXmlRepository.GetAllElements()
?, in IReadOnlyCollection<IKey> XmlKeyManager.GetAllKeys()
?, in CacheableKeyRing KeyRingProvider.CreateCacheableKeyRingCore(DateTimeOffset now, IKey keyJustAdded)
?, in CacheableKeyRing KeyRingProvider.Microsoft.AspNetCore.DataProtection.KeyManagement.Internal.ICacheableKeyRingProvider.GetCacheableKeyRing(DateTimeOffset now)
?, in IKeyRing KeyRingProvider.GetCurrentKeyRingCore(DateTime utcNow, bool forceRefresh)
Error calling SSM to get parameters starting with /MyApp/DataProtection/: Entity doesn't exist in AsyncLocal
Stack Trace:
?, in void Logger.Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func<TState, Exception, string> formatter)+LoggerLog(LogLevel logLevel, EventId eventId, ILogger logger, Exception exception, Func<TState, Exception, string> ...
?, in void Logger.Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func<TState, Exception, string> formatter)
?, in void Logger<T>.Microsoft.Extensions.Logging.ILogger.Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func<TState, Exception, string> formatter)
?, in void LoggerExtensions.Log(ILogger logger, LogLevel logLevel, EventId eventId, Exception exception, string message, params object[] args)
?, in void LoggerExtensions.LogError(ILogger logger, string message, params object[] args)
?, in async Task<IReadOnlyCollection<XElement>> SSMXmlRepository.GetAllElementsAsync()
?, in void AsyncMethodBuilderCore.Start<TStateMachine>(ref TStateMachine stateMachine)
?, in Task<IReadOnlyCollection<XElement>> SSMXmlRepository.GetAllElementsAsync()
?, in bool ThreadPoolWorkQueue.Dispatch()
?, in void WorkerThread.WorkerThreadStart()
?, in void Thread.StartCallback()
Reproduction Steps
void ConfigureServices(WebApplicationBuilder builder)
{
AWSXRayRecorder.InitializeInstance(builder.Configuration);
AWSSDKHandler.RegisterXRayForAllServices();
builder.Services.AddDataProtection()
.SetApplicationName(applicationName: "MyApp")
.PersistKeysToAWSSystemsManager(parameterNamePrefix: "/MyApp/DataProtection");
}
AWS .NET SDK and/or Package version used
Amazon.AspNetCore.DataProtection.SSM 3.0.0
Targeted .NET Platform
.NET 6
Operating System and version
Docker image mcr.microsoft.com/dotnet/aspnet:6.0