aws / aws-extensions-for-dotnet-cli

Extensions to the dotnet CLI to simplify the process of building and publishing .NET Core applications to AWS services
Apache License 2.0
369 stars 87 forks source link

dotnet lambda package-ci chokes on unquoted AWS::NoValue ref in !If block #209

Open hauntingEcho opened 2 years ago

hauntingEcho commented 2 years ago

Describe the bug

if you use !Ref AWS::NoValue as a possible result of an !If, then dotnet lambda package-ci will fail.

Expected Behavior

template provided in the reproduction steps works with dotnet lambda package-ci

Current Behavior

while aws cloudformation validate-template accepts the file, dotnet lambda package-ci fails with the error:

Unknown error executing command: (Line: 22, Col: 52, Idx: 493) - (Line: 22, Col: 55, Idx: 496): While scanning a plain scalar, find unexpected ':'.
   at YamlDotNet.Core.Scanner.ScanPlainScalar()
   at YamlDotNet.Core.Scanner.FetchPlainScalar()
   at YamlDotNet.Core.Scanner.FetchNextToken()
   at YamlDotNet.Core.Scanner.FetchMoreTokens()
   at YamlDotNet.Core.Scanner.MoveNextWithoutConsuming()
   at YamlDotNet.Core.Parser.GetCurrentToken()
   at YamlDotNet.Core.Parser.ParseFlowSequenceEntry(Boolean isFirst)
   at YamlDotNet.Core.Parser.StateMachine()
   at YamlDotNet.Core.Parser.MoveNext()
   at YamlDotNet.Core.ParserExtensions.Allow[T](IParser parser)
   at YamlDotNet.Core.ParserExtensions.Expect[T](IParser parser)
   at YamlDotNet.RepresentationModel.YamlScalarNode.Load(IParser parser, DocumentLoadingState state)
   at YamlDotNet.RepresentationModel.YamlScalarNode..ctor(IParser parser, DocumentLoadingState state)
   at YamlDotNet.RepresentationModel.YamlNode.ParseNode(IParser parser, DocumentLoadingState state)
   at YamlDotNet.RepresentationModel.YamlSequenceNode.Load(IParser parser, DocumentLoadingState state)
   at YamlDotNet.RepresentationModel.YamlSequenceNode..ctor(IParser parser, DocumentLoadingState state)
   at YamlDotNet.RepresentationModel.YamlNode.ParseNode(IParser parser, DocumentLoadingState state)
   at YamlDotNet.RepresentationModel.YamlMappingNode.Load(IParser parser, DocumentLoadingState state)
   at YamlDotNet.RepresentationModel.YamlMappingNode..ctor(IParser parser, DocumentLoadingState state)
   at YamlDotNet.RepresentationModel.YamlNode.ParseNode(IParser parser, DocumentLoadingState state)
   at YamlDotNet.RepresentationModel.YamlMappingNode.Load(IParser parser, DocumentLoadingState state)
   at YamlDotNet.RepresentationModel.YamlMappingNode..ctor(IParser parser, DocumentLoadingState state)
   at YamlDotNet.RepresentationModel.YamlNode.ParseNode(IParser parser, DocumentLoadingState state)
   at YamlDotNet.RepresentationModel.YamlMappingNode.Load(IParser parser, DocumentLoadingState state)
   at YamlDotNet.RepresentationModel.YamlMappingNode..ctor(IParser parser, DocumentLoadingState state)
   at YamlDotNet.RepresentationModel.YamlNode.ParseNode(IParser parser, DocumentLoadingState state)
   at YamlDotNet.RepresentationModel.YamlMappingNode.Load(IParser parser, DocumentLoadingState state)
   at YamlDotNet.RepresentationModel.YamlMappingNode..ctor(IParser parser, DocumentLoadingState state)
   at YamlDotNet.RepresentationModel.YamlNode.ParseNode(IParser parser, DocumentLoadingState state)
   at YamlDotNet.RepresentationModel.YamlDocument..ctor(IParser parser)
   at YamlDotNet.RepresentationModel.YamlStream.Load(IParser parser)
   at YamlDotNet.RepresentationModel.YamlStream.Load(TextReader input)
   at Amazon.Lambda.Tools.TemplateProcessor.TemplateProcessorManager.CreateTemplateParser(String templateBody) in C:\codebuild\tmp\output\src933647099\src\src\Amazon.Lambda.Tools\TemplateProcessor\TemplateProce
ssorManager.cs:line 380
   at Amazon.Lambda.Tools.TemplateProcessor.TemplateProcessorManager.TransformTemplateAsync(String templateDirectory, String templateBody, String[] args) in C:\codebuild\tmp\output\src933647099\src\src\Amazon.L
ambda.Tools\TemplateProcessor\TemplateProcessorManager.cs:line 80
   at Amazon.Lambda.Tools.Commands.PackageCICommand.PerformActionAsync() in C:\codebuild\tmp\output\src933647099\src\src\Amazon.Lambda.Tools\Commands\PackageCICommand.cs:line 131
   at Amazon.Common.DotNetCli.Tools.Commands.BaseCommand`1.ExecuteAsync() in C:\codebuild\tmp\output\src933647099\src\src\Amazon.Common.DotNetCli.Tools\Commands\BaseCommand.cs:line 46

Reproduction Steps

Using serverless.yaml:

AWSTemplateFormatVersion: 2010-09-09
Parameters:
  LambdaExecutionRoleArn:
    Type: String

Conditions:
  trueCondition: !Equals
    - a
    - a

Resources:
  GetAuthz:
    Type: AWS::Lambda::Function
    Properties:
      Timeout: 30
      Runtime: dotnet6
      MemorySize: 2048
      TracingConfig:
        Mode: Active
      Handler: APIGatewayAuthorizerHandler::APIGatewayAuthorizerHandler.Authorizer::Execute
      Description: !If [trueCondition, aaaaa, !Ref AWS::NoValue]
      Role: !Ref LambdaExecutionRoleArn

and 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.",
  ],
  "configuration": "Release",
  "framework": "net6.0",
  "output-template": "compiled.yml",
  "template": "serverless.yaml",
  "s3-prefix": "serverless/",
  "region": "us-east-1"
}

call dotnet lambda package-ci -sb ${bucket} (using a ${bucket} that you can write to)

Possible Solution

Temporary workaround: adding quotes around "AWS::NoValue" makes the utility accept it.

Additional Information/Context

No response

Targeted .NET platform

6

CLI extension version

5.1.4

Environment details (OS name and version, etc.)

Windows 10

hauntingEcho commented 2 years ago

Also applies to AWS::StackName

ashishdhingra commented 2 years ago

@hauntingEcho Although unsure, you might be affected by the issue https://github.com/aws/aws-extensions-for-dotnet-cli/issues/116. If yes, please close this a duplicate.

hauntingEcho commented 2 years ago

My understanding is that 116 only affects the --template-substitutions command-line parameter, which I am not using. This issue is when using CloudFormation's pseudo-parameters