You can build .NET-based Lambda applications using the Lambda plugin to the AWS Toolkit for Visual Studio. The toolkit is available as a Visual Studio extension.
-
Launch Microsoft Visual Studio and choose New project.
-
From the File menu, choose New, and then choose Project.
-
In the New Project window, choose AWS Lambda Project (.NET Core), and then choose OK.
-
In the Select Blueprint window, you can select from a list of sample applications that provide you with sample code to get started with creating a .NET-based Lambda application.
-
To create a Lambda application from scratch, choose Empty Function, and then choose Finish.
-
-
Review the
aws-lambda-tools-defaults.json
file, which is created as part of your project. You can set the options in this file, which the Lambda tooling reads by default. The project templates created in Visual Studio set many of these fields with default values. Note the following fields:-
profile – The name of a profile in your AWS SDK for .NET credentials file
-
function-handler – This is where the
function handler
is specified, which is why you don't have to set it in the wizard. However, whenever you rename the Assembly, Namespace, Class, or Function in your function code, you must update the corresponding fields in theaws-lambda-tools-defaults.json
file.{ "profile":"default", "region" : "us-east-2", "configuration" : "Release", "framework" : "netcoreapp2.1", "function-runtime":"dotnetcore3.1", "function-memory-size" : 256, "function-timeout" : 30, "function-handler" : "Assembly::Namespace.Class::Function" }
-
-
Open the Function.cs file. You are provided with a template to implement your Lambda function handler code.
-
Once you have written the code that represents your Lambda function, upload it by opening the context (right-click) menu for the Project node in your application and then choosing Publish to AWS Lambda.
-
In the Upload Lambda Function window, enter a name for the function, or select a previously published function to republish. Then choose Next.
-
In the Advanced Function Details window, configure the following options:
- Role Name (required) – The AWS Identity and Access Management (IAM) role that Lambda assumes when it runs your function.
- Environment – Key-value pairs that Lambda sets in the execution environment. To extend your function's configuration outside of code, use environment variables.
- Memory – The amount of memory available to the function at runtime. Choose an amount between 128 MB and 10,240 MB in 1-MB increments.
- Timeout – The amount of time that Lambda allows a function to run before stopping it. The default is three seconds. The maximum allowed value is 900 seconds.
- VPC – If your function needs network access to resources that are not available over the internet, configure it to connect to a virtual private cloud (VPC).
- DLQ – If your function is invoked asynchronously, choose a dead-letter queue to receive failed invocations.
- Enable active tracing – Sample incoming requests and trace sampled requests with AWS X-Ray.
-
Choose Next, and then choose Upload to deploy your application.
For more information, see Deploying an AWS Lambda Project with the .NET Core CLI.