Doing LambdaSharp development with Amazon Linux 2 in Windows Terminal
LambdaSharp builds ReadyToRun packages when used on Amazon Linux 2. This can be achieved by either using an EC2 Linux instance, AWS CodeBuild, or the Windows Subsystem for Linux (WSL). This article describes how to enable and configure WSL for building LambdaSharp modules.
The benefit of ReadyToRun packages is reduced cold start time for Lambda functions, as the assemblies contain pre-compiled native code. However, the pre-compiled native code does not replace the original .NET code. Therefore, ReadyToRun packages are larger than their unoptimized counterparts.
Install Amazon Linux 2 for WSL
- Enable WSL on Windows 10.
- Download the Amazon Linux 2 image for WSL from https://github.com/yosukes-dev/AmazonWSL
- Unzip the Amazon2.zip into a permanent location.
- Run Amazon.exe to extract rootfs and register it with WSL.
Add Amazon Linux 2 to Windows Terminal
Windows Terminal is a terminal emulator for Windows 10 written by Microsoft. It includes support for the Command Prompt, PowerShell, WSL, SSH, and more. The following settings make it trivial to open a bash
shell directly in Amazon Linux 2.
- Open Windows Terminal settings.
- Add the following snippet to Windows Terminal settings. The icon path is assuming Amazon2.zip was extracted into C:\Amazon2 folder.
{ "guid": "{3dffc929-1f2e-44cc-8253-9635e0298f6b}", "hidden": false, "name": "Amazon Linux 2", "commandline": "wsl.exe -d Amazon2", "startingDirectory" : "C:\\", "icon": "C:\\Amazon2\\assets\\AWS-icon.png" }
Install LambdaSharp on Amazon Linux 2
The following steps install .NET Core 3.1, some utilities, and LambdaSharp.
- Open Amazon Linux 2 in Windows Terminal.
- Register the Microsoft package repository.
rpm -Uvh https://packages.microsoft.com/config/centos/7/packages-microsoft-prod.rpm
- Install .NET 5, .NET Core 3.1, and misc. required utilities
yum install -y dotnet-sdk-5.0 dotnet-runtime-5.0 dotnet-sdk-3.1 dotnet-runtime-3.1 git zip
- Install LambdaSharp
dotnet tool install --global LambdaSharp.Tool
(Optional) Install VS Code Remote
Visual Studio Code supports remote development, which allows files to be edited from the VS Code in Windows, while all commands are executed on Amazon Linux 2.
- Open Amazon Linux 2 in Windows Terminal.
- Install utilities required by VS Code Remote extension
yum install -y wget glibc libgcc libstdc++ python ca-certificates tar
- Invoke
code
command to trigger the installation of the VS Code Remote extensioncode
- Click Allow Access when prompted by Windows Defender.