使用Powershell执行.Netcore Visual Studio AWS工具包“发布到AWS Lambda ...”

时间:2019-04-14 09:49:31

标签: amazon-web-services powershell .net-core aws-lambda aws-serverless

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

我现在准备将其部署到我们的登台和生产AWS帐户,并需要使用Cloudformation来执行“发布到AWS Lambda ...”部署步骤,并雄心勃勃地创建Cloudformation变更集,以便允许在部署之前进行审核。

我一直在尝试做些什么,并尝试了“ aws cloudformation软件包”和“ sam软件包” CLI命令,但是我似乎找不到前进的方向。

有人可以帮助我了解“发布到AWS Lambda ...”执行的步骤吗?我想重现Powershell中的步骤,因为这将为我提供我需要继续前进的理解。

谢谢。

1 个答案:

答案 0 :(得分:2)

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

您提到您想了解幕后发生的事情-这些工具是开源的,因此您可以在此GitHub repository中查看它为您所做的所有工作。部署无服务器应用程序时,会自动使用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向导一样。

希望它与开放源代码存储库一起帮助您深入研究其中涉及的步骤。