Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS SAM YAML template - Unknown Tag !Ref

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
like image 488
EdsonF Avatar asked Nov 25 '18 18:11

EdsonF


4 Answers

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
like image 24
Roberto Carlos Reyes Fernandez Avatar answered Nov 09 '22 06:11

Roberto Carlos Reyes Fernandez


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"
]
like image 131
Jenya Y. Avatar answered Nov 09 '22 07:11

Jenya Y.


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

like image 11
Pat Myron Avatar answered Nov 09 '22 07:11

Pat Myron


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

like image 10
Dunedan Avatar answered Nov 09 '22 08:11

Dunedan