Skip to content

Commit

Permalink
chore: added Troubleshooting section in AWS PowerShell Lambda Readme …
Browse files Browse the repository at this point in the history
…for enabling Debug output.
  • Loading branch information
ashishdhingra committed Oct 22, 2024
1 parent d0a84f2 commit 6c3ddfc
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions PowerShell/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,25 @@ New-AWSPowerShellLambda|Used to create an initial PowerShell script that is base
Publish-AWSPowerShellLambda|Publishes a given PowerShell script to Lambda.
New-AWSPowerShellLambdaPackage|Creates the Lambda deployment package that can be used in a CI/CD system for deployment.

## Troubleshooting
### Enabling Debug output
In PowerShell, [Write-Debug](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/write-debug?view=powershell-7.4) CmdLet could be used to write debug message to the console. However, by default, debug messages are not displayed in the console, but you can display them by using the **Debug** parameter or the **$DebugPreference** variable.

The default value of [DebugPreference](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_preference_variables?view=powershell-7.4#debugpreference) variable is `SilentlyContinue`, which means the debug message isn't displayed and execution continues without interruption. The `-Debug` parameter could be used to override the `$DebugPreference` value.

Enabling output of `Write-Debug` to CloudWatch logs is a 2 step process:
- In PowerShell Lambda script,
- Either need to set `$DebugPreference = "Continue"` at the beginning of script. Thereafter use `Write-Debug` to output debug messages ; **OR**
- Include `-Debug` parameter while executing `Write-Debug` (e.g.` Write-Debug "Testing Lambda PowerShell Write-Debug" -Debug`).
- At Lambda function level, set the value of `AWS_LAMBDA_HANDLER_LOG_LEVEL` environment variable with value `DEBUG`. This would enable debug logs at Lambda level. This environment variable could be set:
- Either manually in Lambda function configuration in AWS console; **OR**
- While executing CmdLet `Publish-AWSPowerShellLambda`, passing parameter `-EnvironmentVariable @{'AWS_LAMBDA_HANDLER_LOG_LEVEL'='DEBUG'}`.

The value of the `AWS_LAMBDA_HANDLER_LOG_LEVEL` environment variable is set to the values of the [LogLevel](https://github.com/aws/aws-lambda-dotnet/blob/master/Libraries/src/Amazon.Lambda.Core/ILambdaLogger.cs#L7) enum.

The role assigned to Lambda function should have permissions to write to CloudWatch logs.


# Learning Resources

[Lambda Developer Guide](https://docs.aws.amazon.com/lambda/latest/dg/welcome.html)
Expand Down

0 comments on commit 6c3ddfc

Please sign in to comment.