aws-lambda-dotnet icon indicating copy to clipboard operation
aws-lambda-dotnet copied to clipboard

Escaping of string parameter different for `dotnet lambda-test-tool-6.0...` and `dotnet lambda invoke-function...`

Open bryanjhogan opened this issue 3 years ago • 0 comments

Description

Invoking a Lambda function that takes a string as a parameter from the lambda-test-tool requires different escaping than invoking the real Lambda from dotnet lambda invoke-function.

Reproduction Steps

Create a new Lambda from the template lambda.EmptyFunction. Deploy to AWS Lambda.

Command Prompt

Run dotnet lambda invoke-function EmptyFunction --payload ""hello"", or dotnet lambda invoke-function EmptyFunction --payload '"hello"' . These will work.

Try dotnet lambda-test-tool-6.0 --no-ui --payload ""hello"", or dotnet lambda-test-tool-6.0 --no-ui --payload '"hello"' These will fail - "System.Exception: Error deserializing the input JSON to type String"

PowerShell

Run dotnet lambda invoke-function EmptyFunction --payload ""hello"", or dotnet lambda invoke-function EmptyFunction --payload '"hello"' These will work.

Try dotnet lambda-test-tool-6.0 --no-ui --payload ""hello"", or dotnet lambda-test-tool-6.0 --no-ui --payload '"hello"' These will fail - "System.Exception: Error deserializing the input JSON to type String"

What actually works for lambda-test-tool-6.0

PowerShell - dotnet lambda-test-tool-6.0 --no-ui --payload '\"hello\"''

Command Prompt - dotnet lambda-test-tool-6.0 --no-ui --payload "\"hello\""

Logs

Captured Log information:

Request failed to execute
Error:
System.Exception: Error deserializing the input JSON to type String
   at Amazon.Lambda.TestTool.Runtime.LambdaExecutor.BuildParameters(ExecutionRequest request, ILambdaContext context) in C:\codebuild\tmp\output\src581676283\src\Tools\LambdaTestTool\src\Amazon.Lambda.TestTool\Runtime\LambdaExecutor.cs:line 215
   at Amazon.Lambda.TestTool.Runtime.LambdaExecutor.ExecuteAsync(ExecutionRequest request) in C:\codebuild\tmp\output\src581676283\src\Tools\LambdaTestTool\src\Amazon.Lambda.TestTool\Runtime\LambdaExecutor.cs:line 52
---------------- Inner 1 Exception ------------
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Span`1& arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at Amazon.Lambda.TestTool.Runtime.LambdaExecutor.BuildParameters(ExecutionRequest request, ILambdaContext context) in C:\codebuild\tmp\output\src581676283\src\Tools\LambdaTestTool\src\Amazon.Lambda.TestTool\Runtime\LambdaExecutor.cs:line 203
---------------- Inner 2 Exception ------------
Amazon.Lambda.Serialization.SystemTextJson.JsonSerializerException: Error converting the Lambda event JSON payload to type System.String: 'h' is an invalid start of a value. Path: $ | LineNumber: 0 | BytePositionInLine: 0.
   at Amazon.Lambda.Serialization.SystemTextJson.AbstractLambdaJsonSerializer.Deserialize[T](Stream requestStream)
---------------- Inner 3 Exception ------------
System.Text.Json.JsonException: 'h' is an invalid start of a value. Path: $ | LineNumber: 0 | BytePositionInLine: 0.
   at System.Text.Json.ThrowHelper.ReThrowWithPath(ReadStack& state, JsonReaderException ex)
   at System.Text.Json.Serialization.JsonConverter`1.ReadCore(Utf8JsonReader& reader, JsonSerializerOptions options, ReadStack& 
state)
   at System.Text.Json.JsonSerializer.ReadFromSpan[TValue](ReadOnlySpan`1 utf8Json, JsonTypeInfo jsonTypeInfo, Nullable`1 actualByteCount)
   at System.Text.Json.JsonSerializer.Deserialize[TValue](ReadOnlySpan`1 utf8Json, JsonSerializerOptions options)
   at Amazon.Lambda.Serialization.SystemTextJson.DefaultLambdaJsonSerializer.InternalDeserialize[T](Byte[] utf8Json)
   at Amazon.Lambda.Serialization.SystemTextJson.AbstractLambdaJsonSerializer.Deserialize[T](Stream requestStream)
---------------- Inner 4 Exception ------------
System.Text.Json.JsonReaderException: 'h' is an invalid start of a value. LineNumber: 0 | BytePositionInLine: 0.
   at System.Text.Json.ThrowHelper.ThrowJsonReaderException(Utf8JsonReader& json, ExceptionResource resource, Byte nextByte, ReadOnlySpan`1 bytes)
   at System.Text.Json.Utf8JsonReader.ConsumeValue(Byte marker)
   at System.Text.Json.Utf8JsonReader.ReadFirstToken(Byte first)
   at System.Text.Json.Utf8JsonReader.ReadSingleSegment()
   at System.Text.Json.Utf8JsonReader.Read()
   at System.Text.Json.Serialization.JsonConverter`1.ReadCore(Utf8JsonReader& reader, JsonSerializerOptions options, ReadStack& 
state)

Environment

  • Build Version: AWS .NET Core 6.0 Mock Lambda Test Tool (0.12.1)
  • OS Info: Windows 10
  • Build Environment: VSCode + Terminal dotnet
  • Targeted .NET Platform: .NET 6

This is a :bug: bug-report

bryanjhogan avatar Apr 05 '22 15:04 bryanjhogan