You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Visual Studio Code中CloudFormation模板自定义标签YAML验证失败

解决CloudFormation自定义标签在VSCode中反复报"Incorrect Type: Expected String"的问题

可行修复方案

  • 调整扩展加载顺序
    在VSCode的settings.json里添加以下配置,让CloudFormation扩展优先于RedHat YAML扩展加载,避免YAML扩展先解析时无法识别自定义标签:

    "extensions.priority": [
      "aws-scripting-guy.cform",
      "redhat.vscode-yaml"
    ]
    

    注意替换为你实际安装的CloudFormation扩展ID(可在扩展详情页查看)。

  • 仅保留CFN-Lint作为验证器
    禁用RedHat YAML扩展的CloudFormation schema校验,只使用CFN-Lint进行验证,避免规则冲突:

    "yaml.schemas": {
      "cloudformation": "*.yml"
    },
      "yaml.validate": false,
      "cfnLint.enable": true
    
  • 清理扩展缓存
    关闭VSCode,删除对应路径下的缓存文件:

    • Windows:%APPDATA%\Code\Cache 和 %APPDATA%\Code\CachedData
    • macOS:~/Library/Caches/Code 和 ~/Library/Application Support/Code/CachedData
    • Linux:~/.config/Code/Cache 和 ~/.config/Code/CachedData
      重启VSCode后重新加载扩展,解决缓存导致的配置不生效问题。
  • 检查自定义标签配置格式
    确认settings.json中的自定义标签配置无语法错误,示例如下:

    "cloudformation.customTags": [
      {
        "name": "Fn::Transform",
        "type": "object"
      },
      {
        "name": "MyCustom::Tag",
        "type": "object"
      }
    ]
    

    确保自定义标签的type设置为object(而非string)。

  • 降级RedHat YAML扩展版本
    部分用户反馈最新版RedHat YAML扩展与CloudFormation扩展存在兼容性问题,可尝试降级到v1.14.0或更早版本,暂时规避冲突。

其他用户反馈情况

不少用户在VSCode扩展社区和技术论坛提到过该问题,核心原因是RedHat YAML扩展的实时重新校验机制,与CloudFormation自定义标签的规则识别存在冲突——当编辑器触发实时校验时,YAML扩展会优先使用默认schema,而非CloudFormation扩展提供的自定义标签规则。

内容的提问来源于stack exchange,提问作者Allen Fisher

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.19 05:25:18