-
Notifications
You must be signed in to change notification settings - Fork 479
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Combination of ASP.NET (Minimal API) and [LambdaFunction] annotations in the same csproj #1782
Comments
If I understand what you are asking I got a solution by setting a {
"AWSTemplateFormatVersion": "2010-09-09",
"Transform": "AWS::Serverless-2016-10-31",
"Description": "An AWS Serverless Application that uses the ASP.NET Core framework running in Amazon Lambda.",
"Parameters": {},
"Conditions": {},
"Resources": {
"RootFunction": {
"Type": "AWS::Serverless::Function",
"Properties": {
"Handler": "AspNetCoreLambdaDifferentEventSources",
"Runtime": "dotnet8",
"CodeUri": "",
"MemorySize": 512,
"Timeout": 30,
"Role": null,
"Policies": [
"AWSLambda_FullAccess"
],
"Environment" : {
"Variables" : {
"LambdaEventSource" : "RestApi"
}
},
"Events": {
"RootResource": {
"Type": "Api",
"Properties": {
"Path": "/",
"Method": "ANY"
}
}
}
}
},
"CalculatorFunction": {
"Type": "AWS::Serverless::Function",
"Properties": {
"Handler": "AspNetCoreLambdaDifferentEventSources",
"Runtime": "dotnet8",
"CodeUri": "",
"MemorySize": 512,
"Timeout": 30,
"Role": null,
"Policies": [
"AWSLambda_FullAccess"
],
"Environment" : {
"Variables" : {
"LambdaEventSource" : "HttpApi"
}
},
"Events": {
"ProxyResource": {
"Type": "HttpApi",
"Properties": {
"Path": "/calculator/{proxy+}",
"Method": "ANY"
}
}
}
}
}
},
"Outputs": {
"RootURL": {
"Description": "API endpoint URL for Prod environment",
"Value": {
"Fn::Sub": "https://${ServerlessRestApi}.execute-api.${AWS::Region}.amazonaws.com/Prod/"
}
},
"CalculatorURL": {
"Description": "API endpoint URL for Prod environment",
"Value": {
"Fn::Sub": "https://${ServerlessHttpApi}.execute-api.${AWS::Region}.amazonaws.com/calculator/"
}
}
}
} Then in the code that calls var eventSource = Environment.GetEnvironmentVariable("LambdaEventSource");
switch(eventSource)
{
case "RestApi":
builder.Services.AddAWSLambdaHosting(LambdaEventSource.RestApi);
break;
case "HttpApi":
builder.Services.AddAWSLambdaHosting(LambdaEventSource.HttpApi);
break;
} |
I'm going to close this assuming my response gave you enough info move forward. Feel free to reopen or create a new issue if this didn't answer your question. |
Comments on closed issues are hard for our team to see. |
@normj thank you for your suggestion. We also found that it’s possible in the same Csproj to contain both asp.net minimal api Program.cs and Annotations Functions.cs. They are declared as separate lambdas in serverless.template (with comment “This template is partially managed by Amazon.Lambda.Annotations”). It will be good to mention one or both of these solutions in the ASP.NET documentation, because even AWS support engineers advised us, that it’s not possible to mix LambdaEventSources in ASP.NET minimal API csproj. |
Describe the feature
We have a lambda created as ASP.NET minimal API that calls
services.AddAWSLambdaHosting(LambdaEventSource.ApplicationLoadBalancer); and has existing external clients that are using ApplicationLoadBalancer.
The current limitation is that such project expects only ApplicationLoadBalancer request format.
We want to have multiple lambda functions in the same csproj to support calls from different event sources. This functionality is supported by annotations, (see https://chatgpt.com/share/b51a30a1-0f69-459c-ba2b-5448165e86b5 ), but not in AWS ASP.NET lambda Program.cs project, that required to specify only one of 3 options in services.AddAWSLambdaHosting(LambdaEventSource) call.
Do we have to rewrite ASP.NET minimal API project to LambdaFunction annotations due to this restriction?
Or it's possible to have both Asp.Net Program.cs file with services.AddAWSLambdaHosting and Functions.cs with [LambdaFunction] in the same .csproj file?
If it's not possible, please consider to support multiple LambdaEventSource in the same ASP.Net csproj
Use Case
Ability to add lambdas called from amazon connect to the existing project written as ASP.Net Minimal API with calls from ApplicationLoadBalancer
Proposed Solution
have both Asp.Net Program.cs file with services.AddAWSLambdaHosting and Functions.cs with [LambdaFunction] in the same .csproj file?
Other Information
No response
Acknowledgements
AWS .NET SDK and/or Package version used
3.7.302.15
Targeted .NET Platform
.Net 8
Operating System and version
deployed lambdas to AWS, on Dev Windows 11
The text was updated successfully, but these errors were encountered: