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

SSM文档创建报错:YAML格式不规范,如何排查修复?

解决AWS SSM文档YAML格式错误问题

问题分析

你遇到的invalidDocumentContent: YAML not well-formed错误,核心原因是新增的PowerShell代码在JSON格式的SSM文档中存在特殊字符未正确转义的问题,导致文档解析时触发格式错误(即便你用JSON创建文档,SSM内部可能会做格式转换,或是你误选了YAML格式创建)。

修复步骤

针对你提供的代码,需修正以下关键问题:

  1. 转义PowerShell路径中的反斜杠
    在JSON字符串里,单个反斜杠\是转义符,必须写成双反斜杠\\才能被正确识别。比如:
    原代码行:
"$output = [string]::Format('C:\pgadmin4-{0}-x64.exe',$version)"

修正为:

"$output = [string]::Format('C:\\pgadmin4-{0}-x64.exe',$version)"
  1. 确保字符串引号闭合无误
    检查新增的所有PowerShell代码行,确认单引号、双引号都正确闭合,没有遗漏或错位情况。

  2. 修正后的完整文档代码
    替换问题代码块后,完整的SSM文档代码如下:

{
  "schemaVersion": "2.2",
  "description": "X",
  "parameters": {},
  "mainSteps": [
    {
      "action": "aws:runPowerShellScript",
      "name": "dbaCustomizations",
      "precondition": {
        "StringEquals": [
          "platformType",
          "Windows"
        ]
      },
      "inputs": {
        "runCommand": [
          "$errorActionPreference = 'stop'",
          "try {",
          "$AllProtocols = [System.Net.SecurityProtocolType]'Ssl3,Tls,Tls11,Tls12'",
          "[System.Net.ServicePointManager]::SecurityProtocol = $AllProtocols",
          "Set-ItemProperty -Path 'HKLM:\\SOFTWARE\\Wow6432Node\\Microsoft\\.NetFramework\\v4.0.30319' -Name 'SchUseStrongCrypto' -Value '1' -Type DWord",
          "Set-ItemProperty -Path 'HKLM:\\SOFTWARE\\Microsoft\\.NetFramework\\v4.0.30319' -Name 'SchUseStrongCrypto' -Value '1' -Type DWord",
          "",
          "# PG admin separately for the ALLUSERS flag for now. ",
          "$version = '6.18'",
          "$output = [string]::Format('C:\\pgadmin4-{0}-x64.exe',$version)",
          "$url = [string]::Format('https://ftp.postgresql.org/pub/pgadmin/pgadmin4/v{0}/windows/pgadmin4-{0}-x64.exe',$version)",
          "(New-Object Net.WebClient).DownloadFile($url, $output)",
          "Start-Process -Wait -FilePath $output -ArgumentList '/ALLUSERS /VERYSILENT /SUPPRESSMSGBOXES /NORESTART /SP-' -PassThru",
          "}",
          "} catch",
          "{",
          "    Write-Output \"Error encountered \" + $Error[0].Exception.Message",
          "    exit 1",
          "}",
          ""
        ],
        "timeoutSeconds": 7200
      }
    }
  ]
}
  1. 验证文档格式
    可以用本地工具(比如VS Code内置的JSON校验功能)检查修正后的代码,确认无语法错误后再上传至SSM。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.05 10:16:23