Skip to content

fix: Add .NET 8 runtime example #685

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

Merged
merged 2 commits into from
Jun 19, 2025

Conversation

Vlaaaaaaad
Copy link
Contributor

@Vlaaaaaaad Vlaaaaaaad commented Jun 19, 2025

Description

Added documentation for how this module can be used to deploy a tiny .NET 8 Lambda function.

Motivation and Context

TL;DR: Python annoyed me so much I decided to move to .NET 😅 Just like with Python, there are 30 different ways to package a .NET Lambda — this PR adds a super-simple dotnet8 example. To run this brew install --cask dotnet-sdk will probably be needed.

Late last year, after getting annoyed for the millionth time with Python's packaging (yes, I know uv and Flox exist), I decided to start moving some Lambdas to .NET. I was surprised to see no docs for how to use this module to deploy a dotnet8 Lambda — no examples, no issues, no discussions, no anything. Yesterday I finally remembered to create this Pull Request to update the docs 🙂

Just like with Python, there are a ton of ways to package a .NET Lambda:

For all the above, of course, there are even more options:

In addition to me not having any idea how to do most of the above and in addition to me failing to do some of the above things (dotnet lambda package generates a zip already and getting that to play nicely with the package.py script from this module was... too much for me), adding all that would've been confusing and unnecessary. Plus, you know, a lot of code that would have had to be maintained and updated.

Finally I decided to add the most minimal example I could think of: a .NET8 Lambda using top-level statements (i.e. no classes and no factories and no 10 different .cs files) that's straightforward packaged in a .zip and ran using the AWS-maintained-and-managed dotnet8 runtime.
To actually run this, folks will need to install dotnet on their machines: either using the .NET installer or with Homebrew by running brew install --cask dotnet-sdk. The latest version of .NET should be installed (currently latest stable is 9 and latest long-term support is 8) as it can build packages for a lot of targets: from way before dotnet5 and all the way to dotnet9.

Breaking Changes

No breaking change for users of the module since this is a docs-only change.

For developers working on this module that want to run the examples/runtimes code, dotnet will have to be installed.

