【问题标题】:AWS SSM Send Command: Parameters argument not going throughAWS SSM 发送命令:参数参数未通过
【发布时间】:2019-10-05 13:00:32
【问题描述】:

我正在尝试在 Windows EC2 实例上执行 PowerShell 脚本。 Powershell 脚本有效(我 RDP'd 并执行了它)但是当我尝试使用 Boto3 SSM 执行它时,它不允许我使用参数执行它。

我相当肯定,这只是文档中缺乏清晰性,或者我只是犯了一个相当愚蠢的错误。

我已在目标实例中执行了其他 Powershell 脚本,但似乎无法获得需要参数才能工作的 Powershell 脚本。

我的 Powershell 脚本以:

开头
      param(
      [string]$roleToRegister
      )

在我的 Lambda 中,我使用:

result = ssm.send_command(DocumentName="registerxx", InstanceIds=instances, 
Parameters={'roleToRegister': ['myRole'] })

目前我正在接收:

"An error occurred (InvalidParameters) when calling the SendCommand operation:

我也尝试将参数 dict 定义为:

{
'$roleToRegister' : ['myRole']
}

任何想法都会很棒。谢谢。

文档链接: https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/ssm.html#SSM.Client.send_command

【问题讨论】:

  • 在lambda中,用的是什么版本的python和boto3?
  • 您的文档名称应该是“AWS-RunPowerShellScript”,它告诉 SSMClient 您希望运行一个 powershell 脚本。在参数部分传递您在 Windows 实例上使用的 powershell 命令,如字符串。
  • @Lamanus Python 3.7 和 Boto 1.9.235 我相信,
  • @Rajesh 在参数中传递 PowerShell 脚本不是我想做的事情。该脚本作为文档存储在 Systems Manager 中,我只是调用 SSM 为我执行该文档。
  • 能否提供您创建的SSM文档的json

标签: python-3.x aws-lambda boto3


【解决方案1】:

在发送带有参数的命令之前。 确保命令文档声明了参数。

查看架构定义: https://docs.aws.amazon.com/systems-manager/latest/userguide/ssm-plugins.html#top-level

例如:

{
  "schemaVersion": "2.2",
  "description": "Registers XX using the aws:runShellScript plugin.",
  "parameters": {
    "roleToRegister": {
      "type": "StringList",
      "description": "(Required) This is a required parameter that will be use to determine the roles to register.",
      "minItems": 1
    }
  },
  "mainSteps": [
    {
      "action": "aws:runPowerShellScript",
      "name": "RegisterXX",
      "inputs": {
        "timeoutSeconds": 60,
        "runCommand": [
          "$roles = '{{ rolesToRegister }}'",
          "Write-Host $roles"
        ]
      }
    }
  ]
}

【讨论】:

    猜你喜欢
    • 2021-11-28
    • 2021-09-24
    • 1970-01-01
    • 1970-01-01
    • 2022-07-07
    • 1970-01-01
    • 1970-01-01
    • 2012-03-15
    • 1970-01-01
    相关资源
    最近更新 更多