Skip to content

Amazon.Lambda.Tools version 6.0.0 / 6.0.1 does not support comments in JSON configuration file #2230

@waf

Description

@waf

Describe the bug

Hi, the new versions of Amazon.Lambda.Tools v6.0.0 and v6.0.1 do not support comments in the aws-lambda-tools-defaults.json file, while previous v5.X versions did.

For example, given the following JSON (see the comment after function-memory-size):

{
  "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": "",
  "region": "ap-southeast-2",
  "configuration": "Release",
  "package-type": "image",
  "function-memory-size": 256, // some comment explaining reasoning
  "image-command": "Company.Lambdas::Company.Lambdas.LambdaEntryPoint::FunctionHandlerAsync",
  "docker-host-build-output-dir": "./bin/Release/lambda-publish"
}

Then running dotnet lambda package gives the error:

Amazon Lambda Tools for .NET Core applications (6.0.1)
Project Home: https://github.com/aws/aws-extensions-for-dotnet-cli, https://github.com/aws/aws-lambda-dotnet

Error parsing default config D:\Company.Lambdas\aws-lambda-tools-defaults.json: '/' is an invalid start of a property name. Expected a '"'. LineNumber: 11 | BytePositionInLine: 31.

I know that the JSON standard does not technically support comments, but it can be useful when the JSON is used for configuration files.

This did work in v5 and I think the change from LitJSON to System.Text.Json done in aws/aws-extensions-for-dotnet-cli#393 caused this issue. System.Text.Json does support comments but it must be enabled via JsonSerializerOptions.ReadCommentHandling.

Regression Issue

  • Select this option if this issue appears to be a regression.

Expected Behavior

The dotnet lambda package should complete without errors.

Current Behavior

See above, the tool immediately exits with the error Error parsing default config...

Reproduction Steps

See above, use the provided JSON and run dotnet lambda package

Possible Solution

See above, update the behavior introduced in aws/aws-extensions-for-dotnet-cli#393 to use JsonSerializerOptions.ReadCommentHandling.

Additional Information/Context

No response

AWS .NET SDK and/or Package version used

Amazon.Lambda.Tools v6.0.0 / v6.0.1

Targeted .NET Platform

.NET 8

Operating System and version

Windows 11

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugThis issue is a bug.module/lambda-client-libp1This is a high priority issuepending-releaseThis issue will be fixed by an approved PR that hasn't been released yet.potential-regressionMarking this issue as a potential regression to be checked by team member

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions