Contains examples, analysis and learnings of basic AWS Lambda functions implemented following the different AWS templates for .NET 7
Explore each solution and make sure to read the README.md
file containing the analysis.
This repository is based on:
- Windows 10
- PowerShell 7
- Visual Studio Code
- .NET7 Runtime and SDK
Login or create a new Amazon AWS account.
- Go to IAM
- Go to Users
- Go to Create Users
- Choose a name, maybe something like
devawscli
or\<your-name\>vs
- Choose a password (May want to uncheck the change password on first login)
- Click Next
- Choose a name, like
DevOps
orAdminDev
orDevelopers
- Assign AdminAccess policy
- Clikc Create
- Store the username, the password, the access key, the secret access key and the console URL.
- Download the csv.
- Click Close
- Open PowerShell as admin
- Look for the latest version of Python 3:
winget search “python 3”
- Install latest version of Python 3:
winget install Python.Python.3.12
- Install AWS CLI:
winget install Amazon.AWSCLI
- Close PowerShell
- Run:
aws configure
- Enter the access key you stored
- Enter the secret access key you stored
- Choose a default session (maybe look for the cheaper one, like
us-west-1
) - Do not establish an output format, just click Enter
- Run:
aws s3 ls
- Install the AWSToolkitforVisualStudio2022
- Open Visual Studio
- The AWS Explorer pane should be now visible on the left. Otherwise use the View menu to open it.
- Install the AWS CLI extensions for dotnet:
dotnet tool install -g Amazon.Lambda.Tools
- Install the AWS Templates:
dotnet new -i Amazon.Lambda.Templates
- List lambda templates:
dotnet new list Lambda
The easiest way is to just debug from Visual Studio
, which will launch a browser window with a page to test the lambda.
For automation reasons, use the tool used by VS to run a lambda. Look into the launchProperties.json
and you will find all you need:
"commandLineArgs": "--port 5050",
"workingDirectory": ".\\bin\\$(Configuration)\\net7.0",
"executablePath": "%USERPROFILE%\\.dotnet\\tools\\dotnet-lambda-test-tool-7.0.exe"
Make sure to dotnet build
or unit test dotnet test
your lambda beforehand, so that it creates the necessary files in /bin
.
- Open PowerShell
- Go to the root folder of your lambda
- For autpmation, avoid launching a window with
--no-launch-window
- Run the tool as:
PS \MyFunctionName\src\MyFunctionName> C:\Users\MY-USER-NAME\.dotnet\tools\dotnet-lambda-test-tool-7.0.exe --port 5050 --no-launch-window
More info on the tool: https://github.com/aws/aws-lambda-dotnet/blob/master/Tools/LambdaTestTool/README.md