Skip to content
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

Documented handler max length of 128 characters isn't supported #1642

Open
SeijiSuenaga opened this issue Dec 13, 2023 · 5 comments
Open

Documented handler max length of 128 characters isn't supported #1642

SeijiSuenaga opened this issue Dec 13, 2023 · 5 comments
Labels
bug This issue is a bug. module/lambda-client-lib p2 This is a standard priority issue queued service-api This issue is due to a problem in a service API, not the SDK implementation.

Comments

@SeijiSuenaga
Copy link

SeijiSuenaga commented Dec 13, 2023

Describe the bug

AWS documentation says the Handler property has a max length 128 characters, but values exactly 128 characters long appear to be truncated to 127 characters in the dotnet6 Lambda runtime, and therefore fail.

Expected Behavior

A handler value exactly 128 characters long shouldn't be truncated and should invoke the handler method successfully.

Current Behavior

A handler value exactly 128 characters long, such as:

XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX::XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.LambdaFunction::HandleAsync

produces a failure:

Amazon.Lambda.RuntimeSupport.ExceptionHandling.LambdaValidationException: Unable to find method 'HandleAsyn' in type 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.LambdaFunction' from assembly 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX': Found no methods matching method name 'HandleAsyn'.
   at Amazon.Lambda.RuntimeSupport.Bootstrap.UserCodeLoader.FindCustomerMethod(Type type) in /src/Repo/Libraries/src/Amazon.Lambda.RuntimeSupport/Bootstrap/UserCodeLoader.cs:line 242
   at Amazon.Lambda.RuntimeSupport.Bootstrap.UserCodeLoader.Init(Action`1 customerLoggingAction) in /src/Repo/Libraries/src/Amazon.Lambda.RuntimeSupport/Bootstrap/UserCodeLoader.cs:line 116
   at Amazon.Lambda.RuntimeSupport.Bootstrap.UserCodeInitializer.InitializeAsync() in /src/Repo/Libraries/src/Amazon.Lambda.RuntimeSupport/Bootstrap/UserCodeInitializer.cs:line 46
   at Amazon.Lambda.RuntimeSupport.LambdaBootstrap.InitializeAsync() in /src/Repo/Libraries/src/Amazon.Lambda.RuntimeSupport/Bootstrap/LambdaBootstrap.cs:line 155

Reproduction Steps

  1. Create a Lambda with a handler specification that is exactly 128 characters long.
  2. Try to invoke the function.

Possible Solution

No response

Additional Information/Context

AWS Console shows the full value in the "Runtime settings" of the Lambda function, so it seems to be getting truncated somewhere in the Lambda runtime.

AWS .NET SDK and/or Package version used

N/A — this bug is independent from .NET SDK.

Targeted .NET Platform

.NET 6

Operating System and version

Amazon Linux 2

@SeijiSuenaga SeijiSuenaga added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Dec 13, 2023
@ashishdhingra ashishdhingra added needs-reproduction This issue needs reproduction. module/lambda-client-lib and removed needs-triage This issue or PR still needs to be triaged. labels Dec 13, 2023
@ashishdhingra
Copy link
Contributor

ashishdhingra commented Dec 13, 2023

@SeijiSuenaga Good morning. Thanks for opening the issue. Kindly refer Lambda function handler in C#; if you scroll down a little, there is an example for format of function handler GetProductHandler::GetProductHandler.Function::FunctionHandler. This is in the format ASSEMBLY::TYPE::METHOD. So in aws-lambda-tools.defaults.json, the value for function-handler for your use case would have been An.Example.Namespace.For.The.GitHub.Issue::An.Example.Namespace.For.The.GitHub.Issue.ExampleLambdaFunction::HandleInvocationAsync (not An.Example.Namespace.For.The.GitHub.Issue::An.Example.Namespace.For.The.GitHub.Issue.ExampleLambdaFunction.HandleInvocationAsync, this is a wrong specification). This handler name is 129 characters long, and hence, the last letter is truncated by runtime (not in Lambda function settings) due to limit of 128 characters.

If you deploy this function via Visual Studio (using latest AWS Toolkit), it will throw validation error during deployment.

Could you check the function handler name (in above format) in your Lambda function settings?

Thanks,
Ashish

@ashishdhingra ashishdhingra added response-requested Waiting on additional info and feedback. Will move to close soon in 7 days. and removed needs-reproduction This issue needs reproduction. labels Dec 13, 2023
@SeijiSuenaga
Copy link
Author

@ashishdhingra Ah I'm sorry, I got that example wrong 😓 but my actual Lambda function settings have the correct format you specified. Here's the actual format I'm using, with my company's namespace hidden:

XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX::XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.LambdaFunction::HandleAsync

And the resulting error:

Amazon.Lambda.RuntimeSupport.ExceptionHandling.LambdaValidationException: Unable to find method 'HandleAsyn' in type 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.LambdaFunction' from assembly 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX': Found no methods matching method name 'HandleAsyn'.

I'll edit the OP to correct the example.

@github-actions github-actions bot removed the response-requested Waiting on additional info and feedback. Will move to close soon in 7 days. label Dec 14, 2023
@ashishdhingra
Copy link
Contributor

Appears to be reproducible using below code:

using Amazon.Lambda.Core;

// Assembly attribute to enable the Lambda function's JSON input to be converted into a .NET class.
[assembly: LambdaSerializer(typeof(Amazon.Lambda.Serialization.SystemTextJson.DefaultLambdaJsonSerializer))]

namespace XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX;

public class LambdaFunction
{
    public async Task<string> HandleAsync(string input, ILambdaContext context)
    {
        return await Task.Run<string>(() => { return input.ToUpper(); });
    }
}

aws-lambda-tools-defaults.json

{
    "Information" : [
        "This file provides default values for the deployment wizard inside Visual Studio and the AWS Lambda commands added to the .NET Core CLI.",
        "To learn more about the Lambda commands with the .NET Core CLI execute the following command at the command line in the project root directory.",
        "dotnet lambda help",
        "All the command line options for the Lambda command can be specified in this file."
    ],
    "profile"     : "default",
    "region"      : "us-east-2",
    "configuration" : "Release",
    "function-architecture" : "x86_64",
    "function-runtime"      : "dotnet6",
    "function-memory-size"  : 256,
    "function-timeout"      : 30,
    "function-handler"      : "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX::XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.LambdaFunction::HandleAsync",
    "framework"             : "net6.0",
    "function-name"         : "TestFunction",
    "package-type"          : "Zip",
    "function-role"         : "arn:aws:iam::139480602983:role/lambda_exec_TestFunction",
    "function-subnets"      : "",
    "function-security-groups" : "",
    "tracing-mode"             : "PassThrough",
    "environment-variables"    : "",
    "image-tag"                : ""
}

The handler name is XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX::XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.LambdaFunction::HandleAsync is 128 characters long. The Lambda function configuration is also correct. However, when executing Lambda code via AWS console, following exception is logged:

{
  "errorType": "LambdaValidationException",
  "errorMessage": "Unable to find method 'HandleAsyn' in type 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.LambdaFunction' from assembly 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX': Found no methods matching method name 'HandleAsyn'.",
  "stackTrace": [
    "at Amazon.Lambda.RuntimeSupport.Bootstrap.UserCodeLoader.FindCustomerMethod(Type type) in /src/Repo/Libraries/src/Amazon.Lambda.RuntimeSupport/Bootstrap/UserCodeLoader.cs:line 242",
    "at Amazon.Lambda.RuntimeSupport.Bootstrap.UserCodeLoader.Init(Action`1 customerLoggingAction) in /src/Repo/Libraries/src/Amazon.Lambda.RuntimeSupport/Bootstrap/UserCodeLoader.cs:line 116",
    "at Amazon.Lambda.RuntimeSupport.Bootstrap.UserCodeInitializer.InitializeAsync() in /src/Repo/Libraries/src/Amazon.Lambda.RuntimeSupport/Bootstrap/UserCodeInitializer.cs:line 46",
    "at Amazon.Lambda.RuntimeSupport.LambdaBootstrap.InitializeAsync() in /src/Repo/Libraries/src/Amazon.Lambda.RuntimeSupport/Bootstrap/LambdaBootstrap.cs:line 159"
  ]
}

Might be some issue in Amazon.Lambda.RuntimeSupport package.

Needs review with the team.

Thanks,
Ashish

@ashishdhingra ashishdhingra added needs-review p2 This is a standard priority issue labels Dec 14, 2023
@ashishdhingra
Copy link
Contributor

Discussed with the team. Somehow the runtime is not passing correct handler string (refer here). We need to contact service team for the root cause.

@ashishdhingra ashishdhingra added service-api This issue is due to a problem in a service API, not the SDK implementation. and removed needs-review p2 This is a standard priority issue labels Dec 15, 2023
@ashishdhingra
Copy link
Contributor

P109288213

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug. module/lambda-client-lib p2 This is a standard priority issue queued service-api This issue is due to a problem in a service API, not the SDK implementation.
Projects
None yet
Development

No branches or pull requests

2 participants