AWS SAM YAML template - Unknown Tag !Ref

YamlAmazon CloudformationServerlessAws ServerlessAws Sam

Yaml Problem Overview


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

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"
      ]   
    } 
}

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionEdsonFView Question on Stackoverflow
Solution 1 - YamlJenya Y.View Answer on Stackoverflow
Solution 2 - YamlRoberto Carlos Reyes FernandezView Answer on Stackoverflow
Solution 3 - YamlPat MyronView Answer on Stackoverflow
Solution 4 - YamlDunedanView Answer on Stackoverflow
Solution 5 - Yamluser189198View Answer on Stackoverflow
Solution 6 - Yamlkayuapi_myView Answer on Stackoverflow