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

Update Lambda blueprints for .NET 8 #1673

Merged
merged 3 commits into from
Feb 20, 2024
Merged

Conversation

normj
Copy link
Member

@normj normj commented Feb 17, 2024

Description of changes:
In preparation for .NET 8 Lambda support update the blueprints. The update has the following changes.

  • Update all TargetFramework tags to net8.0.
  • Update Lambda runtime targets to dotnet8
  • Update the default memory size to 512 to match what is done in other languages like Java.
  • Updated referenced in README files for target frameworks and Amazon Linux versions.
  • Update Simple DynamoDB blueprint to handle the recent major version bump of the event package. That major version bump removed the dependency from the event package to the AWSSDK.DynamoDBv2 package.
  • Update the serverless Native AOT blueprint to use Amazon.Lambda.Annotations. This takes care of generating the required main method.
  • Update all of the AWS package references in the blueprints project files. This includes Lambda, SDK and PowerTools packages. The versions are updated using the following msbuild command from our build.proj file
dotnet msbuild .\buildtools\build.proj /t:run-blueprint-packager /p:UpdateBlueprintPackageVersions=true
  • Native AOT projects will target the dotnet8 runtime instead of provided.al2023. This is done because provided.al2023 does not have the required libicu system library and avoid having to include it with the deployment bundle. You will see in the project files the removal of the logic to include libicu. This also remove the need to name the assembly as bootstrap.

Testing

Run the msbuild target /t:test-blueprints-dotnew that confirms all blueprints can be instantiated and compiled
Manually deployments of the Native AOT and DynamoDB blueprints that had significant changes.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@normj normj force-pushed the normj/dotnet8-blueprints branch from 243397b to f19623f Compare February 17, 2024 01:01

namespace BlueprintBaseName._1;

/// <summary>
Copy link
Member Author

@normj normj Feb 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the serverless Native AOT blueprint. It used to have its own Main method and logic for switching to the correct method based on an environment variable. Amazon.Lambda.Annotations can now do all of this for us so I removed all of the logic and relied on Lambda Annotations.

I the Lambda methods, JsonSerializerContext and the .NET records in the same file to make it really easy for users that start with this template quickly delete what they don't need once they understand how this works.

@@ -1,12 +1,9 @@
namespace BlueprintBaseName._1.Tests
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file has significant changes to deal with change to move to new major version of Amazon.Lambda.DynamoDBEvents which removed the dependency on the SDK.

@@ -1,11 +1,9 @@
using Xunit;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file has significant changes to deal with change to move to new major version of Amazon.Lambda.DynamoDBEvents which removed the dependency on the SDK.

@@ -5,7 +5,7 @@
"Lambda",
"Function"
],
"name": "Lambda Empty Function (.NET 7 Container Image)",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You removed "NET"

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed


namespace BlueprintBaseName._1;

/// <summary>
/// This class is used to register the input event and return type for the FunctionHandler method with the System.Text.Json source generator.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: use doc reference for all the types you mentioned in docs

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm gonna skip doing this now. We haven't made any effort to doc references in code elements in the other blueprints and if we want to do that we should do that as a separate effort.

I'm a little hesitant to use them here anyways because these comments are meant to be easily readable while reading the code in this file. Not via a doc site or intellisense. Think of these docs as more of a developer guide type content as you are reading the source. I expect users to replace all of this content with the actual content useful to their problem. Having to read the content with a bunch of xml tags useful for a doc site or intellisense makes it harder to read.

Comment on lines 40 to 41


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: remove whitespace

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment on lines 45 to 46
/// <param name="context"></param>
/// <returns></returns>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: add docs to empty attributes

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

// SDK for .NET does not support trimming. This will result in a larger executable size, and still does not
// guarantee runtime trimming errors won't be hit.
/// This method demonstrates methods being exposed as Lambda functions using Amazon.Lambda.Annotations without API Gateway attributes.
/// The event source for the Lambda function can be configured in the serverless.template. The method can also Lambda function can
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the sentence is weirdly formed "The method can also Lambda function can be invoked manually using the AWS SDKs.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

For Native AOT Lambda functions the project must be deployed as an executable and bootstrap the Lambda runtime client. Lambda Annotations
will automatically generate the `Main` by using the `GenerateMain` property of `LambdaGlobalProperties` attribute to true. The generated
`Main` method uses the environment variable `ANNOTATIONS_HANDLER` to switch to the correct function handler for the executable. Lambda
Annotations will automatically set the `ANNOTATIONS_HANDLER` environment variable when synchronize the CloudFormation template. If deploying
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: typo in "synchronize"

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

@normj normj merged commit a4007ba into net8-staging Feb 20, 2024
4 checks passed
@normj normj deleted the normj/dotnet8-blueprints branch February 20, 2024 20:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants