Is there a way to use the Amazon.Lambda.AspNetCoreServer.APIGatewayProxyFunction
with a custom dotnet runtime as allowed by Amazon.Lambda.RuntimeSupport
?
I have a test app up and running on lambda with dot net core 2.2, however can't figure out how to get the proxy integration working for asp.net 2.2.
When the handler is invoked it runs the Main
method which is obviously not the way to run an asp.net core api on AWS Lambda using proxy integration.
How do I set up a custom runtime to use a handler, instead of mounting the Main
method directly?
I've uploaded my test repo:
https://github.com/darbio/apitest
Result from visiting the API Gateway URL https://redacted.execute-api.us-east-1.amazonaws.com/dev/api/values
:
{
message: "Internal server error"
}
Logs from lambda:
END RequestId: 167f8caf-389d-4f8f-8202-6c77004a5c6c
REPORT RequestId: 167f8caf-389d-4f8f-8202-6c77004a5c6c Duration: 6002.92 ms Billed Duration: 6000 ms Memory Size: 1024 MB Max Memory Used: 99 MB
2019-03-28T22:50:19.159Z 167f8caf-389d-4f8f-8202-6c77004a5c6c Task timed out after 6.00 seconds
warn: Microsoft.AspNetCore.DataProtection.Repositories.EphemeralXmlRepository[50]
Using an in-memory repository. Keys will not be persisted to storage.
warn: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[59]
Neither user profile nor HKLM registry available. Using an ephemeral key repository. Protected data will be unavailable when application exits.
warn: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[35]
No XML encryptor configured. Key {a793bc64-722b-4524-9ceb-3a1c6b8a06fe} may be persisted to storage in unencrypted form.
warn: Microsoft.AspNetCore.Server.Kestrel[0]
Unable to bind to http://localhost:5000 on the IPv6 loopback interface: 'Address family not supported by protocol'.
Hosting environment: Production
Content root path: /var/task
Now listening on: http://localhost:5000
Application started. Press Ctrl+C to shut down.
The logs make a lot of sense - we can't run asp as if it was on a traditional server.
How do we run asp with a custom runtime? Lambda is running the program, however I can't specify the function handler to use as you would usually (functionhandlerasync).
Any help really appreciated.
I believe you need to update Program.cs
to be similar to the one from here https://aws.amazon.com/blogs/developer/announcing-amazon-lambda-runtimesupport/
I put up this sample of how to get an ASP.NET Core 2.2 project working. Let me know if this helps
https://github.com/normj/LambdaNETCoreSamples/tree/master/CustomRuntimeAspNetCore
That's a great help. I'll have a look on Monday but I can see how to get it working from the source. Thanks!
Thanks for that @normj 馃憤
@normj - this all helps, given the recent updates on this repo, is there any way to update the 2.2 sample above ?
@acds, can you please specify what you think needs to be updated on the sample?
Most helpful comment
I put up this sample of how to get an ASP.NET Core 2.2 project working. Let me know if this helps
https://github.com/normj/LambdaNETCoreSamples/tree/master/CustomRuntimeAspNetCore