To set up a PowerShell environment with AWS Lambda, you’re going to need to do three things:
• Install PowerShell Core v6 or higher
• Install .NET Core 2.1 (the SDK)
• Install the AWSLambdaPScore PowerShell module
Let’s see how to make it happen!
The first thing we have to do is install PowerShell Core v6 or higher. For this example, I’m going to be installing PowerShell 6.1 because it’s the latest version. You can either download the file with PowerShell or just go to the browser as you normally would. But since this is an article about PowerShell, I will be using PowerShell to do everything.
Once downloading is complete, use the Invoke-WebRequest command. Then, pass in the direct filename of PowerShell 6.1, the 64-bit edition. Finally, save that to your hard drive.
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 $installerFilePath = "$env:TEMP\PSCore61.msi" Invoke-WebRequest -Uri 'https://github.com/PowerShell/PowerShell/releases/download/v6.1.0/PowerShell-6.1.0-win-x64.msi' -OutFile $installerFilePath
Once that’s done, we can install it. Again, we can just go to the installer manually and run it that way, but let’s stay in PowerShell just to make it easier. To do that, for this example, I’m just going to use Start-Process, run msiexec.exe, pass it some arguments — the /i, the file path and /qb to make it quiet, and to show the progress as it goes through.
$procParams = @{ FilePath = 'msiexec.exe' ArgumentList = @('/i', "`"$installerFilePath`"", '/qb') Wait = $true NoNewWindow = $true } Start-Process @procParams
After running the installer, if you didn’t receive any errors, PowerShell Core should be installed.
Next up, let’s install .NET Core 2.1, the SDK.
Microsoft provides a really nice PowerShell script to automate the download and installation of the SDK, so let’s use that.
First, download Microsoft’s dotnet-install PowerShell script using Invoke-WebRequest. The download should be quick.
## Download the installer script $installerFilePath = "$env:TEMP\dotnet-install.ps1" Invoke-WebRequest -Uri 'https://dot.net/v1/dotnet-install.ps1' -OutFile $installerFilePath
Next, we’ll run it by passing a channel of LTS, which the PowerShell script has created with a channel parameter. This essentially is going to provide the latest .NET Core SDK version (long-term-supported).
## Install the latest .NET SDK long-term-supported & $installerFilePath -Channel LTS
It should have downloaded the package and extracted the Zip file.
Now the only thing we have left to do is to install the AWSLambdaPScore module. So let’s first bring up PowerShell Core and run Install-Module to install the AWSLambdaPSCore module.
It will prompt you about an untrusted repository. That’s completely normal; just hit Y for Yes.
Once it finishes with the install, let’s go ahead and make sure it’s installed by running Get-Module.
Get-Module -Name AWSLambdaPSCore -ListAvailable
It looks like the latest version is 1.1.
We have now installed PowerShell Core v6, installed the .NET SDK 2.1, and installed the AWSLambdaPScore PowerShell module. That’s everything it takes to get a development environment set up for running PowerShell in AWS Lambda!