These instructions is a part of a live coding video.
- .NET Core 3.1 SDK - https://dotnet.microsoft.com/download
- Install the AWS CLI - https://aws.amazon.com/pt/cli/
- Install AWS templates for .NET CLI
- Install AWS Lambda Tools for .NET CLI
- Configure your AWS Access Key via AWS CLI
- AWS account and security credential (
AWS Access Key ID
/AWS Secret Access Key
) - AWS security credential with role
AWSLambdaFullAccess
- AWS security credential with role
IAMFullAccess
(optional)
dotnet new -i Amazon.Lambda.Templates
dotnet tool install -g Amazon.Lambda.Tools
or
dotnet tool update -g Amazon.Lambda.Tools
aws configure
AWS Access Key ID: <your access key id>
AWS Secret Access Key: <your secret access key>
{
"profile": "",
// Default region in the deployment, if empty, will need to inform during deployment
"region": "us-east-2",
"configuration": "Release",
"framework": "netcoreapp3.1",
"function-name": "LambdaForProject1",
"function-runtime": "dotnetcore3.1",
"function-memory-size": 256,
"function-timeout": 30,
// SolutionName::Namespace.ClassName::HandlerMethod
"function-handler": "Project1::Project1.Function::FunctionHandler"
}
Create a base folder LambdaProjects
.
Create the .gitignore
file based on file https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
dotnet new lambda.EmptyFunction --name Project1
cd Project1\test\Project1.Tests
dotnet test
cd Project1\src\Project1
dotnet lambda deploy-function
Enter AWS Region: (The region to connect to AWS services, if not set region will be detected from the environment.)
us-east-2
Enter Function Name: (AWS Lambda function name)
LambdaForProject1
Enter name of the new IAM Role:
or
Select IAM Role that to provide AWS credentials to your code:
1) *** Create new IAM Role ***
Enter name of the new IAM Role:
role-for-my-lambda-functions
Select IAM Policy to attach to the new role and grant permissions
1) AWSLambdaFullAccess (Provides full access to Lambda, S3, DynamoDB, CloudWatch Metrics and ...)
cd Project1\src\Project1
dotnet lambda invoke-function LambdaForProject1 --payload "Angelito Casagrande"
If you haven´t directly access to AWS, you can send a .zip with the publish package.
cd Project1\src\Project1
dotnet lambda package
Output file: Project1\src\Project1\bin\Release\netcoreapp3.1\Project1.zip
dotnet new lambda.S3 --name Project2
cd Project2\src\Project2
# Adding ImageMagick package
dotnet add package Magick.NET-Q8-AnyCPU
context.Logger.LogLine("I am here");
https://docs.aws.amazon.com/lambda/latest/dg/lambda-csharp.html