Elliveny
Elliveny

Reputation: 2203

Using Powershell to perform the .Netcore Visual Studio AWS Toolkit 'Publish to AWS Lambda...'

I used Visual Studio 2017 with the AWS Toolkit to develop a .Net Core lambda function. I have Cloudformation script in a file called serverless.template and a deployment configuration in a file called aws-lambda-tools-defaults.json. While developing the project I've been deploying it to an AWS development account using the 'Publish to AWS Lambda...' right click option in the Solution Explorer.

I'm now ready to move to deploying this to our staging and production AWS accounts and need to perform the 'Publish to AWS Lambda...' deployment step using Cloudformation, with an ambition that we create Cloudformation Change Sets, to allow review prior to deployment.

I've been trying to work out what to do and have experimented with the 'aws cloudformation package' and 'sam package' CLI commands, but I can't seem to find a way forward.

Can anyone help me to understand the steps which 'Publish to AWS Lambda...' performs? I'd like to reproduce the steps in Powershell as this will provide me with the understanding I need to move on.

Thanks.

Upvotes: 0

Views: 527

Answers (1)

Steve Roberts
Steve Roberts

Reputation: 734

To deploy from the command line, use the dotnet CLI extension for Lambda. It's the same code that runs inside Visual Studio when you publish from the wizard, and can read the defaults file etc so you get a consistent deployment experience regardless of whether you deploy from the IDE or the command line.

You mention you want to understand what's going on behind the scenes - these tools are open source so you can take a look at all the work it does for you in this GitHub repository. When deploying a serverless application, CloudFormation change sets are used automatically, you don't need to handle it yourself.

The tool is a .NET Core global tool which you first install from the command line:

dotnet tool install -g Amazon.Lambda.Tools

Once installed, you can get help etc:

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>

To deploy your project from the command line, first cd into the project folder then execute the command

dotnet lambda deploy-serverless

This will read the settings in the defaults file and perform the deployment for you, just as if you'd used the IDE wizard.

Hope this, in conjunction with the open source repo, helps you dig into the steps involved.

Upvotes: 3

Related Questions