AWS DotNet Lambda Functions powered by AWS Graviton2 Processors (C#, CDK)

Collin Smith
6 min readOct 5, 2021

This article will quickly demonstrate how to configure DotNet Lambda Functions to be powered by AWS Graviton2 Processors and review the results found.

Graviton2 Lambda Overview

  • AWS Lambda functions powered by AWS Graviton2 processors offer up to 34% better price performance over x86-based Lambda functions.
  • Configured by a new field “Architectures” in FunctionConfiguration data type with 2 possible values (x86_64 or arm64(Graviton2)
  • At launch, currently available for Python, Node, Java, .NET 3.1, Ruby, Custom Runtime (provided.al2) and OCI Base Images
  • At launch, 10 regions will be supported including Asia Pacific(Mumbai), Asia Pacific(Singapore), Asia Pacific(Sydney), Asia Pacific(Tokyo), EU (Frankfurt) EU(Ireland), EU(London), US East (N.Virginia), US East(Ohio) and US West(Oregon)

Graviton2 C# CDK Demonstration

We will now demonstrate the performance improvements of Graviton2 powered Lambda functions with a DotNet with CDK. Xerris has been granted access to the private beta of the Graviton2 powered Lambda functions. If you are unfamiliar with how to create DotNet Graviton2 powered Lambda functions with CDK and want to learn more please refer to Creating an AWS Serverless C# DotNet Application

For this demonstration, we will compare two Lambda functions executing an identical compute only workload. The only difference will be that one is using the x86_64 architecture and the other one will be using the new Graviton2(arm64) architecture.

Creating the Project

Let’s create the project in a cmd shell

cd c:\projects
mkdir DotNetGravitonLambda
cd DotNetGravitonLambda
cdk init --language csharp
dotnet new lambda.EmptyFunction --name Lambdas

You should then be able to open the solution file located in C:\projects\DotNetGravitonLambda\src\DotNetGravitonLambda.sln with Visual Studio

Open Visual Studio, go to the Solution Explorer, right click , select Add, Existing Project…

Navigate to the Lambdas project file

In my case it is located at C:\projects\DotNetGravitonLambda\Lambdas\src\Lambdas\Lambdas.csproj

You should now have 2 projects DotNetGravitonLambda and Lambdas.

You should be able to right click on Solution in the Solution Explorer and Rebuild the solution successfully

The 2 files to examine are:

Program.cs: The entry point for your DotNetGravitonLambda application

DotNetGravitonLambdaAppStack.cs: This class will define your DotNetGravitonLambda stack to determine which AWS Infrastructure resources get generated. It is currently empty.

Go to the command line and execute the following commands to verify that the cdk project is working fine.

cd c:\projects\DotNetGravitonLambda
cdk bootstrap
cdk synth
cdk deploy

You should now see that your code stack has been deployed to your AWS Console successfully by looking under the CloudFormation service as follows:

Making the code changes

Please replace the following 2 classes with the code found at https://github.com/collin-smith/DotNetGravitonLambda

DotNetGravitonLambdaStack.cs

C:\projects\DotNetGravitonLambda\src\DotNetGravitonLambda\DotNetGravitonLambdaStack.cs

Function.cs

C:\projects\DotNetGravitonLambda\Lambdas\src\Lambdas\Function.cs

The next step should be to resolve the missing references by managing the nuget packages until the solution successfully builds

Right click in the Solution Explorer and select “Manage Nuget Packages for Solution…”. Follow the same process as you did for the Amazon.CDK package above.

Required packages include

Amazon.Lambda.APIGatewayEvents

Amazon.CDK.AWS.APIGateway

Once it successfully builds you can then redeploy it to your aws account as follows

cd c:\projects\DotNetGravitonLambda
cdk bootstrap
cdk synth
cdk deploy

You should see the 2 new Lambdas under the Lambda section of the AWS Console

Graviton2 Configuration

The arm64 architecture is configured as follows in our DotNet CDK code.

Architecture[] armArchitecture = new Architecture[1];
armArchitecture[0] = Architecture.ARM_64;
var gravitonSimpleLambdaHandler2 = new Function(this, "gravitonSimpleLambdaHandler", new FunctionProps
{
Runtime = Runtime.DOTNET_CORE_3_1,
FunctionName = "gravitonDotNetSimpleLambda",
MemorySize = 512,
Timeout = Duration.Seconds(50),
Architectures = armArchitecture,
Code = Code.FromAsset("Lambdas\\src\\Lambdas\\bin\\Debug\\netcoreapp3.1"),
Handler = "Lambdas::Lambdas.Function::SimpleLambdaHandler",
Environment = new Dictionary<string, string>{["ENVIRONMENT"] = environment}
});

Each Lambda runs an identical workload basically executing the following CPU Intensive Task:

private static void executeCPUIntensiveTask(){
//some cpu intensive task
long limit = 5000;
String lastSqRoot = "";
for (int i = 0; i < limit; i++)
{
for (int j = 0; j < limit; j++)
{
double sqroot = Math.Sqrt(j);
lastSqRoot = "" + sqroot;
}
}
Console.WriteLine("lastSqRoot=" + lastSqRoot);
}

The 2 Lambdas as seen in the aws console:

dotNetSimpleLambda runs with the x86_64 architecture

gravitonDotNetSimpleLamba runs with the arm64 architecture

Performance results with Graviton2

The lambdas will display how long it takes to execute the cpu intensive task above.

Let us run the lambda functions in the console to see how long they take:

3 runs of dotNetSimpleLambda(x86_64): 35.180, 34.080, 34.850 = Average of 34.703ms

3 runs of gravitonDotNetSimpleLambda(arm64): 34.726, 34.721, 34.738 = Average of 34.728ms

Based in this small sample test, it appears that the graviton2(arm64) based Lambda functions are marginally slower than the x86_64 based Lambdas. In this case it shows that the graviton2 Lambdas are 0.072% slower on the Graviton2 architecture. However, it can be seen that sometimes the Graviton2 lambdas perform better in some test runs.

I would prefer to say that they are are very similar performance wise with a slight edge to the x86_64 architecture over the graviton2(arm64) architecture. I invite the reader to pull the code provided above to confirm if they wish.

Price improvements with Graviton2

In terms of price, the Arm Price(Graviton2) wins hands down.

For example in the US West Region, for a x86 price for a 128MB Lambda the price is $0.0000000021 per 1ms compared to $0.0000000017 per 1ms. This is a savings of about 20%.

Please consult https://aws.amazon.com/lambda/pricing/ for current pricing.

Conclusion

Customers will save money with DotNet Lambda Functions on Graviton2. This can be a big win for customers who want to save money.

After reviewing my results with AWS, it was mentioned that if there was more multi-threaded code, then the performance would be even better but if it’s mostly single threaded and not as heavy usage, then the results are in line.

To summarize, Graviton2 DotNet Lambdas provide a definite cost advantage of about 20% and maintaining similar performance levels when compared to the x86_84 architecture.

With Java based workloads we saw essentially that the arm64 workloads were basically twice as fast. The Java Graviton2 Lambda function testing results can be found at https://collin-smith.medium.com/aws-lambda-functions-powered-by-aws-graviton2-processors-9d8ecb1f5790.

For more information on Graviton2 powered lambda functions please consult https://aws.amazon.com/blogs/aws/aws-lambda-functions-powered-by-aws-graviton2-processor-run-your-functions-on-arm-and-get-up-to-34-better-price-performance/ . Xerris was an AWS Launch Partner for this feature release.

Do not hesitate to reach out to us at Xerris.com for more information about your organization’s needs and how we can help you.

--

--

Collin Smith

AWS Ambassador/Solutions Architect/Ex-French Foreign Legion