Skip to content

Commit

Permalink
Merge pull request #36 from rventuri76/feature/aws-lambda-web-adapter
Browse files Browse the repository at this point in the history
Adding refactored Minimal API Project to use lambda web adapter inste…
  • Loading branch information
jeastham1993 authored Nov 5, 2023
2 parents fe15c30 + 3c3b6fd commit 4aff3aa
Show file tree
Hide file tree
Showing 44 changed files with 1,388 additions and 235 deletions.
70 changes: 54 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ It includes the below implementations as well as benchmarking results for both x
- .NET 6 Lambda
- .NET 6 Top Level statements
- .NET 6 Minimal API
- .NET 6 Minimal API with AWS Lambda Web Adapter
- .NET 6 NativeAOT compilation
- .NET 7 Custom Runtime
- .NET 7 NativeAOT compilation
Expand Down Expand Up @@ -54,6 +55,10 @@ There is a single project named ApiBootstrap that contains all the start-up code

It uses the new minimal API hosting model as detailed [here](https://aws.amazon.com/blogs/compute/introducing-the-net-6-runtime-for-aws-lambda/).

### .NET 6 Minimal API with AWS Lambda Web Adapter

Same as minimal API but instead of using Amazon.Lambda.AspNetCoreServer.Hosting/Amazon.Lambda.AspNetCoreServer it is based on [Aws Lambda Web Adapter](https://github.com/awslabs/aws-lambda-web-adapter)

### .NET 6 native AOT

The code is compiled natively for either Linux-x86_64 or Linux-ARM64 and then deployed manually to Lambda as a zip file. The SAM deploy can still be used to stand up the API Gateway endpoints and DynamoDb table, but won't be able to deploy native AOT .NET Lambda functions yet. Packages need to be published from Linux, since cross-OS native compilation is not supported yet.
Expand Down Expand Up @@ -245,28 +250,61 @@ filter @type="REPORT"
<td><b style="color: green">9.38</b></td>
<td><b style="color: green">20.65</b></td>
<td>417.23</td>
</tr>
<tr>
<th>Minimal API on x86</th>
<td>1742.83</td>
<td>1966.88</td>
<td>2411.74</td>
<td>2503.31</td>
<td><b style="color: green">5.91</b></td>
<td><b style="color: green">9.99</b></td>
<td><b style="color: green">21.74</b></td>
<td>108.6</td>
</tr>
<tr>
<th>Minimal API on ARM64</th>
<td>1149.95</td>
<td>1194.47</td>
<td>1239.47</td>
<td>1315.07</td>
<td><b style="color: green">6.10</b></td>
<td><b style="color: green">10.00</b></td>
<td><b style="color: green">22.91</b></td>
<td>1315.07</td>
<td>2105.21</td>
<td>2164.96</td>
<td>2215.31</td>
<td>2228.18</td>
<td><b style="color: green">6.20</b></td>
<td><b style="color: green">9.67</b></td>
<td><b style="color: green">20.08</b></td>
<td>528.13</td>
</tr>
<tr>
<th>Minimal API with aws lambda web adapter on x86</th>
<td>1013.88</td>
<td>1102.67</td>
<td>1330.62</td>
<td>1392.85</td>
<td><b style="color: green">6.20</b></td>
<td><b style="color: green">10.31</b></td>
<td><b style="color: green">21.74</b></td>
<td>154.62</td>
</tr>
<tr>
<th>Minimal API with aws lambda web adapter on ARM64</th>
<td>1335.57</td>
<td>1395.04</td>
<td>1455.09</td>
<td>1455.09</td>
<td><b style="color: green">7.04</b></td>
<td><b style="color: green">15.58</b></td>
<td><b style="color: green">36.71</b></td>
<td>111.28</td>
</tr>
<tr>
<th>Native AOT on ARM64</th>
<td>448.97</td>
<td>467.75</td>
<td>493.20</td>
<td>516.6</td>
<td><b style="color: green">6.30</b></td>
<td><b style="color: green">10.49</b></td>
<td><b style="color: green">21.50</b></td>
<td>461.35</td>
<td>1277.19</td>
<td>1326.64</td>
<td>1358.84</td>
<td>1367.49</td>
<td><b style="color: green">6.10</b></td>
<td><b style="color: green">9.37</b></td>
<td><b style="color: green">17.97</b></td>
<td>838.78</td>
</tr>
<tr>
<th>Native AOT on X86</th>
Expand Down
16 changes: 16 additions & 0 deletions loadtest/codebuild/load-test-buildspec.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
version: 0.2

phases:
install:
commands:
- npm i artillery -g
build:
commands:
- export temp1=$(pwd);echo $temp1
- cd loadtest/codebuild
- ./run-all-load-tests.sh
artifacts:
files:
- src/NET6MinimalAPI/Report/*
- src/NET6MinimalAPIWebAdapter/Report/*
name: loadtest-$(date +%Y-%m-%H-%M)
51 changes: 51 additions & 0 deletions loadtest/codebuild/run-all-load-tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
TEST_DURATIOMN_SEC=60
LOG_INTERVAL_MIN=20
LOG_DELETE=yes
DELETE_STACK=yes

if [ "x${LT_TEST_DURATIOMN_SEC}" != x ];
then
TEST_DURATIOMN_SEC=$LT_TEST_DURATIOMN_SEC
fi

if [ "x${LT_LOG_INTERVAL_MIN}" != x ];
then
LOG_INTERVAL_MIN=$LT_LOG_INTERVAL_MIN
fi

if [ "x${LT_LOG_DELETE}" != x ];
then
LOG_DELETE=$LT_LOG_DELETE
fi

if [ "x${LT_DELETE_STACK}" != x ];
then
DELETE_STACK=$LT_DELETE_STACK
fi

echo --------------------------------------------
echo TEST_DURATIOMN_SEC: $TEST_DURATIOMN_SEC
echo LOG_INTERVAL_MIN: $LOG_INTERVAL_MIN
echo LOG_DELETE: $LOG_DELETE
echo DELETE_STACK: $DELETE_STACK
echo --------------------------------------------

if [ "$LT_NET6_MINIMAL_API" != yes ];
then
echo SKIPPING net6 minimal api :$LT_NET6_MINIMAL_API
else
echo "RUNNING load test for net6 minimal api"
cd ../../src/NET6MinimalAPI/
source ./deploy.sh $DELETE_STACK
source ./run-loadtest.sh $TEST_DURATIOMN_SEC $LOG_INTERVAL_MIN $LOG_DELETE
fi

if [ "$LT_NET6_MINIMAL_API_WEB_ADAPTER" != yes ];
then
echo SKIPPING net6 minimal api web adapter :$LT_NET6_MINIMAL_API_WEB_ADAPTER
else
echo "RUNNING load test for net6 minimal api web adapter"
cd ../../src/NET6MinimalAPIWebAdapter/
source ./deploy.sh $DELETE_STACK
source ./run-loadtest.sh $TEST_DURATIOMN_SEC $LOG_INTERVAL_MIN $LOG_DELETE
fi
51 changes: 0 additions & 51 deletions src/MinimalAPI/ApiBootstrap/CloudWatchQueryExecution.cs

This file was deleted.

13 changes: 0 additions & 13 deletions src/MinimalAPI/ApiBootstrap/DateUtils.cs

This file was deleted.

25 changes: 0 additions & 25 deletions src/MinimalAPI/ApiBootstrap/QueryResult.cs

This file was deleted.

3 changes: 0 additions & 3 deletions src/MinimalAPI/Makefile

This file was deleted.

72 changes: 0 additions & 72 deletions src/MinimalAPI/template.yaml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@

<PropertyGroup>
<OutputType>exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
<AWSProjectType>Lambda</AWSProjectType>
<AssemblyName>bootstrap</AssemblyName>
<PublishReadyToRunComposite>true</PublishReadyToRunComposite>
<EventSourceSupport>false</EventSourceSupport>
<UseSystemResourceKeys>true</UseSystemResourceKeys>
Expand All @@ -15,14 +14,14 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Amazon.Lambda.AspNetCoreServer.Hosting" Version="1.0.0" />
<PackageReference Include="Amazon.Lambda.Core" Version="$(AmazonLambdaCoreVersion)" />
<PackageReference Include="Amazon.Lambda.APIGatewayEvents" Version="$(ApiGatewayEventsVersion)" />
<PackageReference Include="Amazon.Lambda.RuntimeSupport" Version="$(AmazonLambdaRuntimeSupportVersion)" />
<PackageReference Include="Amazon.Lambda.Serialization.SystemTextJson" Version="$(AmazonLambdaSerializationVersion)" />
<PackageReference Include="AWSSDK.CloudWatchLogs" Version="$(CloudWatchLogsSdkVersion)" />
<PackageReference Include="AWSXRayRecorder.Core" Version="$(XRayRecorderVersion)" />
<PackageReference Include="AWSXRayRecorder.Handlers.AwsSdk" Version="$(XRaySdkHandlerVersion)" />
<PackageReference Include="Amazon.Lambda.AspNetCoreServer.Hosting" Version="1.6.0" />
<PackageReference Include="Amazon.Lambda.Core" Version="2.2.0" />
<PackageReference Include="Amazon.Lambda.APIGatewayEvents" Version="2.7.0" />
<PackageReference Include="Amazon.Lambda.RuntimeSupport" Version="1.10.0" />
<PackageReference Include="Amazon.Lambda.Serialization.SystemTextJson" Version="2.4.0" />
<PackageReference Include="AWSSDK.CloudWatchLogs" Version="3.7.201.21" />
<PackageReference Include="AWSXRayRecorder.Core" Version="2.14.0" />
<PackageReference Include="AWSXRayRecorder.Handlers.AwsSdk" Version="2.12.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Loading

0 comments on commit 4aff3aa

Please sign in to comment.