diff --git a/README.md b/README.md index b9a3a11..3b5d8cb 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,17 @@ # ![](assets/logo-small.png) LambdaNative -Make .NET AWS Lambda functions start 10x faster using LambdaNative. - -[![No Maintenance Intended](http://unmaintained.tech/badge.svg)](http://unmaintained.tech/) -[![Build status](https://ci.appveyor.com/api/projects/status/5x6prdi6oeonxbm7/branch/master?svg=true)](https://ci.appveyor.com/project/zaccharles/lambda-native/branch/master) -[![nuget](https://img.shields.io/nuget/v/LambdaNative.svg)](https://www.nuget.org/packages/LambdaNative/) +Make .NET AWS Lambda functions start 10x faster using LambdaNative and custom for solved AWS Lambda connection timeout (Based on [LambdaNative](https://github.com/zaccharles/lambda-native) by @zaccharles) +[![Build status](https://ci.appveyor.com/api/projects/status/i8h933ig07xin5r7/branch/master?svg=true)](https://ci.appveyor.com/project/ifew/lambda-native/branch/master) +[![nuget](https://img.shields.io/nuget/v/LambdaNative.svg)](https://www.nuget.org/packages/LambdaNativeCustom/) + +# Change Log + +#### Fixed AWS Lambda Connection Timeout +After the invocating first time (Cold Start) and then waiting for 100 seconds its get error message because of AWS Lambda has default connection timeout at 100 seconds (reference https://aws.amazon.com/premiumsupport/knowledge-center/lambda-function-retry-timeout-sdk/) + +Found this solution: Suratchanan Kraidech + # Usage To use LambdaNative in your own project, please see the README in the [example](example) directory. @@ -28,13 +34,13 @@ For more information and comparisons, please read [this Medium post](https://med ## Prerequisites - * [.NET Core SDK 2.1.503](https://dotnet.microsoft.com/download/dotnet-core/2.1) + * [.NET Core SDK 2.2.402](https://dotnet.microsoft.com/download/dotnet-core/2.2) ## Building Clone repository ```bash -> git clone https://github.com/zaccharles/lambda-native.git +> git clone https://github.com/ifew/lambda-native.git ``` Restore NuGet packages diff --git a/example/Dockerfile b/example/Dockerfile new file mode 100644 index 0000000..a3411a6 --- /dev/null +++ b/example/Dockerfile @@ -0,0 +1,7 @@ +# docker build -t lambdanative . +# docker run --rm -v $(pwd):/app lambdanative + +FROM microsoft/dotnet:2.2-sdk AS build-env +WORKDIR /app +RUN apt-get update && apt-get install cmake clang-3.9 libicu-dev uuid-dev libcurl4-openssl-dev zlib1g-dev libkrb5-dev -y +ENTRYPOINT ["dotnet", "publish", "-c", "Release", "-r", "linux-x64"] \ No newline at end of file diff --git a/example/README.md b/example/README.md index bd32de4..c2d498e 100644 --- a/example/README.md +++ b/example/README.md @@ -123,6 +123,21 @@ Here are instructions on how to compile the example project on Ubuntu using EC2. You now have a native executable file named `bootstrap`. +# Compiling with Docker (For Non-Linux User) + +* Create Docker image +```bash +sh build-docker.sh +``` +* Run script to compile +```bash +sh build.sh +``` + +And we have `package.zip` in folder `publish` for ready to deploy + +If your source code changed, you can run only "build.sh" for generate native file + # Deployment Now that you have a native executable named `bootstrap`, you can deploy it to AWS Lambda. It's important that the file is named `bootstrap` as this is a convention that lets AWS Lambda know which file to execute. diff --git a/example/build-docker.sh b/example/build-docker.sh new file mode 100755 index 0000000..6f03aef --- /dev/null +++ b/example/build-docker.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +# +# SHOULD BUILD IMAGE BEFORE +# docker build -t lambdanative . +# + +rm -f $(pwd)/bootstrap +rm -f $(pwd)/package.zip +docker run --rm -v $(pwd):/app lambdanative +cp bin/Release/netcoreapp2.1/linux-x64/native/LambdaNative.Example bootstrap +zip package.zip bootstrap +# aws s3 cp package.zip s3://backend-layer [--profile [PROFILE-NAME]] \ No newline at end of file diff --git a/example/build.sh b/example/build.sh index 3054e23..e238b73 100755 --- a/example/build.sh +++ b/example/build.sh @@ -3,4 +3,4 @@ dotnet publish -r linux-x64 -c release cp bin/release/netcoreapp*/linux-x64/native/* bootstrap # zip package.zip bootstrap -# aws s3 cp package.zip s3:///package.zip +# aws s3 cp package.zip s3:///package.zip \ No newline at end of file diff --git a/global.json b/global.json index be6957e..3cd92d1 100644 --- a/global.json +++ b/global.json @@ -1,5 +1,5 @@ { "sdk": { - "version": "2.1.503" + "version": "2.2.402" } } \ No newline at end of file diff --git a/src/LambdaNative.cs b/src/LambdaNative.cs index 6bb4ced..4a625f3 100644 --- a/src/LambdaNative.cs +++ b/src/LambdaNative.cs @@ -29,7 +29,13 @@ public static class LambdaNative private static void Run(IHandlerRunner runner) { - ILambdaRuntime runtime = new LambdaRuntime(new SystemEnvironment(), new SystemDateTime(), new HttpClient()); + // The Lambda container freezes the process at a point where an HTTP request is in progress. + // We need to make sure we don't timeout waiting for the next invocation. + // Reference 12 Hours from AWS Custom Runtime Support + HttpClient httpClient = new HttpClient(); + httpClient.Timeout = TimeSpan.FromHours(12); + + ILambdaRuntime runtime = new LambdaRuntime(new SystemEnvironment(), new SystemDateTime(), httpClient); ILambdaBootstrap bootstrap = new LambdaBootstrap(runtime, runner); bootstrap.Initialize(); diff --git a/src/LambdaNative.csproj b/src/LambdaNative.csproj index 44b4c5a..d5c2a43 100644 --- a/src/LambdaNative.csproj +++ b/src/LambdaNative.csproj @@ -4,16 +4,16 @@ 1.0.0.0 netstandard2.0 1.0.0 - LambdaNative - Zac Charles - Make .NET AWS Lambda functions start 10x faster using LambdaNative - LambdaNative + LambdaNativeCustom + iFew + Make .NET AWS Lambda functions start 10x faster using LambdaNative and custom for solved AWS Lambda connection timeout (Based on LambdaNative by zaccharles) + LambdaNativeCustom aws,lambda,native,performance - https://github.com/zaccharles/lambda-native - https://raw.githubusercontent.com/zaccharles/lambda-native/master/assets/logo.png - https://github.com/zaccharles/lambda-native/blob/master/LICENSE + https://github.com/ifew/lambda-native + https://raw.githubusercontent.com/ifew/lambda-native/master/assets/logo.png + https://github.com/ifew/lambda-native/blob/master/LICENSE git - https://github.com/zaccharles/lambda-native + https://github.com/ifew/lambda-native