From 9c8fe4823ce34ce41a024ebfbc9625f5455fff03 Mon Sep 17 00:00:00 2001
From: Ashish Dhingra <67916761+ashishdhingra@users.noreply.github.com>
Date: Thu, 19 Sep 2024 14:51:29 -0700
Subject: [PATCH] Fixes an issue where Write-Debug doesn't log debug messages
to CloudWatch for a Lambda PowerShell function.
---
.../Amazon.Lambda.PowerShellHost.csproj | 2 +-
.../Amazon.Lambda.PowerShellHost/PowerShellFunctionHost.cs | 4 ++++
2 files changed, 5 insertions(+), 1 deletion(-)
diff --git a/Libraries/src/Amazon.Lambda.PowerShellHost/Amazon.Lambda.PowerShellHost.csproj b/Libraries/src/Amazon.Lambda.PowerShellHost/Amazon.Lambda.PowerShellHost.csproj
index 1987e6e5e..f8053a6da 100644
--- a/Libraries/src/Amazon.Lambda.PowerShellHost/Amazon.Lambda.PowerShellHost.csproj
+++ b/Libraries/src/Amazon.Lambda.PowerShellHost/Amazon.Lambda.PowerShellHost.csproj
@@ -6,7 +6,7 @@
net6.0;net8.0
AWS Lambda PowerShell Host.
Amazon.Lambda.PowerShellHost
- 3.0.0
+ 3.0.1
Amazon.Lambda.PowerShellHost
Amazon.Lambda.PowerShellHost
AWS;Amazon;Lambda;PowerShell
diff --git a/Libraries/src/Amazon.Lambda.PowerShellHost/PowerShellFunctionHost.cs b/Libraries/src/Amazon.Lambda.PowerShellHost/PowerShellFunctionHost.cs
index 8cb799dab..ae358459c 100644
--- a/Libraries/src/Amazon.Lambda.PowerShellHost/PowerShellFunctionHost.cs
+++ b/Libraries/src/Amazon.Lambda.PowerShellHost/PowerShellFunctionHost.cs
@@ -148,6 +148,9 @@ private IAsyncResult BeginInvoke(string input, ILambdaContext context)
// Clear all previous PowerShell executions, variables and outputs
this._ps.Commands?.Clear();
this._ps.Streams.Verbose?.Clear();
+ this._ps.Streams.Debug?.Clear();
+ this._ps.Streams.Information?.Clear();
+ this._ps.Streams.Warning?.Clear();
this._ps.Streams.Error?.Clear();
this._ps.Runspace?.ResetRunspaceState();
this._output.Clear();
@@ -292,6 +295,7 @@ private void SetupStreamHandlers()
};
this._ps.Streams.Verbose.DataAdding += _loggerFactory("Verbose");
+ this._ps.Streams.Debug.DataAdding += _loggerFactory("Debug");
this._ps.Streams.Information.DataAdding += _loggerFactory("Information");
this._ps.Streams.Warning.DataAdding += _loggerFactory("Warning");
this._ps.Streams.Error.DataAdding += _loggerFactory("Error");