AWS SAM YAML template - Unknown Tag !Ref
YamlAmazon CloudformationServerlessAws ServerlessAws SamYaml Problem Overview
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
Yaml Solutions
Solution 1 - Yaml
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 - Yaml
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 - Yaml
Solution 4 - Yaml
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 5 - Yaml
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.
Solution 6 - Yaml
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"
]
}
}