This template can provide a PowerShell developer with a faster feedback loop when developing a PowerShell Lambda function.
Quickly iterate development of PowerShell Lambda functions using this template workflow.
This workflow uses AWS Serverless Application Module (SAM) template to describe the Lambda function as an application. The template can then be transformed, deployed, updated, and torn down quickly via command line, enabling the developer to observe and receive feedback quickly.
Deploy.ps1: TheDeploy.ps1script will deploy the PowerShell Lambda application using the AWS SAM model.serverless.template: Theserverless.templateis the SAM (CloudFormation) template that describes the AWS Lambda.PowerShellLambda.ps1: ThePowerShellLambda.ps1, which will be renamed by Plaster as the Lambda name, is the PowerShell Lambda code.plasterManifest.xml: TheplasterManifest.xmlcontains the Plaster construct that transforms the template into actual project folder structures.
- .Net Core SDK
- AWS CLI
- PowerShell Core 6
- PowerShell modules:
- Plaster- Plaster is a template-based file and project generator similar to Yeoman
- AWSPowerShell.NetCore
- AWSLambdaPSCore
Assuming you already have:
- Pre-created S3 bucket in the target AWS account.
- Already configured the AWSPowerShell.NetCore and AWS CLI credentials/ profiles/ default regions.
- AWS PowerShell - Using AWS Credentials
- AWS CLI - Configuring the AWS CLI
Once you have the prerequisites ready, use the following steps to create a new PowerShell SAM Lambda project using the template.
NOTE: make sure you have the AWS credential configured for both AWS PowerShell and AWS CLI.
-
Open the
PowerShell Core 6console. -
Type the following command and press enter:
Invoke-Plaster -TemplatePath 'C:\Code\PowerShell-Lambda-Template' -DestinationPath C:\Code\MyHelloWorldLambda
-
You will be prompted for a Lambda name, S3 bucket name. Please provide answers.
(Hint: Press
Ctrl-Cto stop) -
You should see output similar to the following:
-
Navigate to the
C:\Codefolder. It will contain the following folder and file structure. The descriptions are in the brackets.C:\Code \---MyHelloWorldLambda (from the -Destination of Invoke-Plaster) \---HelloWorld (The lambda name) Deploy.ps1 (The PowerShell Script for code deployemnt) HelloWorld-serverless.template (SAM template) HelloWorld.ps1 (The actual PowerShell Lambda code) -
Open the
HelloWorldfolder in Visual Studio Code. -
The
HelloWorld.ps1contains the basic PowerShell Code to output environmental variables. -
Open the
Deploy.ps1file -
Make sure you have
PowerShell 6.xselected on the bottom right. This ensures we are using PowerShell Core 6 in the VSCode's Integrated Console. -
Press
Ctrl + F5to deploy the default Lambda to the AWS account (using default region).NOTE: make sure you have the AWS credential configured for both AWS PowerShell and AWS CLI.
-
Now, you can iterate quickly with:
- update the
HelloWorld.ps1with the code you want. - Go to
Deploy.ps1 - Press
Ctrl + F5to update the Lambda, test, observe and repeat.
- update the
If in VSCode, run the Deploy.ps1 file using Ctrl+F5. F8 or select and run won't work.