AWS SAM YAML template - Unknown Tag !Ref
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"
]
}
}
EdsonF
Updated on July 05, 2022Comments
-
EdsonF almost 2 years
When I try to deploy my AWS SAM YAML file, it fails saying the !Ref is an unknown tag.
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 almost 5 yearsAdding this helped me. In VSCode hit ctrl+, search for yaml custom tags and click on Edit in settings.json.
-
Sang Dang over 3 yearsFYI, if you are using neovim with
coc-yaml
, adding this will work like a charm! Just add it intococ-settings.json
by running:CocConfig
<3 -
kgadek over 3 yearsFor 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 about 3 yearsThis is what fixed it for me!! thank you!
-
Josh Dando about 3 yearsThis solution didn't work until I disabled the kubernetes extension
-
sw_engineer almost 3 yearsremoving Redhat yaml extension worked for me
-
mastazi almost 3 yearsI prefer this solution because it doesn't add unnecessary settings to the main
settings.json
, thank you. -
asok Buzz over 2 yearsFor me needed click gear icon on my extension on VSCode > Extension Setting and update Custom Tag
-
Steve Chambers over 2 yearsI 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 about 2 yearsCmd+Shift+P and select Open Settings UI (Ctrl+Shift+P for Windows I think)