diff --git a/.autover/changes/issue-2208-handler-configuration-docs.json b/.autover/changes/issue-2208-handler-configuration-docs.json new file mode 100644 index 000000000..2bbb78968 --- /dev/null +++ b/.autover/changes/issue-2208-handler-configuration-docs.json @@ -0,0 +1,11 @@ +{ + "Projects": [ + { + "Name": "Amazon.Lambda.AspNetCoreServer.Hosting", + "Type": "Patch", + "ChangelogMessages": [ + "Added Handler Configuration documentation explaining executable vs class library modes and Main(string[] args) pitfall" + ] + } + ] +} \ No newline at end of file diff --git a/Libraries/src/Amazon.Lambda.AspNetCoreServer.Hosting/README.md b/Libraries/src/Amazon.Lambda.AspNetCoreServer.Hosting/README.md index bf3455a65..4ed76da23 100644 --- a/Libraries/src/Amazon.Lambda.AspNetCoreServer.Hosting/README.md +++ b/Libraries/src/Amazon.Lambda.AspNetCoreServer.Hosting/README.md @@ -48,4 +48,38 @@ app.MapControllers(); app.Run(); -``` \ No newline at end of file +``` + +## Handler Configuration + +When deploying your Lambda function, the handler configuration depends on your project structure. + +### Executable Mode (Recommended) + +For executable mode, use `AssemblyName` as the handler (e.g., `MyLambdaProject`). This mode works with top-level statements or a `Main()` method without parameters. The Lambda runtime client handles event routing automatically. + +### Class Library Mode + +For class library mode, use `AssemblyName::ClassName::MethodName` as the handler. This mode works with traditional class-based handlers and uses reflection-based method invocation. + +### Common Configuration Issue + +When using `Main(string[] args)` with executable mode handler configuration, the Lambda runtime attempts to deserialize the incoming API Gateway event JSON into the `string[] args` parameter, which causes a `JsonSerializerException`. + +Incorrect usage: +```csharp +static void Main(string[] args) +{ + var builder = WebApplication.CreateBuilder(args); + // ... rest of setup +} +``` + +Correct usage for executable mode: +```csharp +static void Main() +{ + var builder = WebApplication.CreateBuilder(); + // ... rest of setup +} +```