Minimal API details and further examples #1243
-
Could anyone be so kind as to point me into a direction that has more details about using the minimal api within lambda? I'm not clear on how or if the ILambdaContext is provided in the request, Any help would be greatly appreciated, |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
@jcanady20 What is your use case? Minimal APIs are an ASP.NET API thing. So you can't dual purpose that with S3Events. You need separate lambdas for something to field S3 events, versus a minimal api endpoint. This is the library you want to use for minimal apis: https://github.com/aws/aws-lambda-dotnet/tree/master/Libraries/src/Amazon.Lambda.AspNetCoreServer.Hosting The key line being: builder.Services.AddAWSLambdaHosting(LambdaEventSource.HttpApi); For fielding S3 events, your lamba would look like what is outlined here: public class Function
{
public string Handler(S3Event s3Event, ILambdaContext context)
{
foreach(var record in s3Event.Records)
{
var s3 = record.S3;
Console.WriteLine($"[{record.EventSource} - {record.EventTime}] Bucket = {s3.Bucket.Name}, Key = {s3.Object.Key}");
}
}
} |
Beta Was this translation helpful? Give feedback.
@jcanady20 What is your use case?
Minimal APIs are an ASP.NET API thing. So you can't dual purpose that with S3Events. You need separate lambdas for something to field S3 events, versus a minimal api endpoint.
This is the library you want to use for minimal apis: https://github.com/aws/aws-lambda-dotnet/tree/master/Libraries/src/Amazon.Lambda.AspNetCoreServer.Hosting
The key line being:
For fielding S3 events, your lamba would look like what is outlined here:
https://github.com/aws/aws-lambda-dotnet/tree/master/Libraries/src/Amazon.Lambda.S3Events