【问题标题】:Is there a way to pass output from one step of AWS ssm document to another?有没有办法将输出从 AWS ssm 文档的一个步骤传递到另一个?
【发布时间】:2021-08-07 03:08:21
【问题描述】:

我有一个 SSM 文档,用于运行 PowerShell 脚本,然后调用另一个 SSM 文档。我想将第一个 SSM 文档的输出传递到第二个文档。

{
  "schemaVersion": "2.2",
  "description": "This is to test copying a file from place a to b",
  "parameters": {
    "InputDir": {
      "type": "String",
      "description": "This is the input directory from where we are copying",
      "default": "C:\\himanshu\\AWS_SSM_WORK"
    },
    "OutputDir": {
      "type": "String",
      "description": "This is the output directory  where to we are copying",
      "default": ""
    }
  },
  "mainSteps": [
    {
      "action": "aws:runPowerShellScript",
      "name": "testCopyFunction",
      "inputs": {
        "timeoutSeconds": "60",
        "runCommand": [
          "write-Output {{InputDir }}",
          " $utility_path = '{{InputDir}}'",
          "$var = @{",
          " “name” = “himanshu” ",
          " “surname” = “rai” ",
          "}",
          " if (Test-Path $utility_path) ",
          "   { Set-Location $utility_path ",
          " Start-Process \"cmd.exe\" \" /k C:\\himanshu\\AWS_SSM_WORK\\start.bat \" ",
          " $var.Add(\"state\",\"up\") ",
          "}",
          " else ",
          "   { Write-Error \"Base location of build is incorrectly set.\" ",
          "     exit 1",
          "   }",
          "$var | ConvertTo-Json  | Out-File \".\\name.json\" "
        ]
      }
    },
    {
      "action": "aws:runDocument",
      "name": "egsl_him_second",
      "inputs": {
        "documentType": "SSMDocument",
        "documentPath": "egsl_him_second",
        "documentParameters": {
          "InputDir": "C:\\himanshu\\AWS_SSM_WORK"
        },
        "finallyStep": true
      }
    }
  ]
}

在第二步中,我正在使用 aws:runDocument 调用另一个 SSM 文档。有什么办法,我可以在第二步中使用我在step1中创建的$var

【问题讨论】:

    标签: amazon-web-services aws-ssm


    【解决方案1】:

    您可以在第一步中添加输出

        {
          "action": "aws:runPowerShellScript",
          "name": "testCopyFunction",
          "inputs": {
            "timeoutSeconds": "60",
            "runCommand": [
               ...
            ],
          },
          "outputs": [
              {
                "Name": "var",
                "Selector": "PATH_TO_JSON_ATTRIBUTE",
                "Type": "String"
              }
            ]
          }
        }
    

    假设您从第一步获得 json 输出,您可以将 PATH_TO_JSON_ATTRIBUTE 替换为选择器以将 json 属性值分配给 var 并在您的输入中使用相同的值第二步

          {
          "action": "aws:runDocument",
          "name": "egsl_him_second",
          "inputs": {
            "documentType": "SSMDocument",
            "documentPath": "egsl_him_second",
            "documentParameters": {
              "InputDir": "C:\\himanshu\\AWS_SSM_WORK",
              "var": "{{testCopyFunction.var}}"
            },
            "finallyStep": true
          }
        }
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-07-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多