How Has This Been Tested?

  • I have updated at least one of the examples/* to demonstrate and validate my change(s)
  • I have tested and validated these changes using one or more of the provided examples/* projects
  • I have executed pre-commit run -a on my pull request

I also ran a terraform apply and confirmed the .NET 8 Lambda function was correctly created and that it was working. I commented out the other runtimes as I did not have the dependencies installed and I am ignoring the warning caused by the newly-released v6.0.0 of the AWS Terraform Provider:

Plan: 7 to add, 0 to change, 0 to destroy.

Changes to Outputs:
  + dotnet8_lambda_function_url  = (known after apply)
  + lambda_function_result       = {}
  + lambda_function_status_codes = {
      + dotnet8 = (known after apply)
    }
random_pet.this: Creating...
random_pet.this: Creation complete after 0s [id=pleasant-moccasin]
module.dotnet8_lambda_function.local_file.archive_plan[0]: Creating...
module.dotnet8_lambda_function.local_file.archive_plan[0]: Creation complete after 0s [id=6d4c946421e692953040ec9a9b61001dfbcfe686]
module.dotnet8_lambda_function.null_resource.archive[0]: Creating...
module.dotnet8_lambda_function.null_resource.archive[0]: Provisioning with 'local-exec'...
module.dotnet8_lambda_function.null_resource.archive[0] (local-exec): Executing: ["python3" "../../package.py" "build" "--timestamp" "1750341320306367000" "builds/92cf0e05b510d4bb6e4576ae3034c2b45cded791505c3dbd1aee936c2c857dd4.plan.json"]
module.dotnet8_lambda_function.null_resource.archive[0] (local-exec): zip: creating 'builds/92cf0e05b510d4bb6e4576ae3034c2b45cded791505c3dbd1aee936c2c857dd4.zip' archive
module.dotnet8_lambda_function.aws_cloudwatch_log_group.lambda[0]: Creating...
module.dotnet8_lambda_function.aws_iam_role.lambda[0]: Creating...
module.dotnet8_lambda_function.aws_cloudwatch_log_group.lambda[0]: Creation complete after 1s [id=/aws/lambda/pleasant-moccasin-dotnet8]
module.dotnet8_lambda_function.aws_iam_role.lambda[0]: Creation complete after 2s [id=pleasant-moccasin-dotnet8]
module.dotnet8_lambda_function.null_resource.archive[0] (local-exec): zip: adding content of directory: /Users/vlad/Developer/vlaaaaaaad/terraform-aws-lambda/examples/fixtures/runtimes/dotnet8/publish
module.dotnet8_lambda_function.null_resource.archive[0] (local-exec): zip: adding: Amazon.Lambda.Core.dll
module.dotnet8_lambda_function.null_resource.archive[0] (local-exec): zip: adding: Amazon.Lambda.RuntimeSupport.dll
module.dotnet8_lambda_function.null_resource.archive[0] (local-exec): zip: adding: Amazon.Lambda.Serialization.SystemTextJson.dll
module.dotnet8_lambda_function.null_resource.archive[0] (local-exec): zip: adding: SnapshotRestore.Registry.dll
module.dotnet8_lambda_function.null_resource.archive[0] (local-exec): zip: adding: bootstrap
module.dotnet8_lambda_function.null_resource.archive[0] (local-exec): zip: adding: bootstrap.deps.json
module.dotnet8_lambda_function.null_resource.archive[0] (local-exec): zip: adding: bootstrap.dll
module.dotnet8_lambda_function.null_resource.archive[0] (local-exec): zip: adding: bootstrap.pdb
module.dotnet8_lambda_function.null_resource.archive[0] (local-exec): zip: adding: bootstrap.runtimeconfig.json
module.dotnet8_lambda_function.null_resource.archive[0] (local-exec): Created: builds/92cf0e05b510d4bb6e4576ae3034c2b45cded791505c3dbd1aee936c2c857dd4.zip
module.dotnet8_lambda_function.null_resource.archive[0]: Creation complete after 5s [id=1582037579302064648]
module.dotnet8_lambda_function.aws_lambda_function.this[0]: Creating...
module.dotnet8_lambda_function.aws_lambda_function.this[0]: Still creating... [00m10s elapsed]
module.dotnet8_lambda_function.aws_lambda_function.this[0]: Creation complete after 11s [id=pleasant-moccasin-dotnet8]
module.dotnet8_lambda_function.aws_lambda_function_url.this[0]: Creating...
module.dotnet8_lambda_function.aws_lambda_function_url.this[0]: Creation complete after 0s [id=pleasant-moccasin-dotnet8]
data.http.this["dotnet8"]: Reading...
data.http.this["dotnet8"]: Read complete after 1s [id=https://xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.lambda-url.eu-west-1.on.aws/]

│ Warning: Deprecated attribute

│   on ../../outputs.tf line 9, in output "lambda_function_arn_static":
│    9:   value       = local.create && var.create_function && !var.create_layer ? "arn:${data.aws_partition.current.partition}:lambda:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:function:${var.function_name}" : ""

│ The attribute "name" is deprecated. Refer to the provider documentation for details.

│ (and 2 more similar warnings elsewhere)


Apply complete! Resources: 7 added, 0 changed, 0 destroyed.

Outputs:

dotnet8_lambda_function_url = "https://xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.lambda-url.eu-west-1.on.aws/"
lambda_function_result = {}
lambda_function_status_codes = {
  "dotnet8" = 200
}

Let me know if there's anything I missed or if I should change anything!

@Vlaaaaaaad Vlaaaaaaad changed the title docs: dotnet8 runtime example docs: Add .NET 8 runtime example Jun 19, 2025
Copy link
Member

@antonbabenko antonbabenko left a comment

Choose a reason for hiding this comment

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

Trying to run it on the Mac where dotnet has never existed before. brew install --cask dotnet executed successfully. What else should be installed? Maybe update the README.md or issue desciption.

│ RuntimeError: Script did not run successfully, exit code 1:  - The command could not be loaded, possibly because:
│   * You intended to execute a .NET application:
│       The application 'publish' does not exist.
│   * You intended to execute a .NET SDK command:
│       No .NET SDKs were found.
│ 
│ Download a .NET SDK:
│ https://aka.ms/dotnet/download
│ 
│ Learn about SDK resolution:
│ https://aka.ms/dotnet/sdk-not-found

@Vlaaaaaaad
Copy link
Contributor Author

Oh god, this is embarrassing — I totally had the wrong instructions 🤦 The correct command to install .NET is brew install --cask dotnet-sdk, with the -sdk part. Installing dotnet adds only the runtime which, of course, can't compile code. I tested this on my machine and I can confirm that dotnet failed but dotnet-sdk worked.

@antonbabenko can you run a brew uninstall dotnet && brew install --cask dotnet-sdk please? I believe that should fix it. If it doesn't... I'l be very confused and go on a deeper dive into what is actually happening.

My apologies!

Copy link
Member

@antonbabenko antonbabenko left a comment

Choose a reason for hiding this comment

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

It works!

@antonbabenko antonbabenko changed the title docs: Add .NET 8 runtime example fix: Add .NET 8 runtime example Jun 19, 2025
@antonbabenko antonbabenko merged commit d5c657c into terraform-aws-modules:master Jun 19, 2025
31 of 32 checks passed
antonbabenko pushed a commit that referenced this pull request Jun 19, 2025
## [7.21.1](v7.21.0...v7.21.1) (2025-06-19)

### Bug Fixes

* Add .NET 8 runtime example ([#685](#685)) ([d5c657c](d5c657c))
@antonbabenko
Copy link
Member

This PR is included in version 7.21.1 🎉

@antonbabenko
Copy link
Member

Thank you for adding the example for the .NET runtime!

@Vlaaaaaaad
Copy link
Contributor Author

Thank you for all your work on these awesome modules ❣️

@Vlaaaaaaad Vlaaaaaaad deleted the dotnet8 branch June 19, 2025 18:05
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.

2 participants