Deploying an Amazon Lambda Project with the .NET Core CLI - Amazon Toolkit for Visual Studio
Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions, see Getting Started with Amazon Web Services in China (PDF).

Deploying an Amazon Lambda Project with the .NET Core CLI

The Amazon Toolkit for Visual Studio includes Amazon Lambda .NET Core project templates for Visual Studio. You can deploy Lambda functions built in Visual Studio using the .NET Core command line interface (CLI).

Prerequisites

Before working with .NET Core CLI to deploy Lambda functions, you must meet the following prerequisites:

The following related topics can be helpful as you use the .NET Core CLI to deploy Lambda functions:

  • For more information about Lambda functions, see What is Amazon Lambda? in the Amazon Lambda Developer Guide.

  • For information about creating Lambda functions in Visual Studio, see Amazon Lambda.

  • For more information about Microsoft .NET Core, see .NET Core in Microsoft's online documentation.

Listing the Lambda Commands Available through the .NET Core CLI

To list the Lambda commands that are available through the .NET Core CLI, do the following.

  1. Open a command prompt window, and navigate to the folder containing a Visual Studio .NET Core Lambda project.

  2. Enter dotnet lambda --help.

C:\Lambda\AWSLambda1\AWSLambda1>dotnet lambda --help Amazon Lambda Tools for .NET Core functions Project Home: https://github.com/aws/aws-lambda-dotnet . Commands to deploy and manage Lambda functions: . deploy-function Deploy the project to Lambda invoke-function Invoke the function in Lambda with an optional input list-functions List all of your Lambda functions delete-function Delete a Lambda function get-function-config Get the current runtime configuration for a Lambda function update-function-config Update the runtime configuration for a Lambda function . Commands to deploy and manage Amazon serverless applications using Amazon CloudFormation: . deploy-serverless Deploy an Amazon serverless application list-serverless List all of your Amazon serverless applications delete-serverless Delete an Amazon serverless application . Other Commands: . package Package a Lambda project into a .zip file ready for deployment . To get help on individual commands, run the following: dotnet lambda help <command>

Publishing a .NET Core Lambda Project from the .NET Core CLI

The following instructions assume you've created an Amazon Lambda .NET Core function in Visual Studio.

  1. Open a command prompt window, and navigate to the folder containing your Visual Studio .NET Core Lambda project.

  2. Enter dotnet lambda deploy-function.

  3. When prompted, enter the name of the function to deploy. It can be a new name or the name of an existing function.

  4. When prompted, enter the Amazon Region (the Region to which your Lambda function will be deployed).

  5. When prompted, select or create the IAM role that Lambda will assume when executing the function.

On successful completion, the message New Lambda function created is displayed.

C:\Lambda\AWSLambda1\AWSLambda1>dotnet lambda deploy-function Executing publish command ... invoking 'dotnet publish', working folder 'C:\Lambda\AWSLambda1\AWSLambda1\bin\Release\netcoreapp1.0\publish' ... publish: Publishing AWSLambda1 for .NETCoreApp,Version=v1.0 ... publish: Project AWSLambda1 (.NETCoreApp,Version=v1.0) will be compiled because expected outputs are missing ... publish: Compiling AWSLambda1 for .NETCoreApp,Version=v1.0 ... publish: Compilation succeeded. ... publish: 0 Warning(s) ... publish: 0 Error(s) ... publish: Time elapsed 00:00:01.2479713 ... publish: ... publish: publish: Published to C:\Lambda\AWSLambda1\AWSLambda1\bin\Release\netcoreapp1.0\publish ... publish: Published 1/1 projects successfully Zipping publish folder C:\Lambda\AWSLambda1\AWSLambda1\bin\Release\netcoreapp1.0\publish to C:\Lambda\AWSLambda1\AWSLamb da1\bin\Release\netcoreapp1.0\AWSLambda1.zip Enter Function Name: (Amazon Lambda function name) DotNetCoreLambdaTest Enter Amazon Region: (The region to connect to Amazon services) us-west-2 Creating new Lambda function Select IAM Role that Lambda will assume when executing function: 1) lambda_exec_LambdaCoreFunction 2) *** Create new IAM Role *** 1 New Lambda function created

If you deploy an existing function, the deploy function asks only for the Amazon Region.

C:\Lambda\AWSLambda1\AWSLambda1>dotnet lambda deploy-function Executing publish command Deleted previous publish folder ... invoking 'dotnet publish', working folder 'C:\Lambda\AWSLambda1\AWSLambda1\bin\Release\netcoreapp1.0\publish' ... publish: Publishing AWSLambda1 for .NETCoreApp,Version=v1.0 ... publish: Project AWSLambda1 (.NETCoreApp,Version=v1.0) was previously compiled. Skipping compilation. ... publish: publish: Published to C:\Lambda\AWSLambda1\AWSLambda1\bin\Release\netcoreapp1.0\publish ... publish: Published 1/1 projects successfully Zipping publish folder C:\Lambda\AWSLambda1\AWSLambda1\bin\Release\netcoreapp1.0\publish to C:\Lambda\AWSLambda1\AWSLamb da1\bin\Release\netcoreapp1.0\AWSLambda1.zip Enter Function Name: (Amazon Lambda function name) DotNetCoreLambdaTest Enter Amazon Region: (The region to connect to Amazon services) us-west-2 Updating code for existing function

After your Lambda function is deployed, it's ready to use. For more information, see Examples of How to Use Amazon Lambda.

Lambda automatically monitors Lambda functions for you, reporting metrics through Amazon CloudWatch. To monitor and troubleshoot your Lambda function, see Troubleshooting and Monitoring Amazon Lambda Functions with Amazon CloudWatch.