Skip to content

Latest commit

 

History

History

Sample4

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 

AWS Lambda Custom Runtime Function Project (with Kerberos + gRPC Service)

This is the stock lambda.CustomRuntimeFunction start project that's been augmented to include the use of KerberosManager and to invoke a gRPC Service that's being secured using Windows authentication integrated authentication with the help of the Zyborg.AspNetCore.Authentication.NegotiatedToken package (on the server) and the Zyborg.NegotiatedToken.Client package (on the client, i.e. this Lambda).

Normally, gRPC is not compatible with Windows Authentication because of it's dependency on HTTP/2, however the NegotiatedToken packages provides a workable alternative by combining the Negotiate authentication scheme with a surrogate JWT Token scheme.

A companion project Sample4.Server provides a complimentary gRPC server sample that this project relies on. You can deploy the server sample as a standalone ASP.NET Core 3.0 Kestrel app.

This project demonstrates a Custom Runtime Function sample because the gRPC support in ASP.NET Core requires a minimum of ASP.NET Core 3.0 which is not yet supported natively as an AWS .NET Runtime (since it is not an LTS release).

This starter project consists of:

  • Function.cs - contains a class with a Main method that starts the bootstrap, and a single function handler method
  • aws-lambda-tools-defaults.json - default argument settings for use with Visual Studio and command line deployment tools for AWS
  • bootstrap - a Linux bash script that is invoked by the AWS Lambda infrastructure to start the function

You may also have a test project depending on the options selected.

The generated Main method is the entry point for the function's process. The main method wraps the function handler in a wrapper that the bootstrap can work with. Then it instantiates the bootstrap and sets it up to call the function handler each time the AWS Lambda function is invoked. After the set up the bootstrap is started.

The generated function handler is a simple method accepting a string argument that returns the uppercase equivalent of the input string. Replace the body of this method, and parameters, to suit your needs.

Here are some steps to follow from Visual Studio:

(Deploying and invoking custom runtime functions is not yet available in Visual Studio)

Here are some steps to follow to get started from the command line:

Once you have edited your template and code you can deploy your application using the Amazon.Lambda.Tools Global Tool from the command line. Version 3.1.4 or later is required to deploy this project.

Install Amazon.Lambda.Tools Global Tools if not already installed.

    dotnet tool install -g Amazon.Lambda.Tools

If already installed check if new version is available.

    dotnet tool update -g Amazon.Lambda.Tools

Execute unit tests

    cd "Sample4/test/Sample4.Tests"
    dotnet test

Deploy function to AWS Lambda

    cd "Sample4/src/Sample4"
    dotnet lambda deploy-function

Improve Cold Start

.NET Core 3.0 has a new feature called ReadyToRun. When you compile your .NET Core 3.0 application you can enable ReadyToRun to prejit the .NET assemblies. This saves the .NET Core runtime from doing a lot of work during startup converting the assemblies to a native format. ReadyToRun must be used on the same platform as the platform that will run the .NET application. In Lambda's case that means you have to build the Lambda package bundle in a Linux environment. To enable ReadyToRun edit the aws-lambda-tools-defaults.json file to add /p:PublishReadyToRun=true to the msbuild-parameters parameter.