Powershell Functions in AWS SAM Local

AWSTemplateFormatVersion : '2010-09-09'Transform: AWS::Serverless-2016-10-31
Resources:
VoteSpacesTabs:
Type: "AWS::Serverless::Function"
Properties:
Runtime: python3.8
Handler: lambda_function.lambda_handler
Policies: AmazonDynamoDBFullAccess
Environment:
Events:
Vote:
Type: Api
Properties:
Path: /
Method: get
import os
import json
def lambda_handler(event, context):
print(event)
return {'body': "testing!"}
AWSTemplateFormatVersion : '2010-09-09'Transform: AWS::Serverless-2016-10-31
Resources:
VoteSpacesTabs:
Type: "AWS::Serverless::Function"
Properties:
Runtime: dotnetcore3.1
CodeUri: ./src/MyFunction/
Handler: MyFunction::MyFunction.Function::FunctionHandler
Policies: AmazonDynamoDBFullAccess
Environment:
Events:
Vote:
Type: Api
Properties:
Path: /
Method: get
New-AWSPowerShellLambda -ScriptName MyFirstPSScript -Template Basic
#Requires -Modules @{ModuleName='AWS.Tools.Common';ModuleVersion='4.0.5.0'}write-host "Hello world!!!";Write-Host (ConvertTo-Json -InputObject $LambdaInput -Compress -Depth 5);
# throw "this is an exception!";
return "hello world!";
New-AWSPowerShellLambdaPackage -ScriptPath .\MyFirstPSScript.ps1 -OutputPackage myfirstscripts.zip
AWSTemplateFormatVersion : '2010-09-09'Transform: AWS::Serverless-2016-10-31
Resources:
VoteSpacesTabs:
Type: "AWS::Serverless::Function"
Properties:
Runtime: dotnetcore3.1
CodeUri: myfirstscript
Handler: MyFirstPSScript::MyFirstPSScript.Bootstrap::ExecuteFunction
Policies: AmazonDynamoDBFullAccess
Environment:
Events:
Vote:
Type: Api
Properties:
Path: /
Method: get
Resources:
VoteSpacesTabs:
Type: AWS::Serverless::Function
Properties:
Timeout: 300
Runtime: dotnetcore3.1
.....
  1. Install your tools (.NET, AWS Sam, SAM local, and any dependencies)
  2. Create an example sam local python function because it’s easy
  3. Create an example powershell function
  4. Package it into a zip using New-AWSPowershellLambdaPackage
  5. Unzip it so you have access to it from SAM
  6. Update your template.yaml to point to it
  7. Run away!

Should you do this

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Brian Olson

Brian Olson

Engineer, formerly at Amazon, currently at Google. All opinions are my own. Consider supporting here: https://devblabs.medium.com/membership