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

fv-ian/aws-lambda-powershell-runtime

 
 

Repository files navigation

PowerShell Runtime for AWS Lambda

This new PowerShell custom runtime for AWS Lambda makes it even easier to run 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 new runtime uses Lambda's custom runtime functionality based on the provided.al2 runtime.

PowerShell custom runtime benefits

  • Native PowerShell. This new 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 now also view and edit PowerShell code within the Lambda console's built-in code editor. 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.

Building, deploying, and invoking PowerShell Lambda functions

You can build the custom runtime using a number of tools, including the the AWS Command Line Interface (AWS CLI), or with infrastructure as code tools such as AWS CloudFormation, AWS Serverless Application Model (AWS SAM), Serverless Framework, and AWS Cloud Development Kit (AWS CDK).

Deploy the example demo-runtime-layer-function to explore how the runtime and PowerShell function work.

Contains the PowerShell custom runtime based on provided.al2 with a number of deployment methods.

Contains a number of PowerShell modules you can build and add to your functions.

Module Description
AWSToolsforPowerShell AWS Tools for PowerShell
VMwarePowerCLI VMware PowerCLI

Contains a number of demo applications to show the PowerShell runtime functionality.

Initial demo application demo-runtime-layer-function uses AWS SAM to deploy the following:

  1. PowerShell custom runtime based on provided.al2 as a Lambda layer.

  2. Additional Lambda layer including the AWSTools for PowerShell with the following module.

    • AWS.Tools.Common
  3. Both layers store their Amazon Resource Names (ARNs) as parameters in AWS Systems Manager Parameter Store which can be referenced in other templates

  4. Lambda function with three different handler options.

Example Description
demo-runtime-layer-function All-in-one Powershell runtime layer, AWS Tools for PowerShell layer, Lambda function with all three handler options
demo-s3-lambda-eventbridge Demo to show an event-drive application in PowerShell. Copy .CSV file to S3 which triggers PowerShell Lambda function which parses the file. Sends each file line as an event to EventBridge which writes it to CLoudWatch Logs.

Powershell runtime information

See the PowerShell-runtime page for more information on how the runtime works, including:

  • Variables
  • Lambda handler options
  • Lambda context object in PowerShell
  • PowerShell module support
  • Function logging and metrics
  • Function errors

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.

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • PowerShell 76.5%
  • C# 13.3%
  • Makefile 10.2%