Aspire integration with AWS Lambda project provided by AWS Toolkit for Visual Studio

0

Hi There,

I have been using AWS Lambda Project with ASP.NET Web API and deploying the same in AWS Lambda but now I want to integrate the .NET Aspire which is a cloud ready stack and gives many advantages like Observability support, etc..

in the AWS Lambda Project type we have two classes namely LambdaEntryPoint.cs and LocalEntryPoint.cs and I have done the changes in LocalEntryPoint.cs and running the project locally Aspire Dashboard is also coming but I want to deploy the same AWS Lambda and for this we need to change in LambdaEntryPoint.cs file and I am facing the issue for the same.

In the LambdaEntryPoint.cs I can see below two methods

/// <summary>
/// The builder has configuration, logging and Amazon API Gateway already configured. The startup class
/// needs to be configured in this method using the UseStartup<>() method.
/// </summary>
/// <param name="builder"></param>
protected override void Init(IWebHostBuilder builder)
{
    builder
        .UseStartup<Startup>();
}

/// <summary>
/// Use this override to customize the services registered with the IHostBuilder. 
/// 
/// It is recommended not to call ConfigureWebHostDefaults to configure the IWebHostBuilder inside this method.
/// Instead customize the IWebHostBuilder in the Init(IWebHostBuilder) overload.
/// </summary>
/// <param name="builder"></param>
protected override void Init(IHostBuilder builder)
{
}

But the Aspire needs WebApplicationBuilder which inherits from IHostApplicationBuilder so how can I call the methods like below AddServiceDefaults methods which is extension method of type IHostApplicationBuilder

public static IHostApplicationBuilder AddServiceDefaults(this IHostApplicationBuilder builder)
{
    builder.ConfigureOpenTelemetry();

    builder.AddDefaultHealthChecks();

    builder.Services.AddServiceDiscovery();

    builder.Services.ConfigureHttpClientDefaults(http =>
    {
        // Turn on resilience by default
        http.AddStandardResilienceHandler();

        // Turn on service discovery by default
        http.AddServiceDiscovery();
    });

    return builder;
}

  • I've passed along your question to some folks internally who are testing out Aspire.

Atif
asked 14 days ago184 views
1 Answer
0

@Atif,

I haven't used .NET Aspire in AWS Lambda, so I don't have a full answer to your question. I do have an alternative for you to consider.

If you are looking for observability capabilities such as logging, tracing and metrics, have you considered using Powertools for AWS Lambda (.NET)? The Powertools are written and optimized for running within AWS Lambda and can be easily added to a .NET 6 or .NET 8 project.

Key logging features

  • Capture key fields from Lambda context, cold start and structures logging output as JSON
  • Log Lambda event when instructed (disabled by default)
  • Log sampling enables DEBUG log level for a percentage of requests (disabled by default)
  • Append additional keys to structured log at any point in time

In addition to the observability features, Powertools also provides features to support Idempotency, Parameters, and Batch Processing.

AWS
answered 13 days ago
  • I saw the Powertools but it doesn't gives the visualization as Aspire does.

    Also we need to log into Console everytime to see the logs, etc..

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions