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

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

Closed
bryanjhogan opened this issue Apr 5, 2022 · 2 comments
Assignees
Labels
bug This issue is a bug. module/lambda-test-tool p2 This is a standard priority issue queued

Comments

@bryanjhogan
Copy link
Contributor

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-report

@bryanjhogan bryanjhogan added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Apr 5, 2022
@ashishdhingra ashishdhingra added module/lambda-test-tool B and removed needs-triage This issue or PR still needs to be triaged. labels Apr 5, 2022
@ashishdhingra ashishdhingra added queued p2 This is a standard priority issue and removed B labels Nov 2, 2022
@ashishdhingra ashishdhingra self-assigned this Oct 18, 2024
@ashishdhingra
Copy link
Contributor

Fixed in AWS Lambda Test Tool version 0.15.3:

Copy link
Contributor

github-actions bot commented Nov 6, 2024

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

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-test-tool p2 This is a standard priority issue queued
Projects
None yet
Development

No branches or pull requests

2 participants