-
-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
116 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
using System; | ||
using System.Text.Json.Serialization; | ||
using System.Threading.Tasks; | ||
using Amazon.Lambda.Core; | ||
using Amazon.Lambda.SQSEvents; | ||
using Kralizek.Lambda; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Logging; | ||
|
||
[assembly: LambdaSerializer(typeof(Amazon.Lambda.Serialization.SystemTextJson.DefaultLambdaJsonSerializer))] | ||
|
||
namespace SqsBatchResponseFunction; | ||
|
||
public class Function : RequestResponseFunction<SQSEvent, SQSBatchResponse> | ||
{ | ||
protected override void Configure(IConfigurationBuilder builder) | ||
{ | ||
builder.AddEnvironmentVariables(); | ||
} | ||
|
||
protected override void ConfigureLogging(ILoggingBuilder logging, IExecutionEnvironment executionEnvironment) | ||
{ | ||
logging.AddConfiguration(Configuration.GetSection("Logging")); | ||
|
||
logging.AddLambdaLogger(new LambdaLoggerOptions | ||
{ | ||
IncludeCategory = true, | ||
IncludeLogLevel = true, | ||
IncludeNewline = true | ||
}); | ||
} | ||
|
||
protected override void ConfigureServices(IServiceCollection services, IExecutionEnvironment executionEnvironment) | ||
{ | ||
services.UseQueueMessageHandler<TestMessage, TestMessageHandler>(); | ||
} | ||
} | ||
|
||
public class TestMessage | ||
{ | ||
[JsonPropertyName("message")] | ||
public string? Message { get; set; } | ||
} | ||
|
||
public class TestMessageHandler : IMessageHandler<TestMessage> | ||
{ | ||
private readonly ILogger<TestMessageHandler> _logger; | ||
|
||
public TestMessageHandler(ILogger<TestMessageHandler> logger) | ||
{ | ||
_logger = logger ?? throw new ArgumentNullException(nameof(logger)); | ||
} | ||
|
||
public Task HandleAsync(TestMessage? message, ILambdaContext context) | ||
{ | ||
_logger.LogInformation("Received notification: {Message}", message?.Message); | ||
|
||
if (message is { Message.Length: > 0 }) | ||
{ | ||
if (message.Message.Contains("bad message", StringComparison.OrdinalIgnoreCase)) | ||
{ | ||
throw new ArgumentException("message supplied was a bad message", nameof(message)); | ||
} | ||
} | ||
|
||
return Task.CompletedTask; | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
samples/SqsBatchResponseFunction/SqsBatchResponseFunction.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Amazon.Lambda.Logging.AspNetCore" Version="3.1.0" /> | ||
<PackageReference Include="Microsoft.Extensions.Logging.Configuration" Version="6.0.0" /> | ||
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="6.0.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\src\Kralizek.Lambda.Template.Sqs\Kralizek.Lambda.Template.Sqs.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
21 changes: 21 additions & 0 deletions
21
samples/SqsBatchResponseFunction/aws-lambda-tools-defaults.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"Information": [ | ||
"This file provides default values for the deployment wizard inside Visual Studio and the AWS Lambda commands added to the .NET Core CLI.", | ||
"To learn more about the Lambda commands with the .NET Core CLI execute the following command at the command line in the project root directory.", | ||
|
||
"dotnet lambda help", | ||
|
||
"All the command line options for the Lambda command can be specified in this file." | ||
], | ||
|
||
"profile": "", | ||
"region": "", | ||
"configuration": "Release", | ||
"framework": "net6.0", | ||
"function-name": "SqsBatchResponseFunction", | ||
"function-role": "", | ||
"function-runtime": "dotnet6", | ||
"function-memory-size": 128, | ||
"function-timeout": 30, | ||
"function-handler": "SqsBatchResponseFunction::SqsBatchResponseFunction.Function::FunctionHandlerAsync" | ||
} |