aws / aws-toolkit-visual-studio

AWS Toolkit for Visual Studio - a plugin to interact with AWS
https://aws.amazon.com/visualstudio/
Apache License 2.0
103 stars 29 forks source link

Publish AWS Serverless Application - Failed to create CloudFormation change set: Template Error #421

Open ibbyu opened 1 month ago

ibbyu commented 1 month ago

Describe the bug

... Waiting for change set to be reviewed
Error getting status of change set: Failed to create CloudFormation change set: Template format error: The Value field of every Outputs member must evaluate to a String and not a List

To Reproduce Steps to reproduce the behaviour example:

  1. Create new Serverless Application (Web Api)
  2. Add some parameters & mappings to serverless.template. Example:
    Parameters:
    Environment:
    Type: String
    AllowedValues:
    - dev
    - prod
    Description: The environment. Default is dev.
    Default: dev
    SubDomainName:
    Type: String
    Description: The subdomain for Api. Default is api.
    Default: api
    Mappings:
    DomainMap:
    dev:
      Name: dev.example.com
    prod:
      Name: example.com
  3. Update Output value to sub values found in DomainMap using FindInMap. (This gets highlighted as an error 0: Unresolved tag: !FindInMap). Example:
    Outputs:
    ApiURL:
    Description: Api URL
    Value:
      Fn::Sub:
          - "https://${SubDomainName}.${DomainName}"
          - DomainName: !FindInMap [DomainMap, !Ref Environment, Name]
  4. Right click project -> Publish to AWS Lambda -> Go through options & Publish
  5. Error:
    Error getting status of change set: Failed to create CloudFormation change set: Template format error: The Value field of every Outputs member must evaluate to a String and not a List

Expected behavior Should deploy successfully. This exact same template works when using sam build & sam deploy

Screenshots Error when using VS GUI: image

Successful deployment after using sam build & sam deploy image Toolkit Logs

Development System (please complete the following information):

Additional context This exact same template works when using sam build & sam deploy (Update the Handler to match your project)

Description: An AWS Serverless Application that uses the ASP.NET Core framework running
  in Amazon Lambda.
Parameters:
  Environment:
    Type: String
    AllowedValues:
    - dev
    - prod
    Description: The environment. Default is dev.
    Default: dev
  SubDomainName:
    Type: String
    Description: The subdomain for Api. Default is api.
    Default: api
Mappings:
  DomainMap:
    dev:
      Name: dev.example.com
    prod:
      Name: example.com
Conditions: {}
Resources:
  AspNetCoreFunction:
    Type: AWS::Serverless::Function
    Properties:
      Handler: test::test.LambdaEntryPoint::FunctionHandlerAsync
      Runtime: dotnet8
      CodeUri: ''
      MemorySize: 512
      Timeout: 30
      Role: null
      Policies:
      - AWSLambda_FullAccess
      Events:
        ProxyResource:
          Type: Api
          Properties:
            Path: "/{proxy+}"
            Method: ANY
        RootResource:
          Type: Api
          Properties:
            Path: "/"
            Method: ANY
Outputs:
  ApiURL:
    Description: Api URL
    Value:
      Fn::Sub:
        - "https://${SubDomainName}.${DomainName}"
        - DomainName: !FindInMap [DomainMap, !Ref Environment, Name]
rbbarad commented 1 month ago

@ibbyu Thanks for bringing this issue to our attention. I've reproduced this on my end - there seems to be an issue with the way we are parsing the yaml formatted template file. We are currently investigating a fix for this.

In the meantime as a workaround, try converting the serverless.template file from yaml to json. Using the example you provided, I've confirmed that a json serverless.template file deploys successfully.