Closed vladyslav-sosnov closed 5 months ago
@vladyslav-sosnov Good afternoon. I'm unsure if I understand your code, per my knowledge, HttpContext
by default is available only in the context of web applications. Although your code calls serviceCollection.AddHttpContextAccessor();
, this per HttpServiceCollectionExtensions.AddHttpContextAccessor, adds a default implementation for the IHttpContextAccessor service, which provides access to the current HttpContext, if one is available. The handler you are configuring is a simple Lambda function handler. Refer ASP.NET Core minimal APIs section at https://aws.amazon.com/blogs/compute/introducing-the-net-6-runtime-for-aws-lambda/ on how to use Amazon.Lambda.AspNetCoreServer.Hosting
package.
CCing @normj for any inputs.
Thanks, Ashish
This issue has not received a response in 5 days. If you want to keep this issue open, please just leave a comment below and auto-close will be canceled.
Hello, @ashishdhingra. Indeed, within this Lambda function handler, accessing HttpContext is not possible, which is the exact challenge I'm facing. I understand this might be by design, but I'm curious if there are any intentions to introduce HttpContext support. Alternatively, is there a method to inject it effectively so the context becomes available?
@vladyslav-sosnov There are no plans to add HttpContext
support into the basic Lambda programming model. That is an ASP.NET Core concept that brings with it a lot of dependencies and concepts that we would not introduce into the basic Lambda programming model. What is it you need from HttpContext
that isn't available in the APIGatewayHttpApiV2ProxyRequest
.
@normj Hello! We need to access the session from AWS Dynamo DB Distributed Cache. Alternatively, if we use the Minimal API approach as described in #1666, we are already able to retrieve the session from the HttpContext but Minimal API does not return the correct Custom Authorizer response (as it wraps the response in the body
property).
For this issue, the response is in the correct format (for a Custom Authorizer) but the session can not be retrieved.
Our preference, if possible, is to be able to use the Minimal API approach (#1666) if the response could be fixed to return the correct response for a Custom Authorizer.
Per @normj in https://github.com/aws/aws-lambda-dotnet/issues/1665#issuecomment-2026285737, there are no plans to add HttpContext
support into the basic Lambda programming model. Hence, closing this issue.
Comments on closed issues are hard for our team to see. If you need more assistance, please either tag a team member or open a new issue that references this one. If you wish to keep having a conversation with other community members under this issue feel free to do so.
Describe the bug
HttpContext is always null after it has been injected into AWS Lambda Function Handler. For comparison, it is populated while using the MinimalAPI approach.
Expected Behavior
HttpContext is populated with Items (and Session data when AWS DynamoDB session provider is used)
Current Behavior
HttpContext object is always null when injected in the AWS Lambda Function Handler.
Reproduction Steps
Code sample illustrating the absence of HttpContext.
Possible Solution
No response
Additional Information/Context
Alternatively, a Minimal API approach was trialed where HttpContext was populated with Items and Session data, however, it returned a response that is incorrect for a Custom Authorizer (Raised in a separate issue)
Context HttpContext is required to access session data.
For this purpose, AWS DynamoDB session provider has been integrated and API Gateway HTTP Payload v2.0 was used.
Apart from the use of Function Handler, the Lambda Entry Point approach was used. This approach faces the same issue as the Function Handler, where HttpContext is null. Amazon.Lambda.AspNetCoreServer
AWS .NET SDK and/or Package version used
Targeted .NET Platform
.Net 6
Operating System and version
AWS Lambda