AWS Toolkit for Visual Studio
用户指南

AWS services or capabilities described in AWS Documentation may vary by region/location. Click Getting Started with Amazon AWS to see specific differences applicable to the China (Beijing) Region.

使用 .NET 内核 CLI 部署 AWS Lambda 项目

AWS Toolkit for Visual Studio 包含适用于 Visual Studio 的 AWS Lambda .NET 内核项目模板。您必须先安装 Visual Studio 2015 Update 3,然后才能安装 .NET Core for Windows 和 Toolkit for Visual Studio。您可以使用 .NET 内核命令行界面 (CLI) 在 Visual Studio 中部署 Lambda 函数。

注意

有关在 Visual Studio 中创建 Lambda 函数的信息,请参阅将 AWS Lambda 与 AWS Toolkit for Visual Studio 配合使用

有关 Microsoft .NET 内核的更多信息,请参阅 .NET 内核

有关 Lambda 函数的更多信息,请参阅什么是 AWS Lambda?

列出可通过 CLI 使用的 Lambda 命令#

可通过 .NET 内核 CLI 使用各种 Lambda 命令。

  1. 打开命令提示符并导航到包含 Visual Studio .NET 内核 Lambda 项目的文件夹。
  2. Type dotnet lambda --help.
C:\Lambda\AWSLambda1\AWSLambda1>dotnet lambda --help
    AWS Lambda Tools for .NET Core functions
    Project Home: https://github.com/aws/aws-lambda-dotnet
    .
    Commands to deploy and manage |LAM| functions:
    .
            deploy-function         Deploy the project to |LAM|
            invoke-function         Invoke the function in |LAM| with an optional input
            list-functions          List all of your |LAM| functions
            delete-function         Delete a |LAM| function
            get-function-config     Get the current runtime configuration for a |LAM| function
            update-function-config  Update the runtime configuration for a |LAM| function
    .
    Commands to deploy and manage AWS Serverless applications using |CFNlong|:
    .
            deploy-serverless       Deploy an AWS Serverless application
            list-serverless         List all of your AWS Serverless applications
            delete-serverless       Delete an AWS Serverless application
    .
    Other Commands:
    .
            package                 Package a |LAM| project into a .zip file ready for deployment
    .
    To get help on individual commands execute:

            dotnet lambda help <command>

从 .NET 内核 CLI 发布 .NET 内核 Lambda 项目#

以下说明假定您已在 Visual Studio 中创建 AWS Lambda .NET 内核函数。

  1. 打开命令提示符并导航到包含您的 Visual Studio .NET 内核 Lambda 项目的文件夹。
  2. Type dotnet lambda deploy-function.

#。当系统提示时,键入要部署的函数的名称。它可以是新名称或现有函数的名称。

  1. 当系统提示时,输入 AWS 区域 (Lambda 函数将部署到的区域)。
  2. 当系统提示时,选择或创建 Lambda 将在执行函数时代入的 IAM 角色。
  3. 成功完成后,将显示消息 New Lambda function created
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: (AWS Lambda function name)
DotNetCoreLambdaTest
Enter AWS Region: (The region to connect to AWS 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

如果您部署现有函数,则部署函数仅要求 AWS 区域。

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: (AWS Lambda function name)
DotNetCoreLambdaTest
Enter AWS Region: (The region to connect to AWS services)
us-west-2
Updating code for existing function

在部署 Lambda 函数后,便可使用该函数。请参阅有关如何使用 AWS Lambda 的示例

Lambda 将自动为您监控 Lambda 函数,并通过 Amazon CloudWatch 报告指标。要监控和诊断 Lambda 函数,请参阅使用 Amazon CloudWatch 诊断和监控 AWS Lambda 函数