-
Notifications
You must be signed in to change notification settings - Fork 13
Add integration for setting up SQS event source for a Lambda function. #47
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
Changes from 3 commits
5790641
b37137f
2b391ba
d390005
17c7feb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"Projects": [ | ||
{ | ||
"Name": "Aspire.Hosting.AWS", | ||
"Type": "Patch", | ||
"ChangelogMessages": [ | ||
"Add support for configuring SQS event source for a Lambda function", | ||
"Update version of Amazon.Lambda.TestTool to install to version 0.10.0" | ||
] | ||
} | ||
] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -402,4 +402,7 @@ FodyWeavers.xsd | |
# JetBrains Rider | ||
*.sln.iml | ||
|
||
.idea/ | ||
.idea/ | ||
|
||
# CDK temp files | ||
**/cdk.out/** |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
using Amazon.Lambda.Core; | ||
using Amazon.Lambda.SQSEvents; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Hosting; | ||
using OpenTelemetry.Instrumentation.AWSLambda; | ||
using OpenTelemetry.Trace; | ||
|
||
// Assembly attribute to enable the Lambda function's JSON input to be converted into a .NET class. | ||
[assembly: LambdaSerializer(typeof(Amazon.Lambda.Serialization.SystemTextJson.DefaultLambdaJsonSerializer))] | ||
|
||
namespace SQSProcessorFunction; | ||
|
||
public class Function | ||
{ | ||
IHost _host; | ||
TracerProvider _traceProvider; | ||
|
||
public Function() | ||
{ | ||
var builder = new HostApplicationBuilder(); | ||
|
||
builder.AddServiceDefaults(); | ||
_host = builder.Build(); | ||
|
||
_traceProvider = _host.Services.GetRequiredService<TracerProvider>(); | ||
} | ||
|
||
public Task FunctionHandler(SQSEvent evnt, ILambdaContext context) | ||
=> AWSLambdaWrapper.TraceAsync(_traceProvider, async (evnt, context) => | ||
{ | ||
foreach (var message in evnt.Records) | ||
{ | ||
await ProcessMessageAsync(message, context); | ||
} | ||
}, evnt, context); | ||
|
||
private async Task ProcessMessageAsync(SQSEvent.SQSMessage message, ILambdaContext context) | ||
{ | ||
context.Logger.LogInformation($"Processed message {message.Body}"); | ||
|
||
// TODO: Do interesting work based on the new message | ||
await Task.CompletedTask; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"profiles": { | ||
"Mock Lambda Test Tool": { | ||
"commandName": "Executable", | ||
"commandLineArgs": "--port 5050", | ||
"workingDirectory": ".\\bin\\$(Configuration)\\net8.0", | ||
"executablePath": "%USERPROFILE%\\.dotnet\\tools\\dotnet-lambda-test-tool-8.0.exe" | ||
}, | ||
"Aspire_ProcessorFunction": { | ||
"commandName": "Executable", | ||
"executablePath": "dotnet", | ||
"commandLineArgs": "exec --depsfile ./SQSProcessorFunction.deps.json --runtimeconfig ./SQSProcessorFunction.runtimeconfig.json %USERPROFILE%\\.dotnet\\tools\\.store\\amazon.lambda.testtool\\0.9.999\\amazon.lambda.testtool\\0.9.999\\content\\Amazon.Lambda.RuntimeSupport\\net8.0\\Amazon.Lambda.RuntimeSupport.dll SQSProcessorFunction::SQSProcessorFunction.Function::FunctionHandler", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i think this is here by accident right? you only want the one below - the 0.10.0 version |
||
"workingDirectory": ".\\bin\\$(Configuration)\\net8.0" | ||
}, | ||
"Aspire_SQSProcessorFunction": { | ||
"commandName": "Executable", | ||
"executablePath": "dotnet", | ||
"commandLineArgs": "exec --depsfile ./SQSProcessorFunction.deps.json --runtimeconfig ./SQSProcessorFunction.runtimeconfig.json %USERPROFILE%\\.dotnet\\tools\\.store\\amazon.lambda.testtool\\0.10.0\\amazon.lambda.testtool\\0.10.0\\content\\Amazon.Lambda.RuntimeSupport\\net8.0\\Amazon.Lambda.RuntimeSupport.dll SQSProcessorFunction::SQSProcessorFunction.Function::FunctionHandler", | ||
"workingDirectory": ".\\bin\\$(Configuration)\\net8.0" | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles> | ||
<AWSProjectType>Lambda</AWSProjectType> | ||
<!-- This property makes the build directory similar to a publish directory and helps the AWS .NET Lambda Mock Test Tool find project dependencies. --> | ||
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies> | ||
<!-- Generate ready to run images during publishing to improve cold start time. --> | ||
<PublishReadyToRun>true</PublishReadyToRun> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<PackageReference Include="Amazon.Lambda.Core" /> | ||
<PackageReference Include="Amazon.Lambda.Serialization.SystemTextJson" /> | ||
<PackageReference Include="Amazon.Lambda.SQSEvents" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\Lambda.ServiceDefaults\Lambda.ServiceDefaults.csproj" /> | ||
</ItemGroup> | ||
</Project> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"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": "default", | ||
"region": "us-west-2", | ||
"configuration": "Release", | ||
"function-runtime": "dotnet8", | ||
"function-memory-size": 512, | ||
"function-timeout": 30, | ||
"function-handler": "SQSProcessorFunction::SQSProcessorFunction.Function::FunctionHandler" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,27 +2,33 @@ | |
"profiles": { | ||
"Aspire_AddFunction": { | ||
"commandName": "Executable", | ||
"commandLineArgs": "exec --depsfile ./WebCalculatorFunctions.deps.json --runtimeconfig ./WebCalculatorFunctions.runtimeconfig.json %USERPROFILE%\\.dotnet\\tools\\.store\\amazon.lambda.testtool\\0.0.2-preview\\amazon.lambda.testtool\\0.0.2-preview\\content\\Amazon.Lambda.RuntimeSupport\\net8.0\\Amazon.Lambda.RuntimeSupport.dll WebCalculatorFunctions::WebCalculatorFunctions.Functions::AddFunctionHandler", | ||
"commandLineArgs": "exec --depsfile ./WebCalculatorFunctions.deps.json --runtimeconfig ./WebCalculatorFunctions.runtimeconfig.json %USERPROFILE%\\.dotnet\\tools\\.store\\amazon.lambda.testtool\\0.10.0\\amazon.lambda.testtool\\0.10.0\\content\\Amazon.Lambda.RuntimeSupport\\net8.0\\Amazon.Lambda.RuntimeSupport.dll WebCalculatorFunctions::WebCalculatorFunctions.Functions::AddFunctionHandler", | ||
"workingDirectory": ".\\bin\\$(Configuration)\\net8.0", | ||
"executablePath": "dotnet" | ||
}, | ||
"Aspire_MinusFunction": { | ||
"commandName": "Executable", | ||
"commandLineArgs": "exec --depsfile ./WebCalculatorFunctions.deps.json --runtimeconfig ./WebCalculatorFunctions.runtimeconfig.json %USERPROFILE%\\.dotnet\\tools\\.store\\amazon.lambda.testtool\\0.0.2-preview\\amazon.lambda.testtool\\0.0.2-preview\\content\\Amazon.Lambda.RuntimeSupport\\net8.0\\Amazon.Lambda.RuntimeSupport.dll WebCalculatorFunctions::WebCalculatorFunctions.Functions::MinusFunctionHandler", | ||
"commandLineArgs": "exec --depsfile ./WebCalculatorFunctions.deps.json --runtimeconfig ./WebCalculatorFunctions.runtimeconfig.json %USERPROFILE%\\.dotnet\\tools\\.store\\amazon.lambda.testtool\\0.10.0\\amazon.lambda.testtool\\0.10.0\\content\\Amazon.Lambda.RuntimeSupport\\net8.0\\Amazon.Lambda.RuntimeSupport.dll WebCalculatorFunctions::WebCalculatorFunctions.Functions::MinusFunctionHandler", | ||
"workingDirectory": ".\\bin\\$(Configuration)\\net8.0", | ||
"executablePath": "dotnet" | ||
}, | ||
"Aspire_MultiplyFunction": { | ||
"commandName": "Executable", | ||
"commandLineArgs": "exec --depsfile ./WebCalculatorFunctions.deps.json --runtimeconfig ./WebCalculatorFunctions.runtimeconfig.json %USERPROFILE%\\.dotnet\\tools\\.store\\amazon.lambda.testtool\\0.0.2-preview\\amazon.lambda.testtool\\0.0.2-preview\\content\\Amazon.Lambda.RuntimeSupport\\net8.0\\Amazon.Lambda.RuntimeSupport.dll WebCalculatorFunctions::WebCalculatorFunctions.Functions::MultiplyFunctionHandler", | ||
"commandLineArgs": "exec --depsfile ./WebCalculatorFunctions.deps.json --runtimeconfig ./WebCalculatorFunctions.runtimeconfig.json %USERPROFILE%\\.dotnet\\tools\\.store\\amazon.lambda.testtool\\0.10.0\\amazon.lambda.testtool\\0.10.0\\content\\Amazon.Lambda.RuntimeSupport\\net8.0\\Amazon.Lambda.RuntimeSupport.dll WebCalculatorFunctions::WebCalculatorFunctions.Functions::MultiplyFunctionHandler", | ||
"workingDirectory": ".\\bin\\$(Configuration)\\net8.0", | ||
"executablePath": "dotnet" | ||
}, | ||
"Aspire_DivideFunction": { | ||
"commandName": "Executable", | ||
"commandLineArgs": "exec --depsfile ./WebCalculatorFunctions.deps.json --runtimeconfig ./WebCalculatorFunctions.runtimeconfig.json %USERPROFILE%\\.dotnet\\tools\\.store\\amazon.lambda.testtool\\0.0.2-preview\\amazon.lambda.testtool\\0.0.2-preview\\content\\Amazon.Lambda.RuntimeSupport\\net8.0\\Amazon.Lambda.RuntimeSupport.dll WebCalculatorFunctions::WebCalculatorFunctions.Functions::DivideFunctionHandler", | ||
"commandLineArgs": "exec --depsfile ./WebCalculatorFunctions.deps.json --runtimeconfig ./WebCalculatorFunctions.runtimeconfig.json %USERPROFILE%\\.dotnet\\tools\\.store\\amazon.lambda.testtool\\0.10.0\\amazon.lambda.testtool\\0.10.0\\content\\Amazon.Lambda.RuntimeSupport\\net8.0\\Amazon.Lambda.RuntimeSupport.dll WebCalculatorFunctions::WebCalculatorFunctions.Functions::DivideFunctionHandler", | ||
"workingDirectory": ".\\bin\\$(Configuration)\\net8.0", | ||
"executablePath": "dotnet" | ||
}, | ||
"Mock Lambda Test Tool": { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i think this auto generated one from the aws toolkit will end up confusing customers - we should probably see about getting rid of this eventually sooner than later There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Deleted |
||
"commandName": "Executable", | ||
"commandLineArgs": "--port 5050", | ||
"workingDirectory": ".\\bin\\$(Configuration)\\net8.0", | ||
"executablePath": "%USERPROFILE%\\.dotnet\\tools\\dotnet-lambda-test-tool-8.0.exe" | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we remove this line?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Deleted. I also added a gitignore entry for playground launchsettings.json.