Skip to content

FSharpBristol/FSharp-Template-for-Aws-Lambda

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

FSharp Template for Aws Lambda

Template for publishing F# projects to AWS Lambda. Source code originally from this blog post http://lukemerrett.com/fsharp-on-aws-lambda/

The template at the root of this Git repository uses just dotnet core and AWS Lambda Tools.

If you prefer to use Serverless (and simplify the process of deploying & invoking the function) please use the template in the Serverless folder.

Prerequisites

  • .NET Core SDK Installer
    • This contains runtimes v1.0.4 and v1.1.1
    • 1.1 isn't currently supported by AWS Lambda
  • An AWS Account

Build and Package the Template

The template is already set up as a working, albeit basic, Lambda function. The tool defined in the project.json file allows us to package the project so it can be used by AWS.

CD into the root directory of the project and run:

dotnet restore
dotnet build 
dotnet lambda package --configuration Release --framework netcoreapp1.0

This will output the package zip to bin\Release\netcoreapp1.0\FSharpLambdaTemplate.zip. When creating the AWS Lambda this is the zip file you will provide.

Setting up an AWS Function

Log in to AWS Console and choose your region.

Go to Services -> Lambda -> Get Started Now. Here select the Blank Function blueprint, then select no triggers (we'll trigger it ourselves) and click "Next".

The function can then be set up like this, note the selected zip file is the one packaged above:

02

From here we tell AWS where to find our handler function is. The format of the handler declarion is Assembly::Namespace.ClassName::MethodName so in our case it is: FSharpLambdaTemplate::AwsLambdaTemplate.Program::handler

03

Leave everything else as default and click "Next" to go to the Review stage then "Create function".

Testing the Function

Once created you can click "Test" on the UI; this will invoke the function.

You should see "Execution result: succeeded(logs)" on the bottom panel.

Clicking "logs" will take you to CloudWatch, then clicking on the latest event you should see tracking of the requests starting and ending, with the output "Hello World!" in the middle.

About

Template for publishing F# projects to AWS Lambda

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages