-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 44ac586
Showing
16 changed files
with
4,288 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"version": 1, | ||
"isRoot": true, | ||
"tools": { | ||
"amazon.lambda.tools": { | ||
"version": "5.8.0", | ||
"commands": [ | ||
"dotnet-lambda" | ||
] | ||
}, | ||
"paket": { | ||
"version": "7.2.1", | ||
"commands": [ | ||
"paket" | ||
] | ||
}, | ||
"fantomas": { | ||
"version": "6.2.1", | ||
"commands": [ | ||
"fantomas" | ||
] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
root = true | ||
|
||
[*] | ||
indent_style = space | ||
charset = utf-8 | ||
trim_trailing_whitespace = true | ||
insert_final_newline = true | ||
|
||
[*.yml] | ||
indent_size = 2 | ||
|
||
[*.json] | ||
indent_size = 2 | ||
|
||
[*.fs] | ||
max_line_length = 80 | ||
indent_size = 4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
bin/ | ||
obj/ | ||
build/ | ||
deploy/ | ||
publish/ | ||
packages/ | ||
paket-files/ | ||
node_modules/ | ||
.paket/ | ||
.serverless/ | ||
.ionide/ | ||
.dynamodb/ | ||
package.zip | ||
deploy.zip | ||
yarn-error.log | ||
.idea/ | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
// See https://go.microsoft.com/fwlink/?LinkId=827846 to learn about workspace recommendations. | ||
// Extension identifier format: ${publisher}.${name}. Example: vscode.csharp | ||
|
||
// List of extensions which should be recommended for users of this workspace. | ||
"recommendations": ["ionide.ionide-fsharp", "editorconfig.editorconfig"], | ||
// List of extensions recommended by VS Code that should not be recommended for users of this workspace. | ||
"unwantedRecommendations": [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
// See https://go.microsoft.com/fwlink/?LinkId=733558 | ||
// for the documentation about the tasks.json format | ||
"version": "2.0.0", | ||
"tasks": [ | ||
{ | ||
"type": "npm", | ||
"script": "build", | ||
"group": { | ||
"kind": "build", | ||
"isDefault": true | ||
} | ||
}, | ||
{ | ||
"type": "npm", | ||
"script": "test", | ||
"group": { | ||
"kind": "test", | ||
"isDefault": true | ||
} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"Records": [ | ||
{ | ||
"Body": "{ \"Name\": \"Bob\", \"Size\": 2 }" | ||
}, | ||
{ | ||
"Body": "{ \"Name\": \"Sue\", \"Size\": 9 }" | ||
}, | ||
{ | ||
"Body": "{ \"Name\": \"Ian\", \"Size\": 5 }" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"private": true, | ||
"devDependencies": { | ||
"@totallymoney/github-serverless-dotnet-artifacts": "^3.2.0", | ||
"serverless": "^3.35.2", | ||
"serverless-pseudo-parameters": "^2.6.1" | ||
}, | ||
"scripts": { | ||
"preinstall": "dotnet tool restore", | ||
"prebuild": "dotnet paket restore", | ||
"build": "dotnet build src", | ||
"test": "dotnet run --project tests", | ||
"publish": "gsda-publish mediaingenuity/HiSerialize src", | ||
"deploy": "gsda-deploy mediaingenuity/HiSerialize", | ||
"pick": "gsda-pick -e stage -e prod" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
framework auto-detect | ||
source https://api.nuget.org/v3/index.json | ||
nuget Amazon.Lambda.Core | ||
nuget Amazon.Lambda.SQSEvents | ||
nuget FSharp.Core |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
RESTRICTION: == net6.0 | ||
NUGET | ||
remote: https://api.nuget.org/v3/index.json | ||
Amazon.Lambda.Core (2.1) | ||
Amazon.Lambda.SQSEvents (2.1) | ||
FSharp.Core (7.0.400) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# HiSerialize | ||
|
||
## Deploying | ||
|
||
Review the [release artifacts](https://github.com/mediaingenuity/HiSerialize/releases). | ||
|
||
Use `pick` for interactive deployments: | ||
|
||
```bash | ||
$ yarn pick | ||
``` | ||
|
||
`pick` simply uses the underlying `deploy` command: | ||
|
||
```bash | ||
$ yarn deploy <version> <env> # e.g yarn deploy 0.1.2 prod | ||
``` | ||
|
||
## Tooling | ||
|
||
* Project created by [fsharp-lambda-scaffold](https://github.com/mediaingenuity/fsharp-lambda-scaffold) | ||
* CD provided by [github-serverless-dotnet-artifacts](https://github.com/totallymoney/github-serverless-dotnet-artifacts) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
service: sls-HiSerialize | ||
|
||
frameworkVersion: "3" | ||
|
||
plugins: | ||
- serverless-pseudo-parameters | ||
|
||
custom: | ||
gsda: | ||
version: ${env:VERSION, '0.0.0'} | ||
deployedDate: ${env:DEPLOYED_DATE, ''} | ||
|
||
provider: | ||
name: aws | ||
runtime: dotnet6 | ||
architecture: arm64 | ||
deploymentMethod: direct | ||
stage: ${opt:stage, 'stage'} | ||
region: eu-west-1 | ||
profile: sandbox | ||
timeout: 30 | ||
memorySize: 512 | ||
logRetentionInDays: 14 | ||
versionFunctions: false | ||
|
||
package: | ||
artifact: package.zip | ||
|
||
functions: | ||
ExampleOne: | ||
handler: HiSerialize::ExampleOne::ExampleOne | ||
|
||
ExampleTwo: | ||
handler: HiSerialize::ExampleTwo::ExampleTwo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
module ExampleOne | ||
|
||
|
||
|
||
// Lambda dotnet serialization docs | ||
// https://docs.aws.amazon.com/lambda/latest/dg/csharp-handler.html#csharp-handler-serializer-reflection | ||
|
||
|
||
open System.IO | ||
open System.Text.Json | ||
open Amazon.Lambda.Core | ||
|
||
|
||
type MySerializer() = | ||
|
||
// member this.Serialize(res, stream) = | ||
// (this :> ILambdaSerializer).Serialize(res, stream) | ||
|
||
// member this.Deserialize(stream) = | ||
// (this :> ILambdaSerializer).Deserialize(stream) | ||
|
||
interface ILambdaSerializer with | ||
|
||
member this.Serialize(res, stream: Stream) : unit = | ||
use writer = new Utf8JsonWriter(stream) | ||
JsonSerializer.Serialize(writer, res) | ||
|
||
member this.Deserialize<'T>(stream: Stream) : 'T = | ||
JsonSerializer.Deserialize<'T> stream | ||
|
||
|
||
|
||
|
||
type MyDto = { Name: string; Size: int } | ||
|
||
[<LambdaSerializer(typeof<MySerializer>)>] | ||
let ExampleOne (event: MyDto) = | ||
printfn "the event is:\n\n%A" event | ||
event | ||
|
||
|
||
(* | ||
yarn gsda-dev-deploy nick | ||
*) | ||
|
||
(* | ||
yarn sls invoke -s nick -f ExampleOne -d '{ "Name": "Bob", "Size": 2 }' | ||
*) | ||
|
||
|
||
// C# interface example | ||
// https://sharplab.io/#v2:CYLg1APgAgzABASwHYBcCmAnAZgQwMZpwCSAsAFADe5cNcUALHABoAUUAjAAxwDOAlAG5yAX3LlYdAExwAwnBDE4VMrTrwGzNl158lossKA= | ||
|
||
|
||
// F# interface example | ||
// https://sharplab.io/#v2:DYLgZgzgNAJiDUAfALgTwA4FMAEBJbAvALABQ252AhgEYTIBOlAxstgBojYSd30CWAOwDm2ALQA+bAFUBfZKQUk0WbAGEAFAEpCpCtkHJM9MMxz4A7nIAWuvRQC2me9SPZkVvhAB0bddy4MgkLaBNhaukA== | ||
|
||
|
||
// F# calling interface methods docs | ||
// https://learn.microsoft.com/en-us/dotnet/fsharp/language-reference/interfaces#calling-interface-methods |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
module ExampleTwo | ||
|
||
|
||
open System.IO | ||
open System.Text.Json | ||
open Amazon.Lambda.Core | ||
open Amazon.Lambda.SQSEvents | ||
|
||
|
||
type TypicalDto = { Name: string; Size: int } | ||
|
||
[<LambdaSerializer(typeof<ExampleOne.MySerializer>)>] | ||
let ``A typical SQS event handler`` (event: SQSEvent) = | ||
|
||
let msgs: TypicalDto list = | ||
event.Records | ||
|> List.ofSeq | ||
|> List.map (fun r -> JsonSerializer.Deserialize<TypicalDto> r.Body) | ||
|
||
printfn "the messages are:\n\n%A" msgs | ||
|
||
() | ||
|
||
|
||
|
||
|
||
open type Amazon.Lambda.SQSEvents.SQSEvent | ||
|
||
|
||
|
||
type SQSEventSerializer() = | ||
|
||
member this.Serialize(res, stream) = | ||
System.Runtime.CompilerServices.Unsafe | ||
.As<ILambdaSerializer>(this) | ||
.Serialize(res, stream) | ||
|
||
(this :> ILambdaSerializer).Serialize(res, stream) | ||
|
||
member this.Deserialize(stream) = | ||
(this :> ILambdaSerializer).Deserialize(stream) | ||
|
||
interface ILambdaSerializer with | ||
|
||
member this.Serialize(res, stream: Stream) : unit = | ||
use writer = new Utf8JsonWriter(stream) | ||
JsonSerializer.Serialize(writer, res) | ||
|
||
member this.Deserialize<'T>(stream: Stream) : 'T = | ||
let sqsEvent: SQSEvent = JsonSerializer.Deserialize<SQSEvent> stream | ||
|
||
use stream = new MemoryStream() | ||
use writer = new Utf8JsonWriter(stream) | ||
let parse (m: SQSMessage) = JsonDocument.Parse(m.Body).RootElement | ||
let write (e: JsonElement) = e.WriteTo writer | ||
|
||
writer.WriteStartArray() | ||
sqsEvent.Records |> Seq.iter (parse >> write) | ||
writer.WriteEndArray() | ||
|
||
writer.Flush() | ||
stream.Position <- 0 | ||
JsonSerializer.Deserialize<'T> stream | ||
|
||
|
||
|
||
|
||
|
||
type MySqsMsg = { Name: string; Size: int } | ||
|
||
|
||
[<LambdaSerializer(typeof<SQSEventSerializer>)>] | ||
let ExampleTwo (msgs: MySqsMsg list) = | ||
printfn "the messages are:\n\n%A" msgs | ||
msgs | ||
|
||
|
||
|
||
|
||
(* | ||
yarn sls invoke -s nick -f ExampleTwo -p ./example-two-input.json | ||
*) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project Sdk="Microsoft.NET.Sdk.Web"> | ||
<PropertyGroup> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<WarningsAsErrors>FS0025</WarningsAsErrors> | ||
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles> | ||
<NoWarn>FS0988</NoWarn> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Compile Include="ExampleOne.fs" /> | ||
<Compile Include="ExampleTwo.fs" /> | ||
</ItemGroup> | ||
<Import Project="..\.paket\Paket.Restore.targets" /> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Amazon.Lambda.Core | ||
FSharp.Core | ||
Amazon.Lambda.SQSEvents |
Oops, something went wrong.