82

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
Dunedan
  • 7,848
  • 6
  • 42
  • 52
EdsonF
  • 2,719
  • 3
  • 30
  • 34

7 Answers7

191

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"
]
Lane
  • 6,532
  • 5
  • 28
  • 27
Jenya Y.
  • 2,980
  • 1
  • 16
  • 21
  • 21
    Adding this helped me. In VSCode hit ctrl+, search for _yaml custom tags_ and click on _Edit in settings.json_. – Pedram Tadayoni Jul 11 '19 at 04:26
  • 2
    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 – Sang Dang Oct 11 '20 at 09:24
  • For [neovim-lsp](https://github.com/neovim/nvim-lspconfig#yamlls), 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```. – kgadek Oct 15 '20 at 02:05
  • This solution didn't work until I disabled the kubernetes extension – Josh Dando Apr 14 '21 at 13:36
  • For me needed click gear icon on my extension on VSCode > Extension Setting and update Custom Tag – asok Buzz Sep 25 '21 at 22:59
  • 3
    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"`). – Steve Chambers Nov 15 '21 at 12:17
  • 1
    Cmd+Shift+P and select Open Settings UI (Ctrl+Shift+P for Windows I think) – Velmurugan Apr 02 '22 at 12:03
33

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
11

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

Pat Myron
  • 4,437
  • 2
  • 20
  • 39
10

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).

Dunedan
  • 7,848
  • 6
  • 42
  • 52
5

The Ansible extension for Visual Studio Code was causing this error message for me. I removed it, and that solved the problem for my situation.

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"
      ]   
    } 
}
kayuapi_my
  • 498
  • 1
  • 6
  • 9
  • 1
    I prefer this solution because it doesn't add unnecessary settings to the main `settings.json`, thank you. – mastazi Jul 07 '21 at 11:46
3

On Visual Studio Code, click File ---> Perferences -----> Settings On the search bar, type Yaml tags, then it will show out Yaml:Custom Tags Click Edit in Settings.json

On Settings.josn file:

"yaml.customTags": [
        "!Cidr",
        "!Cidr sequence",
        "!And",
        "!And sequence",
        "!If",
        "!If sequence",
        "!Not",
        "!Not sequence",
        "!Equals",
        "!Equals sequence",
        "!Or",
        "!Or sequence",
        "!FindInMap",
        "!FindInMap sequence",
        "!Base64",
        "!Join",
        "!Join sequence",
        "!Ref",
        "!Sub",
        "!Sub sequence",
        "!GetAtt",
        "!GetAZs",
        "!ImportValue",
        "!ImportValue sequence",
        "!Select",
        "!Select sequence",
        "!Split",
        "!Split sequence"
    ],

Note: if you have issues with "!Cidr", make sure you include the "!Cidr sequence" as well, the unresolved Tag problem will be fixed

I hope it is helpful for you!

Yvette Lau
  • 191
  • 1
  • 7