Skip to content

This new PowerShell custom runtime for AWS Lambda makes it even easier to run Lambda functions written in PowerShell to process events.

License

Notifications You must be signed in to change notification settings

awslabs/aws-lambda-powershell-runtime

PowerShell Runtime for AWS Lambda

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.

Overview

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.

PowerShell custom runtime benefits

  • 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.

Development Requirements

Testing

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.

Building and Deploying

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.

Project Structure

Examples

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

Runtime Information

See the PowerShell-runtime documentation for detailed information on runtime variables, handler options, context objects, module support, logging, and error handling.

Acknowledgements

This custom runtime builds on the work of Norm Johanson, Kevin Marquette, Andrew Pearce, Afroz Mohammed, and Jonathan Nunn.

Security

See CONTRIBUTING for more information.

License

This project is licensed under the Apache-2.0 License.

About

This new PowerShell custom runtime for AWS Lambda makes it even easier to run Lambda functions written in PowerShell to process events.

Topics

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •