How to inject ILambdaContext in a Web API controller constructor

Viewed 24

I need to access AwsRequestId from ILambdaContext. I have a Web API project created in VS Code. I tried injecting ILambdaContext in a controller constructor, but it looks like the SAM template has not registered this dependency. What is the right way to access ILambdaContext?

System.InvalidOperationException: Unable to resolve service for type 'Amazon.Lambda.Core.ILambdaContext' while attempting to activate 'MyApp.Controllers.MyController'.

My code looks like this:

public MyController(ILogger<MyController> logger, IMyRepository myRepository, ILambdaContext context)
{
    _logger = logger;
    _myRepository = myRepository;
    _context = context;
}

I grabbed ILambdaContext from the Amazon.Lambda.Core namespace.

0 Answers
Related