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
已提问 2 个月前284 查看次数
1 回答
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
已回答 2 个月前
  • 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..

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则