Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Lambda net6.0 selfhost #144

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 27 additions & 3 deletions src/Propulsion.DynamoStore.Lambda/Function.fs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
namespace Propulsion.DynamoStore.Lambda
module Propulsion.DynamoStore.Lambda.Program

open Amazon.Lambda.Core
open Amazon.Lambda.DynamoDBEvents
open Amazon.Lambda.RuntimeSupport
open Equinox.DynamoStore
open Propulsion.DynamoStore
open Serilog
Expand Down Expand Up @@ -67,5 +68,28 @@ type Function() =
.CreateLogger()
let service = DynamoStoreIndexer(log, conn.Context, cache, epochBytesCutoff = epochCutoffMiB * 1024 * 1024) //

member _.FunctionHandler(dynamoEvent : DynamoDBEvent, _context : ILambdaContext) =
DynamoStreamsLambda.ingest log service dynamoEvent |> Async.StartImmediateAsTask
// Warm up (pending https://github.com/aws/aws-lambda-dotnet/pull/1091)
member _.InitAsync() =
service.IngestWithoutConcurrency(AppendsTrancheId.wellKnownId, Array.empty)

member _.Handle(dynamoEvent : DynamoDBEvent) =
DynamoStreamsLambda.ingest log service dynamoEvent

let adaptInit f () =
async {
do! f ()
return true
} |> Async.StartImmediateAsTask
let adaptHandler h x =
h x
|> Async.StartImmediateAsTask
:> System.Threading.Tasks.Task

[<EntryPoint>]
let main _ =
let f = Function()
let serializer = Amazon.Lambda.Serialization.SystemTextJson.DefaultLambdaJsonSerializer()
let t = LambdaBootstrapBuilder.Create<_>(adaptHandler f.Handle, serializer)
.UseBootstrapHandler(adaptInit f.InitAsync)
.Build().RunAsync().GetAwaiter()
let () = t.GetResult() in 0
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@
<PackageReference Include="MinVer" Version="4.0.0" PrivateAssets="All" />

<PackageReference Include="Amazon.Lambda.Core" Version="2.1.0" />
<PackageReference Include="Amazon.Lambda.DynamoDBEvents" Version="2.1.0" />
<PackageReference Include="Amazon.Lambda.DynamoDBEvents" Version="2.1.1" />
<PackageReference Include="Amazon.Lambda.RuntimeSupport" Version="1.8.1" />
<PackageReference Include="Amazon.Lambda.Serialization.SystemTextJson" Version="2.3.0" />
<PackageReference Include="Serilog.Formatting.Compact" Version="1.1.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="4.0.1" />
<ProjectReference Include="..\Propulsion.DynamoStore\Propulsion.DynamoStore.fsproj" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@
"function-memory-size": 128,
"function-timeout": 180,
"function-architecture": "arm64",
"function-handler": "Propulsion.DynamoStore.Lambda::Propulsion.DynamoStore.Lambda.Function::FunctionHandler"
"function-handler": "Propulsion.DynamoStore.Lambda"
}