使用Powershell执行.Netcore Visual Studio AWS Toolkit 'Publish to AWS Lambda...'



我将Visual Studio 2017与AWS Toolkit一起使用来开发.Net Core lambda函数。我在一个名为serverless.template的文件中有Cloudformation脚本,在一个名为aws-lambda-tools-defaults.json的文件中有部署配置。在开发项目时,我一直在使用"发布到 AWS Lambda..."将其部署到 AWS 开发账户右键单击"解决方案资源管理器"中的选项。

我现在已准备好将其部署到我们的暂存和生产 AWS 账户,并且需要执行"发布到 AWS Lambda..."使用 Cloudformation 的部署步骤,我们的目标是创建 Cloudformation 更改集,以便在部署之前进行审查。

我一直在尝试弄清楚该怎么做,并尝试了"aws cloudformation 包"和"sam 包"CLI 命令,但我似乎找不到前进的方法。

谁能帮助我理解"发布到 AWS Lambda..."的步骤执行?我想重现Powershell中的步骤,因为这将为我提供继续前进所需的理解。

谢谢。

要从命令行进行部署,请使用适用于 Lambda 的 dotnet CLI 扩展。它与从向导发布时在 Visual Studio 中运行的代码相同,并且可以读取默认文件等,因此无论从 IDE 还是命令行进行部署,都可以获得一致的部署体验。

您提到您想了解幕后发生的事情 - 这些工具是开源的,因此您可以查看它在此 GitHub 存储库中为您所做的所有工作。部署无服务器应用程序时,会自动使用 CloudFormation 更改集,您无需自行处理。

该工具是一个 .NET Core 全局工具,您首先从命令行安装它:

dotnet tool install -g Amazon.Lambda.Tools

安装后,您可以获得帮助等:

PS C:> dotnet lambda help
Amazon Lambda Tools for .NET Core applications (3.2.0)
Project Home: https://github.com/aws/aws-extensions-for-dotnet-cli, https://github.com/aws/aws-lambda-dotnet

Commands to deploy and manage AWS Lambda functions:
deploy-function         Command to deploy the project to AWS Lambda
invoke-function         Command to invoke a function in Lambda with an optional input
list-functions          Command to list all your Lambda functions
delete-function         Command to delete a Lambda function
get-function-config     Command to get the current runtime configuration for a Lambda function
update-function-config  Command to update the runtime configuration for a Lambda function
Commands to deploy and manage AWS Serverless applications using AWS CloudFormation:
deploy-serverless       Command to deploy an AWS Serverless application
list-serverless         Command to list all your AWS Serverless applications
delete-serverless       Command to delete an AWS Serverless application
Commands to publish and manage AWS Lambda Layers:
publish-layer           Command to publish a Layer that can be associated with a Lambda function
list-layers             Command to list Layers
list-layer-versions     Command to list versions for a Layer
get-layer-version       Command to get the details of a Layer version
delete-layer-version    Command to delete a version of a Layer
Other Commands:
package                 Command to package a Lambda project into a zip file ready for deployment
package-ci              Command to use as part of a continuous integration system.
To get help on individual commands execute:
dotnet lambda help <command>

要从命令行部署项目,请先 cd 到项目文件夹中,然后执行命令

dotnet lambda deploy-serverless

这将读取默认文件中的设置并为您执行部署,就像您使用 IDE 向导一样。

希望这与开源存储库相结合,可以帮助您深入了解所涉及的步骤。

最新更新