AWS SAM YAML template - Unknown Tag !Ref
Asked Answered
S

7

87

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
Spatter answered 25/11, 2018 at 18:1 Comment(6)
I think the ! notation is still not supported. Try just REFConjure
Using !Ref in a YAML AWS SAM is definitely posssible.Whensoever
@EdsonF: What's generating the error message? What's the IDE you're using?Whensoever
@Whensoever Visual Studio 2017. And I've also tried Visual Studio Code, to no availeSpatter
Does it fail when you run sls deploy?Vergeboard
Exclamation mark ! in YAML has a specific meaning (it is intended only for use locally (internal to an application). Use in communicating with other applications is not recommended.Radack
J
201

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"
]
Judges answered 23/5, 2019 at 9:8 Comment(8)
Adding this helped me. In VSCode hit ctrl+, search for yaml custom tags and click on Edit in settings.json.Interrex
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 <3Stimulant
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.Meritorious
This solution didn't work until I disabled the kubernetes extensionSeedling
For me needed click gear icon on my extension on VSCode > Extension Setting and update Custom TagAssumpsit
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").Leafstalk
Cmd+Shift+P and select Open Settings UI (Ctrl+Shift+P for Windows I think)Unsuccessful
Related: github.com/redhat-developer/vscode-yaml/issues/669Extramundane
J
40

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
Jaconet answered 9/8, 2019 at 1:2 Comment(2)
removing Redhat yaml extension worked for meFreidafreight
Installing AWS Toolkit VSC extension removed all errors coming from Redhat YAML extension.Sara
W
11

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

Whensoever answered 25/11, 2018 at 18:19 Comment(0)
M
11

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

Molliemollify answered 9/9, 2020 at 23:39 Comment(0)
M
7

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.json 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!

Maravedi answered 13/6, 2022 at 19:6 Comment(0)
D
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.

Dedra answered 19/1, 2020 at 21:46 Comment(0)
Y
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"
      ]   
    } 
}
Yclept answered 21/5, 2021 at 6:55 Comment(1)
I prefer this solution because it doesn't add unnecessary settings to the main settings.json, thank you.Avlona

© 2022 - 2024 — McMap. All rights reserved.