Skip to content

Commit cafe74c

Browse files
committed
Add minimal dotnet8 example
1 parent f1f06ed commit cafe74c

File tree

6 files changed

+74
-3
lines changed

6 files changed

+74
-3
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using System.Text.Json;
2+
using Amazon.Lambda.Core;
3+
using Amazon.Lambda.RuntimeSupport;
4+
using Amazon.Lambda.Serialization.SystemTextJson;
5+
6+
[assembly: LambdaSerializer(typeof(DefaultLambdaJsonSerializer))]
7+
8+
var handler = (JsonElement input, ILambdaContext context) =>
9+
{
10+
context.Logger.LogInformation($"Processing input: {input}");
11+
return "Hello from serverless.tf!!!";
12+
};
13+
14+
await LambdaBootstrapBuilder.Create(handler, new DefaultLambdaJsonSerializer())
15+
.Build()
16+
.RunAsync();
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<TargetFramework>net8.0</TargetFramework>
4+
<AssemblyName>bootstrap</AssemblyName>
5+
<OutputType>Exe</OutputType>
6+
<PublishReadyToRun>true</PublishReadyToRun>
7+
<PublishAot>false</PublishAot>
8+
<ImplicitUsings>enable</ImplicitUsings>
9+
<Nullable>enable</Nullable>
10+
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
11+
</PropertyGroup>
12+
13+
<ItemGroup>
14+
<PackageReference Include="Amazon.Lambda.Core" Version="2.6.0" />
15+
<PackageReference Include="Amazon.Lambda.RuntimeSupport" Version="1.13.1" />
16+
<PackageReference Include="Amazon.Lambda.Serialization.SystemTextJson" Version="2.4.4" />
17+
</ItemGroup>
18+
</Project>

examples/runtimes/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Runtimes Examples
22

3-
Configuration in this directory creates deployment packages for [various runtimes and programming languages (Rust, Go, Java)](https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtimes.html).
3+
Configuration in this directory creates deployment packages for [various runtimes and programming languages (Rust, Go, Java, .NET)](https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtimes.html).
44

55
Each runtime is executable by calling created Lambda Functions at the end.
66

@@ -40,6 +40,7 @@ Note that this example may create resources which cost money. Run `terraform des
4040

4141
| Name | Source | Version |
4242
|------|--------|---------|
43+
| <a name="module_dotnet8_lambda_function"></a> [dotnet8\_lambda\_function](#module\_dotnet8\_lambda\_function) | ../../ | n/a |
4344
| <a name="module_go_lambda_function"></a> [go\_lambda\_function](#module\_go\_lambda\_function) | ../../ | n/a |
4445
| <a name="module_java21_lambda_function"></a> [java21\_lambda\_function](#module\_java21\_lambda\_function) | ../../ | n/a |
4546
| <a name="module_rust_lambda_function"></a> [rust\_lambda\_function](#module\_rust\_lambda\_function) | ../../ | n/a |
@@ -60,6 +61,7 @@ No inputs.
6061

6162
| Name | Description |
6263
|------|-------------|
64+
| <a name="output_dotnet8_lambda_function_url"></a> [dotnet8\_lambda\_function\_url](#output\_dotnet8\_lambda\_function\_url) | The URL of the Lambda Function in .NET 8 |
6365
| <a name="output_go_lambda_function_url"></a> [go\_lambda\_function\_url](#output\_go\_lambda\_function\_url) | The URL of the Lambda Function in Go |
6466
| <a name="output_java21_lambda_function_arn"></a> [java21\_lambda\_function\_arn](#output\_java21\_lambda\_function\_arn) | The ARN of the Lambda Function in Java 21 |
6567
| <a name="output_lambda_function_result"></a> [lambda\_function\_result](#output\_lambda\_function\_result) | The results of the Lambda Function calls |

examples/runtimes/checks.tf

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ locals {
44

55
data "http" "this" {
66
for_each = {
7-
rust = module.rust_lambda_function.lambda_function_url,
8-
go = module.go_lambda_function.lambda_function_url,
7+
rust = module.rust_lambda_function.lambda_function_url,
8+
go = module.go_lambda_function.lambda_function_url,
9+
dotnet8 = module.dotnet8_lambda_function.lambda_function_url,
910
}
1011

1112
url = each.value

examples/runtimes/main.tf

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,35 @@ module "java21_lambda_function" {
9393
]
9494
}
9595

96+
module "dotnet8_lambda_function" {
97+
source = "../../"
98+
99+
function_name = "${random_pet.this.id}-dotnet8"
100+
101+
attach_cloudwatch_logs_policy = false
102+
cloudwatch_logs_retention_in_days = 1
103+
104+
create_lambda_function_url = true
105+
106+
handler = "bootstrap"
107+
runtime = "dotnet8"
108+
architectures = ["arm64"] # x86_64 (--runtime linux-x64) or arm64 (--runtime linux-arm64)
109+
timeout = 30
110+
111+
trigger_on_package_timestamp = false
112+
113+
source_path = [
114+
{
115+
path = "${path.module}/../fixtures/runtimes/dotnet8"
116+
commands = [
117+
"dotnet publish --framework net8.0 --configuration Relesase --runtime linux-arm64 --output ./publish",
118+
"cd publish",
119+
":zip",
120+
]
121+
}
122+
]
123+
}
124+
96125
resource "random_pet" "this" {
97126
length = 2
98127
}

examples/runtimes/outputs.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ output "java21_lambda_function_arn" {
1313
value = module.java21_lambda_function.lambda_function_arn
1414
}
1515

16+
output "dotnet8_lambda_function_url" {
17+
description = "The URL of the Lambda Function in .NET 8"
18+
value = module.dotnet8_lambda_function.lambda_function_url
19+
}
20+
1621
output "lambda_function_result" {
1722
description = "The results of the Lambda Function calls"
1823
value = { for k, v in data.aws_lambda_invocation.this : k => jsondecode(v.result) }

0 commit comments

Comments
 (0)