This PowerShell custom runtime for AWS Lambda enables running Lambda functions written in PowerShell to process events.
Your code runs in an Amazon Linux environment that includes AWS credentials from an AWS Identity and Access Management (IAM) role that you manage.
Lambda has supported running PowerShell since 2018. However, the existing solution uses the .NET Core runtime implementation for PowerShell. It uses the additional AWSLambdaPSCore modules for deployment and publishing, which require compiling the PowerShell code into C# binaries to run on .NET. This adds additional steps to the development process.
This runtime uses Lambda's custom runtime functionality based on the provided.al2023
runtime.
-
Native PowerShell. This runtime uses native PowerShell.
- The function runtime environment matches a standard PowerShell session, which simplifies the development and testing process.
- No compilation step required and no hosting on the .NET runtime.
- Allows additional functionality, such as
Add-Type
to provide richer context information.
-
Code visibility. You can view and edit PowerShell code within the Lambda console's built-in code editor when using .zip archive functions (not container images). You can embed PowerShell code within an AWS CloudFormation template, or other infrastructure as code tools.
-
Output. This custom runtime returns everything placed on the pipeline as the function output, including the output of
Write-Output
.This gives you more control over the function output, error messages, and logging. With the previous .NET runtime implementation, your function returns only the last output from the PowerShell pipeline. Unhandled exceptions are caught by the runtime, then they are logged to the log stream and a error result is returned to the caller.
- PowerShell 7.0 or later for development and testing
- Download from: https://github.com/PowerShell/PowerShell/releases
- Required for development tools and test suite
The runtime includes unit tests and integration tests:
- Unit Tests: Automated tests covering runtime functions and build processes
- Integration Tests: Manual tests with real AWS Lambda functions for end-to-end validation
See powershell-runtime/tests/README.md for testing documentation and commands.
You can build the custom runtime using AWS SAM or other infrastructure-as-code tools. Deploy the example demo-runtime-layer-function to explore how the runtime works.
See powershell-runtime/README.md for detailed deployment instructions.
- powershell-runtime/ - Custom runtime implementation and deployment methods
- powershell-modules/ - Pre-built PowerShell modules (AWS Tools, VMware PowerCLI)
- examples/ - Demo applications showing runtime functionality
Example | Description |
---|---|
demo-runtime-layer-function | Complete runtime layer with AWS Tools and multiple handler options |
demo-s3-lambda-eventbridge | Event-driven application processing S3 files with EventBridge |
demo-container-image-all-aws-sdk | Container image deployment with full AWS SDK |
demo-container-images-shared | Shared container layers for multiple functions |
See the PowerShell-runtime documentation for detailed information on runtime variables, handler options, context objects, module support, logging, and error handling.
This custom runtime builds on the work of Norm Johanson, Kevin Marquette, Andrew Pearce, Afroz Mohammed, and Jonathan Nunn.
See CONTRIBUTING for more information.
This project is licensed under the Apache-2.0 License.