AWS SAM YAML template - Unknown Tag !Ref

20,865

Solution 1

You can add custom YAML tags in your settings.json:

"yaml.customTags": [
  "!Equals sequence",
  "!FindInMap sequence",
  "!GetAtt",
  "!GetAZs",
  "!ImportValue",
  "!Join sequence",
  "!Ref",
  "!Select sequence",
  "!Split sequence",
  "!Sub"
]

Solution 2

First validate your extensions, I eliminated the extension called Redhat yaml and problems solved, I have the next extensions and everything is ok.

  • vscode-cfn-lint
  • Serverless IDE
  • aws-cloudformation-yaml
  • AWS Toolkit for Visual Studio Code

Solution 3

This error message is almost certainly a false-positive from the YAML parser your IDE is using. To assess the correctness of the AWS SAM template, you should use cfn-python-lint instead, which comes with plugins for most major IDEs (unfortunately not for Visual Studio, but for Visual Studio Code).

Solution 4

The CloudFormation Visual Studio Code extension should manage these tags for you

Solution 5

In vscode, click file > save workspace as > click save

Then, open workspace.code-workspace and paste the following:

{   
    "folders": [
      {
        "path": ".."
      }   
    ],   
    "settings": {
      "yaml.customTags": [
        "!Equals sequence",
        "!FindInMap sequence",
        "!GetAtt",
        "!GetAZs",
        "!ImportValue",
        "!Join sequence",
        "!Ref",
        "!Select sequence",
        "!Split sequence",
        "!Sub"
      ]   
    } 
}
Share:
20,865
EdsonF
Author by

EdsonF

Updated on July 05, 2022

Comments

  • EdsonF
    EdsonF almost 2 years

    When I try to deploy my AWS SAM YAML file, it fails saying the !Ref is an unknown tag.

    enter image description here

    Any ideas to get around this?

    AWSTemplateFormatVersion: '2010-09-09'
    Transform: AWS::Serverless-2016-10-31
    
    Resources:
      MySimpleFunction:
        Type: AWS::Serverless::Function
        Properties:
          Handler: index.handler
          Runtime: nodejs4.3
          CodeUri: s3://<bucket>/MyCode.zip
          Events:
            MyUploadEvent:
              Type: S3
              Properties:
                Id: !Ref Bucket
                Events: Create
      Bucket:
        Type: AWS::S3::Bucket
    
  • Pedram Tadayoni
    Pedram Tadayoni almost 5 years
    Adding this helped me. In VSCode hit ctrl+, search for yaml custom tags and click on Edit in settings.json.
  • Sang Dang
    Sang Dang over 3 years
    FYI, if you are using neovim with coc-yaml, adding this will work like a charm! Just add it into coc-settings.json by running :CocConfig <3
  • kgadek
    kgadek over 3 years
    For neovim-lsp, this would be a part of typical init block in lua, like this: require'nvim_lsp'.yamlls.setup{settings={yaml={customTags={"‌​!Equals sequence", !FindInMap sequence", !GetAtt scalar", !GetAZs scalar", !ImportValue scalar", !Join sequence scalar", !Ref scalar", !Select sequence", !Split sequence", !Sub scalar", !And sequence", !Not sequence", !Equals sequence", !Sub sequence", !ImportValue scalar", !If sequence"}}}} EOF.
  • albertpeiro
    albertpeiro about 3 years
    This is what fixed it for me!! thank you!
  • Josh Dando
    Josh Dando about 3 years
    This solution didn't work until I disabled the kubernetes extension
  • sw_engineer
    sw_engineer almost 3 years
    removing Redhat yaml extension worked for me
  • mastazi
    mastazi almost 3 years
    I prefer this solution because it doesn't add unnecessary settings to the main settings.json, thank you.
  • asok Buzz
    asok Buzz over 2 years
    For me needed click gear icon on my extension on VSCode > Extension Setting and update Custom Tag
  • Steve Chambers
    Steve Chambers over 2 years
    I had this issue with GetAtt and needed to add "!GetAtt sequence" in addition to the settings that were automatically added by "update Custom Tag". (Also needed to add "!Cidr" and "!Cidr sequence").
  • Velmurugan
    Velmurugan about 2 years
    Cmd+Shift+P and select Open Settings UI (Ctrl+Shift+P for Windows I think)